report & mark message

This commit is contained in:
negue
2018-06-08 20:26:26 +02:00
parent e3b2443029
commit dc5722d0de
6 changed files with 86 additions and 26 deletions

View File

@@ -13,6 +13,8 @@ div
.svg-icon(v-html="tierIcon", v-if='showShowTierStyle') .svg-icon(v-html="tierIcon", v-if='showShowTierStyle')
p.time {{msg.timestamp | timeAgo}} p.time {{msg.timestamp | timeAgo}}
.text(v-markdown='msg.text') .text(v-markdown='msg.text')
.reported(v-if="isMessageReported")
span(v-once) {{ $t('reportedMessage')}}
hr hr
.action(@click='like()', v-if='!inbox && msg.likes', :class='{active: msg.likes[user._id]}') .action(@click='like()', v-if='!inbox && msg.likes', :class='{active: msg.likes[user._id]}')
.svg-icon(v-html="icons.like") .svg-icon(v-html="icons.like")
@@ -20,13 +22,13 @@ div
span(v-if='msg.likes[user._id]') {{ $t('liked') }} span(v-if='msg.likes[user._id]') {{ $t('liked') }}
span.action(v-if='!inbox', @click='copyAsTodo(msg)') span.action(v-if='!inbox', @click='copyAsTodo(msg)')
.svg-icon(v-html="icons.copy", v-once) .svg-icon(v-html="icons.copy", v-once)
| {{$t('copyAsTodo')}} span(v-once) {{$t('copyAsTodo')}}
span.action(v-if='inbox || (user.flags.communityGuidelinesAccepted && msg.uuid !== "system")', @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)
| {{$t('report')}} span(v-once) {{$t('report')}}
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)
| {{$t('delete')}} span(v-once) {{$t('delete')}}
span.action.float-right.liked(v-if='likeCount > 0') span.action.float-right.liked(v-if='likeCount > 0')
.svg-icon(v-html="icons.liked") .svg-icon(v-html="icons.liked")
| + {{ likeCount }} | + {{ likeCount }}
@@ -34,6 +36,7 @@ div
<style lang="scss" scoped> <style lang="scss" scoped>
@import '~client/assets/scss/tiers.scss'; @import '~client/assets/scss/tiers.scss';
@import '~client/assets/scss/colors.scss';
.mentioned-icon { .mentioned-icon {
width: 16px; width: 16px;
@@ -104,6 +107,10 @@ div
.action.active, .active .svg-icon { .action.active, .active .svg-icon {
color: #46a7d9 color: #46a7d9
} }
.reported {
color: $maroon-50;
}
</style> </style>
<script> <script>
@@ -154,6 +161,7 @@ export default {
tier9, tier9,
tierNPC, tierNPC,
}), }),
reported: false,
}; };
}, },
directives: { directives: {
@@ -218,6 +226,9 @@ export default {
} }
return this.icons[`tier${message.contributor.level}`]; return this.icons[`tier${message.contributor.level}`];
}, },
isMessageReported () {
return this.msg.reported || this.reported;
},
}, },
methods: { methods: {
async like () { async like () {
@@ -239,7 +250,15 @@ export default {
copyAsTodo (message) { copyAsTodo (message) {
this.$root.$emit('habitica::copy-as-todo', message); this.$root.$emit('habitica::copy-as-todo', message);
}, },
async report () { report () {
this.$root.$on('habitica:report-result', data => {
if (data.ok) {
this.reported = true;
}
this.$root.$off('habitica:report-result');
});
this.$root.$emit('habitica::report-chat', { this.$root.$emit('habitica::report-chat', {
message: this.msg, message: this.msg,
groupId: this.groupId || 'privateMessage', groupId: this.groupId || 'privateMessage',

View File

@@ -113,12 +113,22 @@ export default {
async reportAbuse () { async reportAbuse () {
this.text('Thank you for reporting this violation. The moderators have been notified.'); this.text('Thank you for reporting this violation. The moderators have been notified.');
await this.$store.dispatch('chat:flag', { let result = await this.$store.dispatch('chat:flag', {
groupId: this.groupId, groupId: this.groupId,
chatId: this.abuseObject.id, chatId: this.abuseObject.id,
comment: this.reportComment, comment: this.reportComment,
}); });
console.info('error', result);
this.$root.$emit('habitica:report-result', result);
if (!result.ok && result.error) {
alert('errrorororor!');
console.info('error', result);
this.error(result.error);
}
this.close(); this.close();
}, },
async clearFlagCount () { async clearFlagCount () {

View File

@@ -80,6 +80,9 @@ export async function flag (store, payload) {
const response = await axios.post(url, { const response = await axios.post(url, {
comment: payload.comment, comment: payload.comment,
}); });
console.info('response', response.data.data);
return response.data.data; return response.data.data;
} }

View File

@@ -70,5 +70,7 @@
"notificationsRequired": "Notification ids are required.", "notificationsRequired": "Notification ids are required.",
"unallocatedStatsPoints": "You have <span class=\"notification-bold-blue\"><%= points %> unallocated Stat Points</span>", "unallocatedStatsPoints": "You have <span class=\"notification-bold-blue\"><%= points %> unallocated Stat Points</span>",
"beginningOfConversation": "This is the beginning of your conversation with <%= userName %>. Remember to be kind, respectful, and follow the Community Guidelines!" "beginningOfConversation": "This is the beginning of your conversation with <%= userName %>. Remember to be kind, respectful, and follow the Community Guidelines!",
"reportedMessage": "You have reported this message to moderators."
} }

View File

@@ -543,9 +543,19 @@ api.flagPrivateMessage = {
url: '/members/flag-private-message/:messageId', url: '/members/flag-private-message/:messageId',
middlewares: [authWithHeaders()], middlewares: [authWithHeaders()],
async handler (req, res) { async handler (req, res) {
const chatReporter = chatReporterFactory('Inbox', req, res); try {
const message = await chatReporter.flag(); const chatReporter = chatReporterFactory('Inbox', req, res);
res.respond(200, message); const message = await chatReporter.flag();
res.respond(200, {
ok: true,
message,
});
} catch (e) {
res.respond(500, {
ok: false,
error: e,
});
}
}, },
}; };

View File

@@ -61,32 +61,48 @@ export default class InboxChatReporter extends ChatReporter {
}); });
} }
async flagInboxMessage (message) { updateMessageAndSave (message, updateFunc) {
// Log user ids that have flagged the message updateFunc(message);
if (!message.flags) message.flags = {};
// TODO fix error type
if (message.flags[this.user._id] && !this.user.contributor.admin) throw new NotFound(this.res.t('messageGroupChatFlagAlreadyReported'));
message.flags[this.user._id] = true;
// Log total number of flags (publicly viewable)
if (!message.flagCount) message.flagCount = 0;
if (this.user.contributor.admin) {
// Arbitrary amount, higher than 2
message.flagCount = 5;
} else {
message.flagCount++;
}
this.user.inbox.messages[message.id] = message; this.user.inbox.messages[message.id] = message;
this.user.markModified('inbox.messages'); this.user.markModified('inbox.messages');
await this.user.save(); return this.user.save();
}
flagInboxMessage (message) {
// Log user ids that have flagged the message
if (!message.flags) message.flags = {};
// TODO fix error type
if (message.flags[this.user._id] && !this.user.contributor.admin) {
throw new NotFound(this.res.t('messageGroupChatFlagAlreadyReported'));
}
return this.updateMessageAndSave(message, (m) => {
m.flags[this.user._id] = true;
// Log total number of flags (publicly viewable)
if (!m.flagCount) m.flagCount = 0;
if (this.user.contributor.admin) {
// Arbitrary amount, higher than 2
m.flagCount = 5;
} else {
m.flagCount++;
}
});
}
async markMessageAsReported (message) {
return this.updateMessageAndSave(message, (m) => {
m.reported = true;
});
} }
async flag () { async flag () {
let {message, userComment} = await this.validate(); let {message, userComment} = await this.validate();
await this.flagInboxMessage(message); await this.flagInboxMessage(message);
await this.notify(message, userComment); await this.notify(message, userComment);
await this.markMessageAsReported(message);
return message; return message;
} }
} }