Commit 5d198168 authored by Sean Hammond's avatar Sean Hammond

Fix annotating while signed out

If the user creates annotations while signed out and then signs in, we
want those annotations to still be present in the sidebar after sign in,
rather than being lost.

Commit 7a1b5ca8d99252d3a086a8a8103fca4702521d06 had inadvertently broken
this.

The problem is that app.coffee destroys all AnnotationController
instances on sign in, and only creates new instances for those
annotations that have drafts.

7a1b5ca8d99252d3a086a8a8103fca4702521d06 removed a spurious call to
saveToDrafts() in vm.edit() but it turns out that this call was
(apparently inadvertently) the only thing that was causing drafts of
annotations created while signed out to be saved, and hence the only
thing causing these annotations to persist across sign ins.

So add a listener for the USER_CHANGED event and save drafts of
annotations on sign in, just before the AnnotationControllers get
destroyed.
parent 67e127e0
......@@ -314,6 +314,9 @@ function AnnotationController(
// Call `onGroupFocused()` whenever the currently-focused group changes.
$scope.$on(events.GROUP_FOCUSED, onGroupFocused);
// Call `onUserChanged()` whenever the user logs in or out.
$scope.$on(events.USER_CHANGED, onUserChanged);
// New annotations (just created locally by the client, rather then
// received from the server) have some fields missing. Add them.
domainModel.user = domainModel.user || session.state.userid;
......@@ -356,6 +359,18 @@ function AnnotationController(
}
}
function onUserChanged(event, args) {
// If the user creates an annotation while signed out and then signs in
// we want those annotations to still be in the sidebar after sign in.
// So we need to save a draft of the annotation here on sign in because
// app.coffee / the routing code is about to destroy all the
// AnnotationController instances and only the ones that have saved drafts
// will be re-created.
if (vm.editing() && session.state.userid) {
saveToDrafts(drafts, domainModel, vm);
}
}
/** Save this annotation if it's a new highlight.
*
* The highlight will be saved to the server if the user is logged in,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment