Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust user messages around the Session Pause feature #2858

Merged

Conversation

avazirna
Copy link
Contributor

@avazirna avazirna commented Sep 18, 2024

Summary

Copy of #2851

cross-request: cross-request: dimagi/commcare-core#1437

@avazirna
Copy link
Contributor Author

@damagatchi retest this please

@shubham1g5
Copy link
Contributor

@avazirna It doesn't look like the comments on the original PR are addressed in this PR, let me know if my understanding is wrong.

@avazirna avazirna force-pushed the adjust-user-messages-when-autosaving-session-form branch from 7d90d94 to 2b994db Compare September 19, 2024 20:56
@avazirna
Copy link
Contributor Author

@shubham1g5 I have entertained a few design alternatives over this, walking the fine line between structural changes and the bare minimum to achieve the goals of this PR. I'm more inclined to leave the structural work for 2.55 where we can have a proper QA and properly assess all the risks. I also don't think that deep changes should be rolled out in a hotfix, which I believe you agree with me. So in terms of future work, the main points are:

  • InterruptedFormState should evolve into InterruptedSessionState - we are now redundantly saving the SessionStateDescriptorId, individually and in the InterruptedFormState - this means using this model for both Session expiration (and suspension) and Session Pause;
    • This requires a few change in the way we restore expired sessions
    • There may be challenges to ensure backward compatibility, considering that users would be migrating from version with both
  • Stop storing the SSDId in SharedPreferences
  • Review the workflow around the is-restart-after-session-expiration - currently, it implies catering only for Session expiration but the reality is that with the changes we introduced, it's also serving the Session Pause feature

Copy link
Contributor

@shubham1g5 shubham1g5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall approach looks good to me, left some minor comments around code clarity and readability as optional but nice to have feedback.

// note that we have started saving the form
customFormSaveCallback = listener;
interruptAndSaveForm(exit);
interruptAndSaveForm(true, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not clear to me from any of the semantics around this method that formSaveCallback necessarily means that sessionExpiredOrSustended is true and userTriggered is false. I suggest that we should either let these values get passed as a paramenter to formSaveCallback OR rename formSaveCallback to make it clear that it's only every utilised by auto-save calls which are not a result of explicit user action and that the save is a result of session lifecycle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 3ade9b2

}

private void interruptAndSaveForm(boolean exit) {
private void interruptAndSaveForm(boolean sessionExpiredOrSustended, boolean userTriggered) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename sessionExpiredOrSustended -> sessionExpired (assiming session expiry and suspensions are same things here)

private void saveIncompleteFormToDisk(boolean exit) {
saveDataToDisk(exit, false, null, true);
private void saveIncompleteFormToDisk(boolean sessionExpiredOrSuspended, boolean userTriggered) {
boolean shouldExit = sessionExpiredOrSuspended ? FormEntryConstants.EXIT : FormEntryConstants.DO_NOT_EXIT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would prefer if exit comes directly from caller of the save methods as before instead of us deriving it on the basis of sessionExpiry. (More scalable, would cause less changes in future if we decide to save due to another reason where we want user to exit as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 3ade9b2

@@ -20,13 +21,17 @@ public class AndroidFormController extends FormController implements PendingCall
private boolean wasPendingCalloutCancelled;
private FormIndex formIndexToReturnTo = null;
private boolean formCompleteAndSaved = false;
private InterruptedFormState restoredFormSession;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably better to call it interrruptedFormState


private FormAnalyticsHelper formAnalyticsHelper;

public AndroidFormController(FormEntryController fec, boolean readOnly, FormIndex formIndex) {
public AndroidFormController(FormEntryController fec, boolean readOnly, InterruptedFormState savedFormSession) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inconsistent variable naming. would keep them all as interruptedFormState

Comment on lines 32 to 34
if (savedFormSession !=null ){
formIndexToReturnTo = savedFormSession.getFormIndex();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think we can remove global reference to formIndexToReturnTo and just derive it from restoredFormSession when needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formIndexToReturnTo is nullified after its first use, which makes sense because we are supposed to return to that FormIndex only when loading the form after a session expiration or app kill. Am I missing something here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. no need for a change here.

@shubham1g5
Copy link
Contributor

@avazirna Can you create a ticket describing the pending list of items and make sure it gets prioritised for 2.55.


private FormAnalyticsHelper formAnalyticsHelper;

public AndroidFormController(FormEntryController fec, boolean readOnly, FormIndex formIndex) {
public AndroidFormController(FormEntryController fec, boolean readOnly, InterruptedFormState savedFormSession) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we mark savedFormSession and restoredFormSession as @Nullable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super(fec, readOnly);
formAnalyticsHelper = new FormAnalyticsHelper();
formIndexToReturnTo = formIndex;
this.restoredFormSession = savedFormSession;
if (savedFormSession !=null ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:formatting

@avazirna avazirna force-pushed the adjust-user-messages-when-autosaving-session-form branch from 5b4b1be to 3ade9b2 Compare October 22, 2024 16:53
@@ -59,6 +63,10 @@ public FormIndex getFormIndex() {
return formIndex;
}

public boolean getInterruptedDueToSessionExpiration(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to isInterrupted..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -793,7 +796,7 @@ protected void onExternalAttachmentUpdated() {
}
String formStatus = formRecord.getStatus();
if (FormRecord.STATUS_INCOMPLETE.equals(formStatus)) {
saveDataToDisk(false, false, null, true);
saveDataToDisk(false, false, null, true, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this save isuserTriggered as it happens in response to updating an attachment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1063,7 +1066,8 @@ private void loadForm() {
}

mFormLoaderTask = new FormLoaderTask<FormEntryActivity>(symetricKey, instanceIsReadOnly,
formEntryRestoreSession.isRecording(), FormEntryInstanceState.mFormRecordPath, this, lastFormIndex) {
formEntryRestoreSession.isRecording(), FormEntryInstanceState.mFormRecordPath, this,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks weird to have a comma just before method call close. No compilation errors here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that too, bad conflict resolution. Redid it locally, pushing it in a few.

if (sessionStateRecordId != -1) {
SqlStorage<SessionStateDescriptor> sessionStorage =
CommCareApplication.instance().getUserStorage(SessionStateDescriptor.class);
SessionStateDescriptor current = sessionStorage.read(sessionStateRecordId);
InterruptedFormState interruptedFormState = new InterruptedFormState(current.getID(), formIndex, current.getFormRecordId());

InterruptedFormState interruptedFormState = new InterruptedFormState(current.getID(), formIndex, current.getFormRecordId(), sessionExpired);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not sure on formatting here.

@avazirna avazirna force-pushed the adjust-user-messages-when-autosaving-session-form branch from 15b4fea to a776076 Compare October 23, 2024 10:58
@avazirna
Copy link
Contributor Author

@damagatchi retest this please

@avazirna avazirna merged commit aebd94e into feature/givewell Oct 23, 2024
1 check passed
@avazirna avazirna mentioned this pull request Oct 23, 2024
3 tasks
@avazirna avazirna deleted the adjust-user-messages-when-autosaving-session-form branch October 23, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants