PLT-5677 Make System messages mark channels as unread (#313)

* PLT-5677 Make System messages mark channels as unread equals to the webapp

* addressing feedback

* Clarify when the channel should be mark as read

* ignored posts types dont change the channel read state

* fix typo
This commit is contained in:
enahum 2017-03-01 19:02:17 -03:00 committed by GitHub
parent 069495ecb2
commit 433a95ed69
3 changed files with 45 additions and 3 deletions

View file

@ -31,7 +31,7 @@ import {
} from 'service/constants';
import {getCurrentChannelStats} from 'service/selectors/entities/channels';
import {getUserIdFromChannelName} from 'service/utils/channel_utils';
import {isSystemMessage} from 'service/utils/post_utils';
import {isSystemMessage, shouldIgnorePost} from 'service/utils/post_utils';
import EventEmitter from 'service/utils/event_emitter';
export function init(siteUrl, token, optionalWebSocket) {
@ -224,7 +224,21 @@ async function handleNewPostEvent(msg, dispatch, getState) {
}
]), getState);
if (userId === users.currentId || post.channel_id === currentChannelId || isSystemMessage(post)) {
if (shouldIgnorePost(post)) {
// if the post type is in the ignore list we'll do nothing with the read state
return;
}
let markAsRead = false;
if (userId === users.currentId && !isSystemMessage(post)) {
// In case the current user posted the message and that message wasn't triggered by a system message
markAsRead = true;
} else if (post.channel_id === currentChannelId) {
// if the post is for the channel that the user is currently viewing we'll mark the channel as read
markAsRead = true;
}
if (markAsRead) {
markChannelAsRead(post.channel_id)(dispatch, getState);
} else {
markChannelAsUnread(post.channel_id, msg.data.mentions)(dispatch, getState);

View file

@ -54,7 +54,31 @@ const FileConstants = {
WORD_TYPES: ['doc', 'docx']
};
const PostsTypes = {
ADD_REMOVE: 'system_add_remove',
ADD_TO_CHANNEL: 'system_add_to_channel',
CHANNEL_DELETED: 'system_channel_deleted',
DISPLAYNAME_CHANGE: 'system_displayname_change',
EPHEMERAL: 'system_ephemeral',
HEADER_CHANGE: 'system_header_change',
JOIN_CHANNEL: 'system_join_channel',
JOIN_LEAVE: 'system_join_leave',
LEAVE_CHANNEL: 'system_leave_channel',
PURPOSE_CHANGE: 'system_purpose_change',
REMOVE_FROM_CHANNEL: 'system_remove_from_channel'
};
export default {
...Constants,
...FileConstants
...FileConstants,
...PostsTypes,
IGNORE_POST_TYPES: [
PostsTypes.ADD_REMOVE,
PostsTypes.ADD_TO_CHANNEL,
PostsTypes.CHANNEL_DELETED,
PostsTypes.JOIN_LEAVE,
PostsTypes.JOIN_CHANNEL,
PostsTypes.LEAVE_CHANNEL,
PostsTypes.REMOVE_FROM_CHANNEL
]
};

View file

@ -7,6 +7,10 @@ export function isSystemMessage(post) {
return post.type && post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX);
}
export function shouldIgnorePost(post) {
return Constants.IGNORE_POST_TYPES.includes(post.type);
}
export function addDatesToPostList(posts, indicateNewMessages, currentUserId, lastViewedAt) {
const out = [];