Skip to content

Commit

Permalink
Fix messages losing thread titles on editing or reaction and improve …
Browse files Browse the repository at this point in the history
…message actions (#14051)
  • Loading branch information
ggazzo authored and sampaiodiego committed Apr 9, 2019
1 parent 98eed0f commit 7fc7b3a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
25 changes: 11 additions & 14 deletions app/ui-message/client/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,17 @@
{{/with}}
{{#unless system}}
<div class="message-actions">
{{#if messageActions 'message'}}
<div class="message-actions__buttons">
{{#each action in messageActions 'message'}}
<button class="message-actions__button" data-message-action="{{action.id}}">
{{> icon block="message-actions__button-icon" icon=action.icon}}
</button>
{{/each}}
</div>
{{/if}}
{{#if messageActions 'menu'}}
<div class="message-actions__menu">
{{> icon block="message-actions__menu-icon" icon="menu"}}
</div>
{{/if}}

<div class="message-actions__buttons">
{{#each action in messageActions 'message'}}
<button class="message-actions__button" data-message-action="{{action.id}}">
{{> icon block="message-actions__button-icon" icon=action.icon}}
</button>
{{/each}}
</div>
<div class="message-actions__menu">
{{> icon block="message-actions__menu-icon" icon="menu"}}
</div>
</div>
{{/unless}}
{{#unless hideActionLinks}}
Expand Down
27 changes: 12 additions & 15 deletions app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Meteor } from 'meteor/meteor';
import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/tap:i18n';
import { ReactiveVar } from 'meteor/reactive-var';

import { timeAgo } from '../../lib/client/lib/formatDate';
import { DateFormat } from '../../lib/client';
Expand Down Expand Up @@ -69,9 +68,6 @@ async function renderPdfToCanvas(canvasId, pdfLink) {
}

Template.message.helpers({
hover() {
return Template.instance().hover.get();
},
and(a, b) {
return a && b;
},
Expand Down Expand Up @@ -392,7 +388,7 @@ const findParentMessage = (() => {
return;
}
const { _id, ...msg } = message;
Messages.update({ tmid: _id }, {
Messages.update({ tmid: _id, repliesCount: { $exists: 0 } }, {
$set: {
threadMsg: normalizeThreadMessage(msg),
repliesCount: msg.tcount,
Expand All @@ -410,7 +406,12 @@ const findParentMessage = (() => {
const message = Messages.findOne({ _id: tmid });

if (message) {
return;
return Messages.update({ tmid, repliesCount: { $exists: 0 } }, {
$set: {
threadMsg: normalizeThreadMessage(message),
repliesCount: message.tcount,
},
}, { multi: true });
}

waiting.push(tmid);
Expand All @@ -422,12 +423,6 @@ const findParentMessage = (() => {
const renderBody = (msg, settings) => {
const isSystemMessage = MessageTypes.isSystemMessage(msg);
const messageType = MessageTypes.getType(msg) || {};
if (msg.thread_message) {
msg.reply = Markdown.parse(TAPi18n.__('Thread_message', {
username: msg.u.username,
msg: msg.thread_message.msg,
}));
}

if (messageType.render) {
msg = messageType.render(msg);
Expand All @@ -450,13 +445,12 @@ const renderBody = (msg, settings) => {
};

Template.message.onCreated(function() {
this.hover = new ReactiveVar(false);
// const [, currentData] = Template.currentData()._arguments;
// const { msg, settings } = currentData.hash;
const { msg, settings } = Template.currentData();

this.wasEdited = msg.editedAt && !MessageTypes.isSystemMessage(msg);
if (msg.tmid && !msg.thread_message) {
if (msg.tmid && !msg.threadMsg) {
findParentMessage(msg.tmid);
}
return this.body = renderBody(msg, settings);
Expand Down Expand Up @@ -516,7 +510,10 @@ const setNewDayAndGroup = (currentNode, previousNode, forceDate, period, noDate)

Template.message.onViewRendered = function(context) {
const [, currentData] = Template.currentData()._arguments;
const { settings, forceDate, noDate } = currentData.hash;
const { settings, forceDate, noDate, msg } = currentData.hash;
if (msg.tmid && !msg.threadMsg) {
findParentMessage(msg.tmid);
}
return this._domrange.onAttached((domRange) => {
if (context.file && context.file.type === 'application/pdf') {
Meteor.defer(() => { renderPdfToCanvas(context.file._id, context.attachments[0].title_link); });
Expand Down
21 changes: 12 additions & 9 deletions app/ui-utils/client/lib/MessageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const MessageAction = new class {
}

if (config.condition) {
config.condition = mem(config.condition);
config.condition = mem(config.condition, { maxAge: 1000 });
}

return Tracker.nonreactive(() => {
Expand Down Expand Up @@ -103,23 +103,26 @@ export const MessageAction = new class {
return allButtons[id];
}

_getButtons = mem(function() {
return _.sortBy(_.toArray(this.buttons.get()), 'order');
}, { maxAge: 100 })

getButtons(message, context, group) {
let allButtons = _.toArray(this.buttons.get());
let allButtons = this._getButtons();

if (group) {
allButtons = allButtons.filter((button) => button.group === group);
}

if (message) {
allButtons = _.compact(_.map(allButtons, function(button) {
return allButtons.filter(function(button) {
if (button.context == null || button.context.includes(context)) {
if (button.condition == null || button.condition(message, context)) {
return button;
}
return button.condition == null || button.condition(message, context);
}
}));
return false;
});
}
return _.sortBy(allButtons, 'order');
return allButtons;
}

resetButtons() {
Expand Down Expand Up @@ -351,7 +354,7 @@ Meteor.startup(async function() {

},
condition(message) {
const subscription = Subscriptions.findOne({ rid: message.rid });
const subscription = Subscriptions.findOne({ rid: message.rid }, { fields: { ignored: 1 } });
return Meteor.userId() !== message.u._id && subscription && subscription.ignored && subscription.ignored.indexOf(message.u._id) > -1;
},
order: 20,
Expand Down

0 comments on commit 7fc7b3a

Please sign in to comment.