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

View File

@@ -113,12 +113,22 @@ export default {
async reportAbuse () {
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,
chatId: this.abuseObject.id,
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();
},
async clearFlagCount () {

View File

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

View File

@@ -70,5 +70,7 @@
"notificationsRequired": "Notification ids are required.",
"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',
middlewares: [authWithHeaders()],
async handler (req, res) {
const chatReporter = chatReporterFactory('Inbox', req, res);
const message = await chatReporter.flag();
res.respond(200, message);
try {
const chatReporter = chatReporterFactory('Inbox', req, res);
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) {
// 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'));
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++;
}
updateMessageAndSave (message, updateFunc) {
updateFunc(message);
this.user.inbox.messages[message.id] = message;
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 () {
let {message, userComment} = await this.validate();
await this.flagInboxMessage(message);
await this.notify(message, userComment);
await this.markMessageAsReported(message);
return message;
}
}