-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
238 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<template name="report"> | ||
{{#modal title=title }} | ||
<div class="header"> | ||
<h2 class="h2">{{ title }}</h2> | ||
<hr class="separator" /> | ||
</div> | ||
<div class="report"> | ||
<select name="reason-select" | ||
id="reason-select" | ||
class="js-report-reason-select select"> | ||
{{#each reportAllReasons }} | ||
<option value="{{ this }}"> | ||
{{ this }} | ||
</option> | ||
{{/each }} | ||
</select> | ||
<form class="js-console-form"> | ||
<textarea class="textarea js-command-input" name="js-command-input" placeholder="Explain here" autocomplete="off"></textarea> | ||
<button type="button" class="button js-button-submit">Send</button> | ||
</form> | ||
</div> | ||
{{/modal }} | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
const inputSelector = '.js-command-input'; | ||
|
||
|
||
const getUser = id => Meteor.users.findOne(id); | ||
|
||
const getMessage = id => Messages.findOne(id); | ||
|
||
const getAllAdmins = () => Meteor.users.find({ roles: { admin: true } }).fetch(); | ||
|
||
function buildMessage(text, level, reason, reported, messageId) { | ||
let messageText = ''; | ||
if (messageId) { | ||
const message = getMessage(messageId); | ||
messageText = `Message: ${messageId} - ${message.text}\nChannel: ${message.channel}\n`; | ||
} | ||
|
||
return `REPORT LOG - ${Date()}\n\n\nLevel: ${level}\n\nJustification:\n${text}\n\nReason:\n${reason}\n\n${messageText}Reported:\n${reported._id} - ${reported.profile.name}`; | ||
} | ||
|
||
const sendReport = (channel, text) => { | ||
let messageId; | ||
|
||
try { | ||
messageId = messagesModule.sendMessage(channel, text); | ||
lp.notif.success('Report sent'); | ||
} catch (e) { lp.notif.error(e); } | ||
|
||
return messageId; | ||
}; | ||
|
||
const closeConsole = () => { closeModal('report'); }; | ||
|
||
const onSubmit = (reason, reported, messageId) => { | ||
if (reported._id === Meteor.userId()) { | ||
lp.notif.error('You can\'t report yourself'); | ||
return; | ||
} | ||
const isAdmin = getUser(Meteor.userId()).roles?.admin; | ||
|
||
const text = document.querySelector(inputSelector).value; | ||
const currentLevel = Meteor.user().profile.levelId; | ||
if (!text) { | ||
lp.notif.error('Please enter a message'); | ||
return; | ||
} | ||
if (text.length > 1024) { | ||
lp.notif.error('Message is too long'); | ||
return; | ||
} | ||
let admins = getAllAdmins(); | ||
if (isAdmin) { | ||
admins = admins.filter(admin => admin._id !== Meteor.userId()); | ||
} | ||
if (!admins.length) { | ||
// Quiting even if the user is an admin because we don't want to create a conversation with himself | ||
lp.notif.error('No admins found'); | ||
return; | ||
} | ||
const adminsLevel = admins.filter(admin => admin.profile.levelId === currentLevel); | ||
if (adminsLevel.length) { | ||
admins = adminsLevel; | ||
} | ||
const level = Levels.findOne(currentLevel).name; | ||
const message = buildMessage(text, level, reason, reported, messageId); | ||
const channel = [...admins.map(admin => admin._id), Meteor.userId()].sort().join(';'); | ||
|
||
sendReport(channel, message); | ||
|
||
closeConsole(); | ||
}; | ||
|
||
Template.report.onCreated(function () { | ||
this.reason = new ReactiveVar('Non-specified'); | ||
}); | ||
|
||
Template.report.helpers({ | ||
title() { | ||
const template = Template.instance(); | ||
return `Report user - ${getUser(template.data.userId)?.profile.name}`; | ||
}, | ||
reportAllReasons() { | ||
const reportAllReasons = ['Non-specified', 'Spam', 'Abusive chat', 'Cheating', 'Offensive name', 'Other']; | ||
return reportAllReasons; | ||
}, | ||
explanation() { | ||
switch (Template.instance().reason.get()) { | ||
case 'Non-specified': | ||
return ''; | ||
case 'Spam': | ||
return 'Spam is the use of the messages to send too many messages in a short period of time, to send the same message multiple times, or to repeatedly connect and disconnect with an user'; | ||
case 'Abusive chat': | ||
return 'Abusive chat is the use of the messages to harass, insult, or threaten another user'; | ||
case 'Cheating': | ||
return 'Cheating is the use of any third-party software or any other method to gain an unfair advantage in the game'; | ||
case 'Offensive name': | ||
return 'Offensive name is the use of a name that is offensive, vulgar, or inappropriate'; | ||
case 'Other': | ||
return 'Other behavior that is not listed above, please specify'; | ||
default: | ||
return ''; | ||
} | ||
}, | ||
}); | ||
|
||
Template.report.events({ | ||
'change .js-report-reason-select'(event) { | ||
Template.instance().reason.set(event.target.value); | ||
}, | ||
'click .js-button-submit'(event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
const template = Template.instance(); | ||
lp.notif.confirm('Report user', `Do you really want to report this message?`, () => onSubmit(template.reason.get(), getUser(template.data.userId), template.data.messageId)); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.report { | ||
width: 90%; | ||
height: 80%; | ||
margin: auto; | ||
|
||
form { | ||
height: 100%; | ||
textarea { | ||
margin-top: 25px; | ||
width: 100%; | ||
height: 80%; | ||
} | ||
button { | ||
margin-bottom: 0px; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters