Skip to content

Commit

Permalink
Fix updating last message when showing deleted status
Browse files Browse the repository at this point in the history
Closes #9332
  • Loading branch information
sampaiodiego committed Jan 4, 2018
1 parent 9dc9db3 commit 11ebf26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/rocketchat-lib/server/functions/deleteMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ RocketChat.deleteMessage = function(message, user) {

// update last message
if (RocketChat.settings.get('Store_Last_Message')) {
const lastMessage = RocketChat.models.Messages.getLastMessageSentWithNoTypeByRoomId(message.rid);
RocketChat.models.Rooms.setLastMessageById(message.rid, lastMessage);
const room = RocketChat.models.Rooms.findOneById(message.rid, { fields: { lastMessage: 1 } });
if (!room.lastMessage || room.lastMessage._id === message._id) {
const lastMessage = RocketChat.models.Messages.getLastVisibleMessageSentWithNoTypeByRoomId(message.rid, message._id);
RocketChat.models.Rooms.setLastMessageById(message.rid, lastMessage);
}
}

if (showDeletedStatus) {
Expand Down
4 changes: 3 additions & 1 deletion packages/rocketchat-lib/server/models/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base {
return this.findOne(query);
}

getLastMessageSentWithNoTypeByRoomId(rid) {
getLastVisibleMessageSentWithNoTypeByRoomId(rid, messageId) {
const query = {
_id: { $ne: messageId },
rid,
_hidden: { $ne: true },
t: { $exists: false }
};

Expand Down

0 comments on commit 11ebf26

Please sign in to comment.