Skip to content
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
2 changes: 1 addition & 1 deletion app/threads/client/flextab/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Template.thread.onRendered(function() {
const tmid = Tracker.nonreactive(() => this.state.get('tmid'));
this.atBottom = true;

this.chatMessages = new ChatMessages();
this.chatMessages = new ChatMessages(this.Threads);
this.chatMessages.initializeWrapper(this.find('.js-scroll-thread'));
this.chatMessages.initializeInput(this.find('.js-input-message'), { rid, tmid });

Expand Down
18 changes: 11 additions & 7 deletions app/ui/client/lib/chatMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ callbacks.add('afterLogoutCleanUp', messageBoxState.purgeAll, callbacks.priority
const showModal = (config) => new Promise((resolve, reject) => modal.open(config, resolve, reject));

export class ChatMessages {
constructor(collection = ChatMessage) {
this.collection = collection;
}

editing = {}

records = {}
Expand Down Expand Up @@ -113,7 +117,7 @@ export class ChatMessages {
}

recordInputAsDraft() {
const message = ChatMessage.findOne(this.editing.id);
const message = this.collection.findOne(this.editing.id);
const record = this.records[this.editing.id] || {};
const draft = this.input.value;

Expand All @@ -133,7 +137,7 @@ export class ChatMessages {
}

resetToDraft(id) {
const message = ChatMessage.findOne(id);
const message = this.collection.findOne(id);
const oldValue = this.input.value;
messageBoxState.set(this.input, message.msg);
return oldValue !== message.msg;
Expand Down Expand Up @@ -176,7 +180,7 @@ export class ChatMessages {
}

edit(element, isEditingTheNextOne) {
const message = ChatMessage.findOne(element.dataset.id);
const message = this.collection.findOne(element.dataset.id);

const hasPermission = hasAtLeastOnePermission('edit-message', message.rid);
const editAllowed = settings.get('Message_AllowEditing');
Expand Down Expand Up @@ -270,7 +274,7 @@ export class ChatMessages {
}

// don't add tmid or tshow if the message isn't part of a thread (it can happen if editing the main message of a thread)
const originalMessage = ChatMessage.findOne({ _id: this.editing.id }, { fields: { tmid: 1 }, reactive: false });
const originalMessage = this.collection.findOne({ _id: this.editing.id }, { fields: { tmid: 1 }, reactive: false });
if (originalMessage && tmid && !originalMessage.tmid) {
tmid = undefined;
tshow = undefined;
Expand Down Expand Up @@ -298,7 +302,7 @@ export class ChatMessages {
}

if (this.editing.id) {
const message = ChatMessage.findOne(this.editing.id);
const message = this.collection.findOne(this.editing.id);
const isDescription = message.attachments && message.attachments[0] && message.attachments[0].description;

try {
Expand Down Expand Up @@ -352,7 +356,7 @@ export class ChatMessages {
return false;
}

const lastMessage = ChatMessage.findOne({ rid, tmid }, { fields: { ts: 1 }, sort: { ts: -1 } });
const lastMessage = this.collection.findOne({ rid, tmid }, { fields: { ts: 1 }, sort: { ts: -1 } });
await call('setReaction', reaction, lastMessage._id);
return true;
}
Expand Down Expand Up @@ -440,7 +444,7 @@ export class ChatMessages {
private: true,
};

ChatMessage.upsert({ _id: invalidCommandMsg._id }, invalidCommandMsg);
this.collection.upsert({ _id: invalidCommandMsg._id }, invalidCommandMsg);
return true;
}
}
Expand Down