From 38f6382387d81d499876cfcfb0182c998355e68b Mon Sep 17 00:00:00 2001
From: Florian Orben <florian.orben@gmail.com>
Date: Mon, 16 Nov 2015 00:27:26 +0100
Subject: PLT-924: Combine sequential messages from same user to look like one
 message (still edits as separate messages)

---
 web/react/components/posts_view.jsx | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

(limited to 'web/react/components/posts_view.jsx')

diff --git a/web/react/components/posts_view.jsx b/web/react/components/posts_view.jsx
index 087ca1df2..ec8223203 100644
--- a/web/react/components/posts_view.jsx
+++ b/web/react/components/posts_view.jsx
@@ -83,9 +83,14 @@ export default class PostsView extends React.Component {
             let hideProfilePic = false;
 
             if (prevPost) {
-                sameUser = prevPost.user_id === post.user_id && post.create_at - prevPost.create_at <= 1000 * 60 * 5;
+                const postIsComment = Utils.isComment(post);
+                const prevPostIsComment = Utils.isComment(prevPost);
+                const postFromWebhook = Boolean(post.props && post.props.from_webhook);
+                const prevPostFromWebhook = Boolean(prevPost.props && prevPost.props.from_webhook);
 
-                sameRoot = Utils.isComment(post) && (prevPost.id === post.root_id || prevPost.root_id === post.root_id);
+                sameUser = prevPost.user_id === post.user_id && postFromWebhook === prevPostFromWebhook &&
+                    post.create_at - prevPost.create_at <= 1000 * 60 * 5;
+                sameRoot = (postIsComment && (prevPost.id === post.root_id || prevPost.root_id === post.root_id)) || (!postIsComment && !prevPostIsComment && sameUser);
 
                 // hide the profile pic if:
                 //     the previous post was made by the same user as the current post,
@@ -94,10 +99,10 @@ export default class PostsView extends React.Component {
                 //     the current post is not from a webhook
                 //     and the previous post is not from a webhook
                 if ((prevPost.user_id === post.user_id) &&
-                        !Utils.isComment(prevPost) &&
-                        !Utils.isComment(post) &&
-                        (!post.props || !post.props.from_webhook) &&
-                        (!prevPost.props || !prevPost.props.from_webhook)) {
+                        !prevPostIsComment &&
+                        !postIsComment &&
+                        !postFromWebhook &&
+                        !prevPostFromWebhook) {
                     hideProfilePic = true;
                 }
             }
-- 
cgit v1.2.3-1-g7c22

