mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
refactor {group,inbox}-chatReporter variables
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import {
|
||||
} from '../errors';
|
||||
import { getUserInfo } from '../email';
|
||||
import { getGroupUrl, getUserInfo } from '../email';
|
||||
import { getAuthorEmailFromMessage } from '../chat';
|
||||
|
||||
export default class ChatReporter {
|
||||
@@ -11,27 +9,51 @@ export default class ChatReporter {
|
||||
|
||||
async validate () {}
|
||||
|
||||
async notify (group, message) {
|
||||
const reporterEmailContent = getUserInfo(this.user, ['email']).email;
|
||||
this.authorEmail = await getAuthorEmailFromMessage(message);
|
||||
this.emailVariables = [
|
||||
async getMessageVariables (group, message) {
|
||||
const reporterEmail = getUserInfo(this.user, ['email']).email;
|
||||
|
||||
const authorVariables = await this.getAuthorVariables(message);
|
||||
const groupUrl = getGroupUrl(group);
|
||||
|
||||
return [
|
||||
{name: 'MESSAGE_TIME', content: (new Date(message.timestamp)).toString()},
|
||||
{name: 'MESSAGE_TEXT', content: message.text},
|
||||
|
||||
{name: 'REPORTER_DISPLAYNAME', content: this.user.profile.name},
|
||||
{name: 'REPORTER_USERNAME', content: this.user.auth.local.username},
|
||||
{name: 'REPORTER_UUID', content: this.user._id},
|
||||
{name: 'REPORTER_EMAIL', content: reporterEmailContent},
|
||||
{name: 'REPORTER_EMAIL', content: reporterEmail},
|
||||
{name: 'REPORTER_MODAL_URL', content: `/static/front/#?memberId=${this.user._id}`},
|
||||
|
||||
{name: 'AUTHOR_DISPLAYNAME', content: message.user},
|
||||
{name: 'AUTHOR_USERNAME', content: message.username},
|
||||
{name: 'AUTHOR_UUID', content: message.uuid},
|
||||
{name: 'AUTHOR_EMAIL', content: this.authorEmail},
|
||||
{name: 'AUTHOR_MODAL_URL', content: `/static/front/#?memberId=${message.uuid}`},
|
||||
...authorVariables,
|
||||
|
||||
{name: 'GROUP_NAME', content: group.name},
|
||||
{name: 'GROUP_TYPE', content: group.type},
|
||||
{name: 'GROUP_ID', content: group._id},
|
||||
{name: 'GROUP_URL', content: groupUrl || 'N/A'},
|
||||
];
|
||||
}
|
||||
|
||||
createGenericAuthorVariables (prefix, {user, username, uuid, email}) {
|
||||
return [
|
||||
{name: `${prefix}_DISPLAYNAME`, content: user},
|
||||
{name: `${prefix}_USERNAME`, content: username},
|
||||
{name: `${prefix}_UUID`, content: uuid},
|
||||
{name: `${prefix}_EMAIL`, content: email},
|
||||
{name: `${prefix}_MODAL_URL`, content: `/static/front/#?memberId=${uuid}`},
|
||||
];
|
||||
}
|
||||
|
||||
async getAuthorVariables (message) {
|
||||
this.authorEmail = await getAuthorEmailFromMessage(message);
|
||||
return this.createGenericAuthorVariables('AUTHOR', {
|
||||
user: message.user,
|
||||
username: message.username,
|
||||
uuid: message.uuid,
|
||||
email: this.authorEmail,
|
||||
});
|
||||
}
|
||||
|
||||
async flag () {
|
||||
throw new Error('Flag must be implemented');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user