diff options
author | samogot <samogot@gmail.com> | 2016-07-14 15:19:27 +0300 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2016-07-14 08:19:27 -0400 |
commit | 9b9facd3d21a7ab341dd6d80fd8b53fb852ae036 (patch) | |
tree | 11418f04ce57bb6083797c29ceba690b97302e15 /webapp/actions | |
parent | 6abc9601bec18e5005ff16dd4147bf038dafb264 (diff) | |
download | chat-9b9facd3d21a7ab341dd6d80fd8b53fb852ae036.tar.gz chat-9b9facd3d21a7ab341dd6d80fd8b53fb852ae036.tar.bz2 chat-9b9facd3d21a7ab341dd6d80fd8b53fb852ae036.zip |
PLT-3366 Holding down the ALT key and clicking on a message adds a new messages indicator (squashed) (#3374)
Diffstat (limited to 'webapp/actions')
-rw-r--r-- | webapp/actions/channel_actions.jsx | 12 | ||||
-rw-r--r-- | webapp/actions/post_actions.jsx | 52 |
2 files changed, 64 insertions, 0 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx index 9e5ecb03b..f8bc61538 100644 --- a/webapp/actions/channel_actions.jsx +++ b/webapp/actions/channel_actions.jsx @@ -5,6 +5,8 @@ import {browserHistory} from 'react-router/es6'; import * as Utils from 'utils/utils.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; +import ChannelStore from 'stores/channel_store.jsx'; +import * as AsyncClient from 'utils/async_client.jsx'; import Client from 'utils/web_client.jsx'; export function goToChannel(channel) { @@ -24,3 +26,13 @@ export function goToChannel(channel) { export function executeCommand(channelId, message, suggest, success, error) { Client.executeCommand(channelId, message, suggest, success, error); } + +export function setChannelAsRead(channelIdParam) { + const channelId = channelIdParam || ChannelStore.getCurrentId(); + AsyncClient.updateLastViewedAt(); + ChannelStore.resetCounts(channelId); + ChannelStore.emitChange(); + if (channelId === ChannelStore.getCurrentId()) { + ChannelStore.emitLastViewed(Number.MAX_VALUE, false); + } +} diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx index 866ae5888..a6b464a24 100644 --- a/webapp/actions/post_actions.jsx +++ b/webapp/actions/post_actions.jsx @@ -6,7 +6,9 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import PostStore from 'stores/post_store.jsx'; import TeamStore from 'stores/team_store.jsx'; +import UserStore from 'stores/user_store.jsx'; +import * as PostUtils from 'utils/post_utils.jsx'; import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; @@ -62,3 +64,53 @@ export function handleNewPost(post, msg) { websocketMessageProps }); } + +export function setUnreadPost(channelId, postId) { + let lastViewed = 0; + let ownNewMessage = false; + const post = PostStore.getPost(channelId, postId); + const posts = PostStore.getVisiblePosts(channelId).posts; + var currentUsedId = UserStore.getCurrentId(); + if (currentUsedId === post.user_id || PostUtils.isSystemMessage(post)) { + for (const otherPostId in posts) { + if (lastViewed < posts[otherPostId].create_at && currentUsedId !== posts[otherPostId].user_id && !PostUtils.isSystemMessage(posts[otherPostId])) { + lastViewed = posts[otherPostId].create_at; + } + } + if (lastViewed === 0) { + lastViewed = Number.MAX_VALUE; + } else if (lastViewed > post.create_at) { + lastViewed = post.create_at - 1; + ownNewMessage = true; + } else { + lastViewed -= 1; + } + } else { + lastViewed = post.create_at - 1; + } + + if (lastViewed === Number.MAX_VALUE) { + AsyncClient.updateLastViewedAt(); + ChannelStore.resetCounts(ChannelStore.getCurrentId()); + ChannelStore.emitChange(); + } else { + let unreadPosts = 0; + for (const otherPostId in posts) { + if (posts[otherPostId].create_at > lastViewed) { + unreadPosts += 1; + } + } + const member = ChannelStore.getMember(channelId); + const channel = ChannelStore.get(channelId); + member.last_viewed_at = lastViewed; + member.msg_count = channel.total_msg_count - unreadPosts; + member.mention_count = 0; + ChannelStore.setChannelMember(member); + ChannelStore.setUnreadCount(channelId); + AsyncClient.setLastViewedAt(lastViewed, channelId); + } + + if (channelId === ChannelStore.getCurrentId()) { + ChannelStore.emitLastViewed(lastViewed, ownNewMessage); + } +} |