Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Regression in prune by user, and update lastMessage #11646

Merged
merged 3 commits into from Aug 7, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/rocketchat-lib/server/functions/cleanRoomHistory.js
Expand Up @@ -24,14 +24,10 @@ RocketChat.cleanRoomHistory = function({ rid, latest = new Date(), oldest = new
return fileCount;
}

let count = 0;
if (limit) {
count = RocketChat.models.Messages.removeByIdPinnedTimestampLimitAndUsers(rid, excludePinned, ts, limit, fromUsers);
} else {
count = RocketChat.models.Messages.removeByIdPinnedTimestampAndUsers(rid, excludePinned, ts, fromUsers);
}
const count = limit ? RocketChat.models.Messages.removeByIdPinnedTimestampLimitAndUsers(rid, excludePinned, ts, limit, fromUsers) : RocketChat.models.Messages.removeByIdPinnedTimestampAndUsers(rid, excludePinned, ts, fromUsers);

if (count) {
RocketChat.models.Rooms.resetLastMessageById(rid);
RocketChat.Notifications.notifyRoom(rid, 'deleteMessageBulk', {
rid,
excludePinned,
Expand Down
3 changes: 1 addition & 2 deletions packages/rocketchat-lib/server/functions/deleteMessage.js
Expand Up @@ -39,8 +39,7 @@ RocketChat.deleteMessage = function(message, user) {
if (RocketChat.settings.get('Store_Last_Message')) {
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);
RocketChat.models.Rooms.resetLastMessageById(message.rid);
}
}

Expand Down
17 changes: 17 additions & 0 deletions packages/rocketchat-lib/server/models/Rooms.js
Expand Up @@ -439,6 +439,23 @@ class ModelRooms extends RocketChat.models._Base {
return this.update(query, update);
}

resetLastMessageById(_id) {
const query = { _id };
const lastMessage = RocketChat.models.Messages.getLastVisibleMessageSentWithNoTypeByRoomId(_id);

const update = lastMessage ? {
$set: {
lastMessage
}
} : {
$unset: {
lastMessage: 1
}
};

return this.update(query, update);
}

replaceUsername(previousUsername, username) {
const query = {usernames: previousUsername};

Expand Down