From 6aefb3be90348a2ae47ca3f6a53e5a0bb3fea57d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 15 Dec 2015 17:01:16 +0000 Subject: [PATCH] Don't notify for events until the SDK is PREPARED else you can notify for stale events --- src/Notifier.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Notifier.js b/src/Notifier.js index 307c91f457..a35c3bb1ee 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -98,13 +98,16 @@ var Notifier = { start: function() { this.boundOnRoomTimeline = this.onRoomTimeline.bind(this); + this.boundOnSyncStateChange = this.onSyncStateChange.bind(this); MatrixClientPeg.get().on('Room.timeline', this.boundOnRoomTimeline); + MatrixClientPeg.get().on("sync", this.boundOnSyncStateChange); this.toolbarHidden = false; }, stop: function() { if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener('Room.timeline', this.boundOnRoomTimeline); + MatrixClientPeg.get().removeListener('sync', this.boundOnSyncStateChange); } }, @@ -175,8 +178,15 @@ var Notifier = { return this.toolbarHidden; }, + onSyncStateChange: function(state) { + if (state === "PREPARED" || state === "SYNCING") { + this.isPrepared = true; + } + }, + onRoomTimeline: function(ev, room, toStartOfTimeline) { if (toStartOfTimeline) return; + if (!this.isPrepared) return; // don't alert for any messages initially if (ev.sender && ev.sender.userId == MatrixClientPeg.get().credentials.userId) return; if (!this.isEnabled()) {