msg: Fix report confirmation

pull/9714/head
Benedikt Werner 2021-09-03 16:45:42 +02:00
parent a46eb557e3
commit 2d99547b85
No known key found for this signature in database
GPG Key ID: 1DBFF0F8E9E121EB
4 changed files with 11 additions and 16 deletions

View File

@ -200,7 +200,7 @@ final class Report(
env.user.repo named data.username flatMap {
_ ?? { user =>
if (user == me) BadRequest.fuccess
else api.commFlag(Reporter(me), Suspect(user), data.resource, data.text) inject Ok
else api.commFlag(Reporter(me), Suspect(user), data.resource, data.text) inject jsonOkResult
}
}
)

View File

@ -57,16 +57,4 @@ object form {
)
)
}
def flag(username: String, resource: String, text: String) =
postForm(action := routes.Report.flag, cls := "comm-flag")(
form3.hidden("username", username),
form3.hidden("resource", resource),
form3.hidden("text", text take 140),
submitButton(
cls := "button button-empty button-red confirm",
dataIcon := "",
title := "Report spam or offensive language"
)
)
}

View File

@ -177,11 +177,18 @@ export default class MsgCtrl {
report = () => {
const user = this.data.convo?.user;
if (user) {
const text = this.data.convo?.msgs.find(m => m.user != this.data.me.id)?.text.slice(0, 140);
if (text) network.report(user.name, text).then(_ => alert('Your report has been sent.'));
const text = this.reportableMsg()?.text.slice(0, 140);
if (text)
network
.report(user.name, text)
.then(_ => alert('Your report has been sent.'))
.catch(err => alert('Failed to send report: ' + err));
}
};
reportableMsg = (): Msg | undefined =>
this.data.convo?.msgs.find(m => m.user != this.data.me.id && m.text.length > 2);
block = () => {
const userId = this.data.convo?.user.id;
if (userId) network.block(userId).then(() => this.openConvo(userId));

View File

@ -54,7 +54,7 @@ export default function renderActions(ctrl: MsgCtrl, convo: Convo): VNode[] {
hook: bind('click', withConfirm(ctrl.delete)),
})
);
if (convo.msgs[0])
if (ctrl.reportableMsg())
nodes.push(
h(`button.${cls}.bad`, {
key: 'report',