Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Main thread title on replies #14372

Merged
merged 5 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@ const renderBody = (msg, settings) => {
};

Template.message.onCreated(function() {
const { msg, settings } = Template.currentData();
const { msg, settings, shouldCollapseReplies } = Template.currentData();

this.wasEdited = msg.editedAt && !MessageTypes.isSystemMessage(msg);
if (msg.tmid && !msg.threadMsg) {
if (shouldCollapseReplies && msg.tmid && !msg.threadMsg) {
findParentMessage(msg.tmid);
}
return this.body = Tracker.nonreactive(() => renderBody(msg, settings));
Expand Down
6 changes: 3 additions & 3 deletions app/ui-utils/client/lib/RoomHistoryManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import mem from 'mem';
import s from 'underscore.string';
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
Expand All @@ -10,7 +9,8 @@ import { RoomManager } from './RoomManager';
import { readMessage } from './readMessages';
import { renderMessageBody } from './renderMessageBody';

export const normalizeThreadMessage = mem((message) => {
export const normalizeThreadMessage = (message) => {
ggazzo marked this conversation as resolved.
Show resolved Hide resolved

if (message.msg) {
return renderMessageBody(message).replace(/<br\s?\\?>/g, ' ');
}
Expand All @@ -26,7 +26,7 @@ export const normalizeThreadMessage = mem((message) => {
return s.escapeHTML(attachment.title);
}
}
}, { maxAge: 1000 });
};

export const upsertMessage = ({ msg: { _id, ...msg }, subscription }) => {
const userId = msg.u && msg.u._id;
Expand Down
25 changes: 23 additions & 2 deletions app/ui-utils/client/lib/renderMessageBody.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import { callbacks } from '../../../callbacks';
import s from 'underscore.string';

export const renderMessageBody = (message) => {
const generateKeyDefault = (...args) => args.map((item) => JSON.stringify(item)).join('-');

const mem = (fn, tm = 500, generateKey = generateKeyDefault) => {
const cache = {};
const timeout = {};

const invalidateCache = (key) => delete cache[key];
return (...args) => {
const key = generateKey(...args);
if (!cache[key]) {
cache[key] = fn(...args);
}
if (timeout[key]) {
clearTimeout(timeout[key]);
}
timeout[key] = setTimeout(invalidateCache, tm, key);
return cache[key];
};
};

export const renderMessageBody = mem((message) => {

message.html = s.trim(message.msg) ? s.escapeHTML(message.msg) : '';

const { tokens, html } = callbacks.run('renderMessage', message);

return (Array.isArray(tokens) ? tokens.reverse() : [])
.reduce((html, { token, text }) => html.replace(token, () => text), html);
};
}, 5000, ({ _id, _updatedAt }) => (_id + _updatedAt));
7 changes: 3 additions & 4 deletions tests/pageobjects/main-content.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ class MainContent extends Page {
}

waitForLastMessageTextAttachmentEqualsText(text) {
browser.waitUntil(function() {
browser.waitForVisible('.message:last-child .attachment-text', 5000);
return browser.getText('.message:last-child .attachment-text') === text;
}, 5000);

browser.waitForVisible('.message:last-child .attachment-text', 5000);
return browser.getText('.message:last-child .attachment-text') === text;
}

// Wait for the last message author username to equal the provided text
Expand Down