core/remote: Move doc before migrating references (#1876)
core/remote: Move doc before migrating references (#1876)

In case of an overwriting move (i.e. there is an existing document at
the move target location that we will overwrite), we want to preserve
the overwritten document's references.
This is useful to preserve a modified photo's album for example.

In this situation, the `Remote.moveAsync()` method will perform 4
actions:
1. fetch the overwritten document's references
2. add those references to the overwriting document
3. trash the overwritten document
4. move the overwriting document to the target location

If performed in this order, step 2. will generate a CouchDB change
with the overwriting document's previous location. This change will
then be picked up by the remote watcher. Since we have already saved
the document's new location in our local PouchDB record, the remote
watcher will believe this change is a move, from our target location
to the source location.
Thankfully, we receive the subsequent move change before we can
synchronize the wrong, inverted move and the local watcher will bundle
the two of them, resulting in a noop (i.e. the remote document is in
sync with our local PouchDB record).

But this situation can be avoided altogether. We can simply perform
step 2. last, after the overwriting document has been moved on the
remote Cozy. In this case, the remote watcher will only fetch changes
for the document at its new location, matching the location saved in
our local PouchDB record.
cozy-labs/cozy-desktop,cozy-labs/cozy-desktop,cozy-labs/cozy-desktop,cozy-labs/cozy-desktop