refactor update the message to use .save - fix test

This commit is contained in:
negue
2018-11-18 22:37:09 +01:00
parent 3f47cdd9a2
commit 3203bffeaa
3 changed files with 14 additions and 18 deletions

View File

@@ -67,10 +67,12 @@ export default class InboxChatReporter extends ChatReporter {
});
}
updateMessageAndSave (message, updateFunc) {
updateFunc(message);
updateMessageAndSave (message, ...changedFields) {
for (const changedField of changedFields) {
message.markModified(changedField);
}
return inboxLib.updateMessage(message);
return message.save();
}
flagInboxMessage (message) {
@@ -81,16 +83,16 @@ export default class InboxChatReporter extends ChatReporter {
throw new BadRequest(this.res.t('messageGroupChatFlagAlreadyReported'));
}
return this.updateMessageAndSave(message, (m) => {
m.flags[this.user._id] = true;
m.flagCount = 1;
});
message.flags[this.user._id] = true;
message.flagCount = 1;
return this.updateMessageAndSave(message, 'flags', 'flagCount');
}
async markMessageAsReported (message) {
return this.updateMessageAndSave(message, (m) => {
m.reported = true;
});
message.reported = true;
return this.updateMessageAndSave(message, 'reported');
}
async flag () {