Send back flag data if user had flagged the message.

This commit is contained in:
Blade Barringer
2015-11-10 08:15:54 -06:00
parent 6b7a757459
commit 1fc21167dc
2 changed files with 17 additions and 3 deletions

View File

@@ -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', () => {

View File

@@ -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;
});
}