mattermost-mobile/service/utils/post_utils.js
Chris Duarte 0bf26e95b0 PLT-5499 Indicate start of new messages in posts list (#279)
* Indicate start of new messages in posts list

* Use flag prop to indicate start of new messages in posts list

* Declare style props with View.propTypes.style
2017-02-20 18:05:16 -03:00

40 lines
1.2 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, lastViewedAt) {
const out = [];
let lastDate = null;
let subsequentPostIsUnread = false;
let postIsUnread;
for (const post of posts) {
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);
postIsUnread = post.create_at > lastViewedAt;
if (indicateNewMessages && subsequentPostIsUnread && !postIsUnread) {
out.push(Constants.START_OF_NEW_MESSAGES);
}
subsequentPostIsUnread = postIsUnread;
}
// Push on the date header for the oldest post
if (lastDate) {
out.push(lastDate);
}
return out;
}