From 72f895d87fa628ff5a4bd07d3d15d023e1d8bf3c Mon Sep 17 00:00:00 2001 From: Rick Hanlon II Date: Mon, 27 Jun 2016 11:44:20 -0400 Subject: [PATCH] Only notify for unseen messages Closes larvalabs/breaker#40 --- web/redux/actions/notification-actions.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/web/redux/actions/notification-actions.js b/web/redux/actions/notification-actions.js index 6af9480..c0a57b0 100644 --- a/web/redux/actions/notification-actions.js +++ b/web/redux/actions/notification-actions.js @@ -40,6 +40,8 @@ export function handleSendNotification(title, body, roomName) { export function handleMessageUserMentionNotification(message) { return (dispatch, getStore) => { + const store = getStore(); + // Prop validation if (!message.message.mentionedUsernames || !message.message.mentionedUsernames.length) { return null; @@ -49,7 +51,7 @@ export function handleMessageUserMentionNotification(message) { return null; } - const authUsername = getStore().getIn(['authUser', 'username'], '').toLowerCase(); + const authUsername = store.getIn(['authUser', 'username'], '').toLowerCase(); if (message.user.username.toLowerCase() === authUsername) { return null; } @@ -73,6 +75,11 @@ export function handleNewMessageNotification(message) { return null; } + const lastSeenRoomTime = store.getIn(['lastSeenTimes', message.room.name]); + if (message.message.createDateLongUTC < lastSeenRoomTime) { + return null; + } + dispatch(handleMessageUserMentionNotification(message)); }; }