mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix flagging in the new inbox collection - move flag private message to api/v4
This commit is contained in:
@@ -27,7 +27,6 @@ div
|
|||||||
span.action(v-if='(inbox || (user.flags.communityGuidelinesAccepted && msg.uuid !== "system")) && !isMessageReported', @click='report(msg)')
|
span.action(v-if='(inbox || (user.flags.communityGuidelinesAccepted && msg.uuid !== "system")) && !isMessageReported', @click='report(msg)')
|
||||||
.svg-icon(v-html="icons.report", v-once)
|
.svg-icon(v-html="icons.report", v-once)
|
||||||
span(v-once) {{$t('report')}}
|
span(v-once) {{$t('report')}}
|
||||||
// @TODO make flagging/reporting work in the inbox. NOTE: it must work even if the communityGuidelines are not accepted and it MUST work for messages that you have SENT as well as received. -- Alys
|
|
||||||
span.action(v-if='msg.uuid === user._id || inbox || user.contributor.admin', @click='remove()')
|
span.action(v-if='msg.uuid === user._id || inbox || user.contributor.admin', @click='remove()')
|
||||||
.svg-icon(v-html="icons.delete", v-once)
|
.svg-icon(v-html="icons.delete", v-once)
|
||||||
span(v-once) {{$t('delete')}}
|
span(v-once) {{$t('delete')}}
|
||||||
@@ -238,7 +237,7 @@ export default {
|
|||||||
return achievementsLib.getContribText(message.contributor, message.backer) || '';
|
return achievementsLib.getContribText(message.contributor, message.backer) || '';
|
||||||
},
|
},
|
||||||
isMessageReported () {
|
isMessageReported () {
|
||||||
return this.msg.reported || this.reported;
|
return this.msg.flags && this.msg.flags[this.user.id] || this.reported;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|||||||
42
website/server/controllers/api-v4/members.js
Normal file
42
website/server/controllers/api-v4/members.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { authWithHeaders } from '../../middlewares/auth';
|
||||||
|
import { chatReporterFactory } from '../../libs/chatReporting/chatReporterFactory';
|
||||||
|
|
||||||
|
let api = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /api/v4/members/flag-private-message/:messageId Flag a private message
|
||||||
|
* @apiDescription A message will be hidden immediately if a moderator flags the message. An email is sent to the moderators about every flagged message.
|
||||||
|
* @apiName FlagPrivateMessage
|
||||||
|
* @apiGroup Member
|
||||||
|
*
|
||||||
|
* @apiParam (Path) {UUID} messageId The private message id
|
||||||
|
*
|
||||||
|
* @apiSuccess {Object} data The flagged chat message
|
||||||
|
* @apiSuccess {UUID} data.id The id of the message
|
||||||
|
* @apiSuccess {String} data.text The text of the message
|
||||||
|
* @apiSuccess {Number} data.timestamp The timestamp of the message in milliseconds
|
||||||
|
* @apiSuccess {Object} data.likes The likes of the message
|
||||||
|
* @apiSuccess {Object} data.flags The flags of the message
|
||||||
|
* @apiSuccess {Number} data.flagCount The number of flags the message has
|
||||||
|
* @apiSuccess {UUID} data.uuid The user id of the author of the message
|
||||||
|
* @apiSuccess {String} data.user The username of the author of the message
|
||||||
|
*
|
||||||
|
* @apiUse MessageNotFound
|
||||||
|
* @apiUse MessageIdRequired
|
||||||
|
* @apiError (404) {NotFound} messageGroupChatFlagAlreadyReported The message has already been flagged
|
||||||
|
*/
|
||||||
|
api.flagPrivateMessage = {
|
||||||
|
method: 'POST',
|
||||||
|
url: '/members/flag-private-message/:messageId',
|
||||||
|
middlewares: [authWithHeaders()],
|
||||||
|
async handler (req, res) {
|
||||||
|
const chatReporter = chatReporterFactory('Inbox', req, res);
|
||||||
|
const message = await chatReporter.flag();
|
||||||
|
res.respond(200, {
|
||||||
|
ok: true,
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = api;
|
||||||
@@ -10,6 +10,7 @@ import slack from '../slack';
|
|||||||
import apiError from '../apiError';
|
import apiError from '../apiError';
|
||||||
|
|
||||||
import _find from 'lodash/find';
|
import _find from 'lodash/find';
|
||||||
|
import * as inboxLib from '../inbox';
|
||||||
|
|
||||||
const FLAG_REPORT_EMAILS = nconf.get('FLAG_REPORT_EMAIL').split(',').map((email) => {
|
const FLAG_REPORT_EMAILS = nconf.get('FLAG_REPORT_EMAIL').split(',').map((email) => {
|
||||||
return { email, canSend: true };
|
return { email, canSend: true };
|
||||||
@@ -33,7 +34,7 @@ export default class InboxChatReporter extends ChatReporter {
|
|||||||
this.inboxUser = await User.findOne({_id: this.req.query.userId});
|
this.inboxUser = await User.findOne({_id: this.req.query.userId});
|
||||||
}
|
}
|
||||||
|
|
||||||
let messages = this.inboxUser.inbox.messages;
|
const messages = await inboxLib.getUserInbox(this.inboxUser);
|
||||||
|
|
||||||
const message = _find(messages, (m) => m.id === this.req.params.messageId);
|
const message = _find(messages, (m) => m.id === this.req.params.messageId);
|
||||||
if (!message) throw new NotFound(this.res.t('messageGroupChatNotFound'));
|
if (!message) throw new NotFound(this.res.t('messageGroupChatNotFound'));
|
||||||
@@ -70,10 +71,7 @@ export default class InboxChatReporter extends ChatReporter {
|
|||||||
updateMessageAndSave (message, updateFunc) {
|
updateMessageAndSave (message, updateFunc) {
|
||||||
updateFunc(message);
|
updateFunc(message);
|
||||||
|
|
||||||
this.inboxUser.inbox.messages[message.id] = message;
|
return inboxLib.updateMessage(message);
|
||||||
this.inboxUser.markModified('inbox.messages');
|
|
||||||
|
|
||||||
return this.inboxUser.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
flagInboxMessage (message) {
|
flagInboxMessage (message) {
|
||||||
|
|||||||
@@ -45,3 +45,13 @@ export async function clearPMs (user) {
|
|||||||
Inbox.remove({ownerId: user._id}).exec(),
|
Inbox.remove({ownerId: user._id}).exec(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateMessage (message) {
|
||||||
|
const messagesInDb = await Inbox
|
||||||
|
.find({id: message.id})
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
const messageInDb = messagesInDb[0];
|
||||||
|
|
||||||
|
await messageInDb.update(message);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user