Only show notifications when done with sync (#1507)

This prevents the parade of notifications if a machine wakes up from
sleep. Basically covers situations that the loading screen doesn't
already.

When disabled, notifications will be cached until they are subsequently
re-enabled, at which time all the pending notifications will be summarized.

From the background page, notifications are disabled during connection attempts
until an empty event. This means we can always safely call conversation.notify
to queue a notification for the next batch, dropping some options from message
and conversation model methods.

We've also moved the calls to check window focus and draw attention to the
window, which were previously included in the conversation model, but are now
performed by the Notification system, because the time that the notification is
displayed might be some time after the message is added by the conversation, so
decisions about focus and attention should be made in that moment and not
before.

// FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-09-29 09:15:28 -07:00 committed by GitHub
parent 3b4fd2d0e0
commit 10a38297b8
4 changed files with 52 additions and 36 deletions

View file

@ -179,6 +179,8 @@
retryCached: connectCount === 1,
};
Whisper.Notifications.disable(); // avoid notification flood until empty
// initialize the socket and start listening for messages
messageReceiver = new textsecure.MessageReceiver(
SERVER_URL, USERNAME, PASSWORD, mySignalingKey, options
@ -239,6 +241,8 @@
view.onEmpty();
}
}, 500);
Whisper.Notifications.enable();
}
function onProgress(ev) {
var count = ev.count;
@ -509,9 +513,7 @@
}
conversation.trigger('newmessage', message);
if (initialLoadComplete) {
conversation.notify(message);
}
conversation.notify(message);
if (ev.confirm) {
ev.confirm();