mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Send back flag data if user had flagged the message.
This commit is contained in:
@@ -39,6 +39,17 @@ describe('POST /groups/:id/chat/:id/flag', () => {
|
||||
expect(message.flagCount).to.eql(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot flag the same message twice', () => {
|
||||
let api = requester(user);
|
||||
|
||||
return expect(api.post(`/groups/${group._id}/chat/${message.id}/flag`).then((messages) => {
|
||||
return api.post(`/groups/${group._id}/chat/${message.id}/flag`);
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: t('messageGroupChatFlagAlreadyReported'),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('own message', () => {
|
||||
|
||||
@@ -151,7 +151,7 @@ api.get = function(req, res, next) {
|
||||
}
|
||||
|
||||
if (!user.contributor.admin) {
|
||||
_purgeFlagInfoFromChat(group);
|
||||
_purgeFlagInfoFromChat(group, user);
|
||||
}
|
||||
|
||||
//Since we have a limit on how many members are populate to the group, we want to make sure the user is always in the group
|
||||
@@ -260,7 +260,7 @@ api.attachGroup = function(req, res, next) {
|
||||
if(!group) return res.json(404, {err: shared.i18n.t('messageGroupNotFound')});
|
||||
|
||||
if (!user.contributor.admin) {
|
||||
_purgeFlagInfoFromChat(group);
|
||||
_purgeFlagInfoFromChat(group, user);
|
||||
}
|
||||
|
||||
res.locals.group = group;
|
||||
@@ -1100,9 +1100,12 @@ api.questLeave = function(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function _purgeFlagInfoFromChat(group) {
|
||||
function _purgeFlagInfoFromChat(group, user) {
|
||||
group.chat = _.filter(group.chat, function(message) { return !message.flagCount || message.flagCount < 2; });
|
||||
_.each(group.chat, function (message) {
|
||||
var userHasFlagged = message.flags[user._id];
|
||||
message.flags = {};
|
||||
|
||||
if (userHasFlagged) message.flags[user._id] = userHasFlagged;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user