mattermost-mobile/service/utils/post_utils.js
Harrison Healey 249312b852 PLT-5252 Added Thread view (#239)
* Added Thread view

* Fixed added unit test

* Fixed copyright date on added file

* Moved scene-specific selector into service directory
2017-02-13 18:08:26 -03:00

32 lines
847 B
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) {
const out = [];
let lastDate = null;
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);
}
// Push on the date header for the oldest post
if (lastDate) {
out.push(lastDate);
}
return out;
}