Skip to content

Commit

Permalink
Only notify for unseen messages
Browse files Browse the repository at this point in the history
Closes #40
  • Loading branch information
rickhanlonii committed Jun 27, 2016
1 parent fb6e8af commit 72f895d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion web/redux/actions/notification-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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));
};
}

0 comments on commit 72f895d

Please sign in to comment.