Skip to content

Commit

Permalink
Merge branch 'develop' into threads-render
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Apr 10, 2019
2 parents 2a67741 + 7fc7b3a commit c0082c7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 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
30 changes: 8 additions & 22 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 @@ -70,9 +69,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 All @@ -479,11 +473,8 @@ const getPreviousSentMessage = (currentNode) => {
};

const setNewDayAndGroup = (currentNode, previousNode, forceDate, period, noDate) => {


const { classList } = currentNode;

// const $nextNode = $(nextNode);
if (previousNode == null) {

classList.remove('sequential');
Expand All @@ -499,7 +490,6 @@ const setNewDayAndGroup = (currentNode, previousNode, forceDate, period, noDate)
classList.add('new-day');
}


if (previousDataset.tmid !== currentDataset.tmid) {
return classList.remove('sequential');
}
Expand Down Expand Up @@ -560,9 +550,7 @@ Template.message.onViewRendered = function() {
}
templateInstance.sendToBottomIfNecessary();
}

});

};

Template.message.onRendered(function() {
Expand Down Expand Up @@ -610,6 +598,4 @@ Template.message.onRendered(function() {
}
templateInstance.sendToBottomIfNecessary();
}


});
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"@google-cloud/language": "^2.0.0",
"@google-cloud/storage": "^2.3.1",
"@google-cloud/vision": "^0.23.0",
"@rocket.chat/apps-engine": "1.4.0",
"@rocket.chat/apps-engine": "1.4.1",
"@slack/client": "^4.8.0",
"adm-zip": "^0.4.13",
"apollo-server-express": "^1.3.6",
Expand Down

0 comments on commit c0082c7

Please sign in to comment.