Merge pull request from matrix-org/dbkr/fix_notifs_on_refresh

Don't re-notify about messages on browser refresh
This commit is contained in:
David Baker 2017-03-28 15:16:12 +01:00 committed by GitHub
commit e90897d117

View file

@ -98,7 +98,7 @@ var Notifier = {
MatrixClientPeg.get().on("Room.receipt", this.boundOnRoomReceipt); MatrixClientPeg.get().on("Room.receipt", this.boundOnRoomReceipt);
MatrixClientPeg.get().on("sync", this.boundOnSyncStateChange); MatrixClientPeg.get().on("sync", this.boundOnSyncStateChange);
this.toolbarHidden = false; this.toolbarHidden = false;
this.isPrepared = false; this.isSyncing = false;
}, },
stop: function() { stop: function() {
@ -107,7 +107,7 @@ var Notifier = {
MatrixClientPeg.get().removeListener("Room.receipt", this.boundOnRoomReceipt); MatrixClientPeg.get().removeListener("Room.receipt", this.boundOnRoomReceipt);
MatrixClientPeg.get().removeListener('sync', this.boundOnSyncStateChange); MatrixClientPeg.get().removeListener('sync', this.boundOnSyncStateChange);
} }
this.isPrepared = false; this.isSyncing = false;
}, },
supportsDesktopNotifications: function() { supportsDesktopNotifications: function() {
@ -213,18 +213,18 @@ var Notifier = {
}, },
onSyncStateChange: function(state) { onSyncStateChange: function(state) {
if (state === "PREPARED" || state === "SYNCING") { if (state === "SYNCING") {
this.isPrepared = true; this.isSyncing = true;
} }
else if (state === "STOPPED" || state === "ERROR") { else if (state === "STOPPED" || state === "ERROR") {
this.isPrepared = false; this.isSyncing = false;
} }
}, },
onRoomTimeline: function(ev, room, toStartOfTimeline, removed, data) { onRoomTimeline: function(ev, room, toStartOfTimeline, removed, data) {
if (toStartOfTimeline) return; if (toStartOfTimeline) return;
if (!room) return; if (!room) return;
if (!this.isPrepared) return; // don't alert for any messages initially if (!this.isSyncing) return; // don't alert for any messages initially
if (ev.sender && ev.sender.userId == MatrixClientPeg.get().credentials.userId) return; if (ev.sender && ev.sender.userId == MatrixClientPeg.get().credentials.userId) return;
if (data.timeline.getTimelineSet() !== room.getUnfilteredTimelineSet()) return; if (data.timeline.getTimelineSet() !== room.getUnfilteredTimelineSet()) return;