mattermost-mobile/service/utils/post_utils.js
Chris Duarte afe09babfa PLT-5605 Fix logic for indicating start of new messages (#284)
* Fix placement of new messages separator

* Ignore your own posts when determining start of new messages

* Cache lastViewedAt in ChannelPostList until switching channels

* Increase padding around DateHeader & NewMessagesDivider

* Improve styling of new messages divider line

* Use async await for ChannelDrawerList.onSelectChannel

* Convert DateHeader to functional component
2017-02-21 23:59:27 -03:00

42 lines
1.3 KiB
JavaScript

// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {Constants} from 'service/constants';
export function isSystemMessage(post) {
return post.type && post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX);
}
export function addDatesToPostList(posts, indicateNewMessages, currentUserId, lastViewedAt) {
const out = [];
let lastDate = null;
let subsequentPostIsUnread = false;
let subsequentPostUserId;
let postIsUnread;
for (const post of posts) {
postIsUnread = post.create_at > lastViewedAt;
if (indicateNewMessages && subsequentPostIsUnread && !postIsUnread && subsequentPostUserId !== currentUserId) {
out.push(Constants.START_OF_NEW_MESSAGES);
}
subsequentPostIsUnread = postIsUnread;
subsequentPostUserId = post.user_id;
const postDate = new Date(post.create_at);
// Push on a date header if the last post was on a different day than the current one
if (lastDate && lastDate.toDateString() !== postDate.toDateString()) {
out.push(lastDate);
}
lastDate = postDate;
out.push(post);
}
// Push on the date header for the oldest post
if (lastDate) {
out.push(lastDate);
}
return out;
}