Skip to content

Commit

Permalink
[FIX] Duplicate thread message after editing (#14330)
Browse files Browse the repository at this point in the history
* fix

* renamed method
  • Loading branch information
ggazzo authored and rodrigok committed Apr 30, 2019
1 parent 596e909 commit f6ca356
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions app/models/server/models/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,25 @@ export class Messages extends Base {
return this.find(query, options);
}

findVisibleByRoomId(roomId, options) {
findVisibleByRoomId(rid, options) {
const query = {
_hidden: {
$ne: true,
},

rid: roomId,
rid,
};

return this.find(query, options);
}

findVisibleThreadByThreadId(tmid, options) {
const query = {
_hidden: {
$ne: true,
},

tmid,
};

return this.find(query, options);
Expand Down
2 changes: 1 addition & 1 deletion app/threads/client/flextab/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Template.thread.onRendered(function() {
const tmid = this.state.get('tmid');
this.threadsObserve && this.threadsObserve.stop();

this.threadsObserve = Messages.find({ tmid, _updatedAt: { $gt: new Date() } }, {
this.threadsObserve = Messages.find({ tmid, _updatedAt: { $gt: new Date() }, _hidden: { $ne: true } }, {
fields: {
collapsed: 0,
threadMsg: 0,
Expand Down
2 changes: 1 addition & 1 deletion app/threads/client/flextab/threads.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Template.threads.onCreated(async function() {
this.autorun(() => {
const rid = this.state.get('rid');
this.threadsObserve && this.threadsObserve.stop();
this.threadsObserve = Messages.find({ rid, _updatedAt: { $gt: new Date() }, tcount: { $exists: true } }).observe({
this.threadsObserve = Messages.find({ rid, _updatedAt: { $gt: new Date() }, tcount: { $exists: true }, _hidden: { $ne: true } }).observe({
added: ({ _id, ...message }) => {
this.Threads.upsert({ _id }, message);
}, // Update message to re-render DOM
Expand Down
2 changes: 1 addition & 1 deletion app/threads/server/methods/getThreadMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Meteor.methods({

readThread({ userId: user._id, rid: thread.rid, tmid });

const result = Messages.find({ tmid }, { ...(skip && { skip }), ...(limit && { limit }), sort: { ts : -1 } }).fetch();
const result = Messages.findVisibleThreadByThreadId(tmid, { ...(skip && { skip }), ...(limit && { limit }), sort: { ts : -1 } }).fetch();

return [thread, ...result];
},
Expand Down

0 comments on commit f6ca356

Please sign in to comment.