couchbaselabs/ToDoLite-Android

Add conflict resolution

Closed this issue · 4 comments

It would be nice to display a mark in the cell when a Task has conflicting revisions.
When the user clicks on the mark, then open a new Screen/Activity, display both revisions and let the user pick the winner.

Actions:

  • In the method setting up the cell in the list view, add logic to detect if this task has conflicting revisions.
final Document task = (Document) getItem(position);
if (task.getConflictingRevisions().size() > 0) {
    // show conflict marker
}
  • add onClickListener on the marker button to show new activity with the list of conflicting revisions.
  • when user picks a revision, delete all the other ones. This will cause the remaining revision to be the current revision
// x: number of the revision picked in the list showed to the user
SavedRevision pickedRevision = task.getConflictingRevisions().get(x);
for (SavedRevision rev : task.getConflictingRevisions()) {
    if (rev.equals(pickedRevision)) {
        // do nothing
    } else {
        rev.deleteDocument();
    }
}

See conflict resolution guide

There is also the possibility to do auto merging when userProperties do not conflict. I don't think that's a use case for Todo Lite yet though since the schema is always the same.

I've tested the above and all works fine but i'm not sure that the behaviour is what a user would expect.

Use case: device A creates a doc with rev1, device B pulls rev1 from sync gateway. device A creates a rev2-hashA. Some time later, device B creates rev2-hashB as well.

I think the user expects to see the rev2-hashB item in the list because it was the latest update in time. So we could have automatic conflict resolution to pick the rev with the latest updated_at property.

Automatic resolution would be what the user expects but we wouldn't be able to show the conflict icon then.

What is the best approach?

I don't think we need or want automatic conflict resolution. If two people make two conflicting changes, lets say editing the text of the item, there's no good way to have the business logic choose the "right" branch. Already, couchbase lite will choose a winning revision on its own -- do you mean "promote the winning branch" and "delete the losing branch" by automatic conflict resolution?

If so, there's a problem with that. If you delete the losing branch of the rev tree, then you lose the ability to have the user choose what the winning revision should be.

I proposed a fix in gitter

Yes, it would be really nice to show the user the list of conflicting revisions with the "date of last edit" and "user who last edited" information for each one, and let the user pick the winning one.

Ok, using this resolution, the content of a task cell on the list may change when the user doesn't expect it to (we have to show the current revision). Say we have updated a task so now it's at rev2-hashA. Some time later, the device pulls a rev2-hashB of that document and couchbase lite deterministically decides that rev2-hashB is the current revision. The item will change in the todo list from rev2-hashA to rev2-hashB.

I think that's reasonable though 👍

Pasting here the spec @tleyden and @zgramana came up with:

  • if a doc is detected to be in conflict, show an icon (I think you already had this idea)
  • If user longtaps the doc, they have an option ("Resolve Conflict")
  • it shows summary (but not content) of conflicting versions:
    • user who last edited
    • date of last edit
  • there is a way for the user to choose the winning revision
  • the doc will no longer be in conflict