[FIX] Edit in thread (#15640)

* Globally register threads chatMessages

* Enable editing inside thread tab
pull/15688/head
Tasso Evangelista 6 years ago committed by Guilherme Gazzo
parent fb150cd15c
commit 0646274344
  1. 5
      app/threads/client/flextab/thread.js
  2. 19
      app/ui-utils/client/lib/MessageAction.js

@ -4,7 +4,7 @@ import { Template } from 'meteor/templating';
import { ReactiveDict } from 'meteor/reactive-dict'; import { ReactiveDict } from 'meteor/reactive-dict';
import { Tracker } from 'meteor/tracker'; import { Tracker } from 'meteor/tracker';
import { ChatMessages } from '../../../ui'; import { chatMessages, ChatMessages } from '../../../ui';
import { normalizeThreadMessage, call } from '../../../ui-utils/client'; import { normalizeThreadMessage, call } from '../../../ui-utils/client';
import { messageContext } from '../../../ui-utils/client/lib/messageContext'; import { messageContext } from '../../../ui-utils/client/lib/messageContext';
import { upsertMessageBulk } from '../../../ui-utils/client/lib/RoomHistoryManager'; import { upsertMessageBulk } from '../../../ui-utils/client/lib/RoomHistoryManager';
@ -127,6 +127,9 @@ Template.thread.onRendered(function() {
const rid = this.state.get('rid'); const rid = this.state.get('rid');
const tmid = this.state.get('tmid'); const tmid = this.state.get('tmid');
this.chatMessages.initializeInput(this.find('.js-input-message'), { rid, tmid }); this.chatMessages.initializeInput(this.find('.js-input-message'), { rid, tmid });
if (rid && tmid) {
chatMessages[`${ rid }-${ tmid }`] = this.chatMessages;
}
}); });

@ -143,6 +143,19 @@ export const MessageAction = new class {
Meteor.startup(async function() { Meteor.startup(async function() {
const { chatMessages } = await import('../../../ui'); const { chatMessages } = await import('../../../ui');
const getChatMessagesFrom = (msg) => {
const { rid, tmid } = msg;
if (rid) {
if (tmid) {
return chatMessages[`${ rid }-${ tmid }`];
}
return chatMessages[rid];
}
return chatMessages[Session.get('openedRoom')];
};
MessageAction.addButton({ MessageAction.addButton({
id: 'reply-directly', id: 'reply-directly',
icon: 'reply-directly', icon: 'reply-directly',
@ -247,7 +260,7 @@ Meteor.startup(async function() {
context: ['message', 'message-mobile', 'threads'], context: ['message', 'message-mobile', 'threads'],
action() { action() {
const { msg } = messageArgs(this); const { msg } = messageArgs(this);
chatMessages[Session.get('openedRoom')].edit(document.getElementById(msg._id)); getChatMessagesFrom(msg).edit(document.getElementById(msg.tmid ? `thread-${ msg._id }` : msg._id));
}, },
condition({ msg: message, subscription, settings }) { condition({ msg: message, subscription, settings }) {
if (subscription == null) { if (subscription == null) {
@ -284,8 +297,8 @@ Meteor.startup(async function() {
context: ['message', 'message-mobile', 'threads'], context: ['message', 'message-mobile', 'threads'],
color: 'alert', color: 'alert',
action() { action() {
const { msg: message } = messageArgs(this); const { msg } = messageArgs(this);
chatMessages[Session.get('openedRoom')].confirmDeleteMsg(message); getChatMessagesFrom(msg).confirmDeleteMsg(msg);
}, },
condition({ msg: message, subscription }) { condition({ msg: message, subscription }) {
if (!subscription) { if (!subscription) {

Loading…
Cancel
Save