Skip to content

Commit

Permalink
fix grouping messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Apr 24, 2019
1 parent b587351 commit caad041
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/threads/client/flextab/thread.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h2 class="contextual-bar__header-title">
<div class="thread-list js-scroll-thread">
<ul class="thread">
{{# with messageContext}}
{{> nrr nrrargs 'message' hideRoles=true msg=mainMessage room=room subscription=subscription settings=settings customClass="thread-message" templatePrefix='thread-' customClass="thread-main" u=u}}
{{> nrr nrrargs 'message' groupable=false hideRoles=true msg=mainMessage room=room subscription=subscription settings=settings customClass="thread-message" templatePrefix='thread-' customClass="thread-main" u=u}}
{{#each msg in messages}}
{{> nrr nrrargs 'message' hideRoles=true msg=msg room=room subscription=subscription settings=settings templatePrefix='thread-' u=u}}
{{/each}}
Expand Down
2 changes: 1 addition & 1 deletion app/threads/client/flextab/threads.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2 class="thread-empty">{{_ "No_Threads"}}</h2>
settings=settings
templatePrefix='threads-'
u=u
noDate=true
showDateSeparator=false
context="threads"
timeAgo=true
}}
Expand Down
23 changes: 13 additions & 10 deletions app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Meteor } from 'meteor/meteor';
import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/tap:i18n';
import mem from 'mem';

import { timeAgo, formatDateAndTime } from '../../lib/client/lib/formatDate';
import { DateFormat } from '../../lib/client';
Expand All @@ -15,6 +16,8 @@ import { Markdown } from '../../markdown/client';
import { t, roomTypes, getURL } from '../../utils';
import { messageArgs } from '../../ui-utils/client/lib/messageArgs';

Blaze._globalHelpers._ = mem(Blaze._globalHelpers._);

async function renderPdfToCanvas(canvasId, pdfLink) {
const isSafari = /constructor/i.test(window.HTMLElement) ||
((p) => p.toString() === '[object SafariRemoteNotification]')(!window.safari ||
Expand Down Expand Up @@ -138,7 +141,7 @@ Template.message.helpers({
},
isGroupable() {
const { msg, room = {}, settings, groupable } = this;
if (groupable === false || settings.allowGroup === false || room.broadcast || msg.groupable === false || MessageTypes.isSystemMessage(msg)) {
if ((msg.tmid && settings.showreply) || groupable === false || settings.allowGroup === false || room.broadcast || msg.groupable === false || MessageTypes.isSystemMessage(msg)) {
return 'false';
}
},
Expand Down Expand Up @@ -385,8 +388,8 @@ Template.message.helpers({
return !!(tmid && showreply);
},
collapsed() {
const { msg: { tmid, collapsed }, settings: { showreply } } = this;
const isCollapsedThreadReply = tmid && showreply && collapsed !== false;
const { msg: { tmid, collapsed }, settings: { showreply }, shouldCollapseReplies } = this;
const isCollapsedThreadReply = shouldCollapseReplies && tmid && showreply && collapsed !== false;
if (isCollapsedThreadReply) {
return 'collapsed';
}
Expand Down Expand Up @@ -505,20 +508,20 @@ const getPreviousSentMessage = (currentNode) => {
}
};

const setNewDayAndGroup = (currentNode, previousNode, forceDate, period, noDate) => {
const setNewDayAndGroup = (currentNode, previousNode, forceDate, period, showDateSeparator) => {
const { classList, dataset: currentDataset } = currentNode;

if (!previousNode) {
classList.remove('sequential');
!noDate && classList.add('new-day');
showDateSeparator && classList.add('new-day');
return;
}

const { dataset: previousDataset } = previousNode;
const previousMessageDate = new Date(parseInt(previousDataset.timestamp));
const currentMessageDate = new Date(parseInt(currentDataset.timestamp));

if (!noDate && (forceDate || previousMessageDate.toDateString() !== currentMessageDate.toDateString())) {
if (showDateSeparator && previousMessageDate.toDateString() !== currentMessageDate.toDateString()) {
classList.remove('sequential');
classList.add('new-day');
}
Expand All @@ -533,9 +536,9 @@ const setNewDayAndGroup = (currentNode, previousNode, forceDate, period, noDate)
};

Template.message.onViewRendered = function() {
const { settings, forceDate, noDate, groupable, msg } = messageArgs(Template.currentData());
const { settings, forceDate, showDateSeparator = true, groupable, msg } = messageArgs(Template.currentData());

if (noDate && !groupable) {
if (!showDateSeparator && !groupable) {
return;
}

Expand All @@ -547,11 +550,11 @@ Template.message.onViewRendered = function() {
const currentDataset = currentNode.dataset;
const previousNode = getPreviousSentMessage(currentNode);
const nextNode = currentNode.nextElementSibling;
setNewDayAndGroup(currentNode, previousNode, forceDate, settings.Message_GroupingPeriod, noDate);
setNewDayAndGroup(currentNode, previousNode, forceDate, settings.Message_GroupingPeriod, showDateSeparator);
if (nextNode && nextNode.dataset) {
const nextDataset = nextNode.dataset;
if (forceDate || nextDataset.date !== currentDataset.date) {
if (!noDate) {
if (showDateSeparator) {
currentNode.classList.add('new-day');
}
currentNode.classList.remove('sequential');
Expand Down
2 changes: 1 addition & 1 deletion app/ui/client/views/app/room.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
{{/if}}

{{# with messageContext}}
{{#each msg in messagesHistory}}{{#nrr nrrargs 'message' msg=msg room=room subscription=subscription settings=settings u=u}}{{/nrr}}{{/each}}
{{#each msg in messagesHistory}}{{#nrr nrrargs 'message' shouldCollapseReplies=true msg=msg room=room subscription=subscription settings=settings u=u}}{{/nrr}}{{/each}}
{{/with}}

{{#if hasMoreNext}}
Expand Down

0 comments on commit caad041

Please sign in to comment.