fchat-rising/chat/ReportDialog.vue

90 lines
3.7 KiB
Vue
Raw Permalink Normal View History

2017-09-02 01:50:31 +00:00
<template>
2019-01-03 17:38:17 +00:00
<modal :action="l('chat.report')" @submit.prevent="submit()" :disabled="submitting" dialogClass="modal-lg">
2017-09-02 01:50:31 +00:00
<div class="alert alert-danger" v-show="error">{{error}}</div>
<div ref="caption"></div>
<br/>
<div class="form-group">
2019-01-03 17:38:17 +00:00
<h6>{{l('chat.report.conversation')}}</h6>
<p>{{conversation}}</p>
<h6>{{l('chat.report.reporting')}}</h6>
<p>{{character ? character.name : l('chat.report.general')}}</p>
<h6>{{l('chat.report.text')}}</h6>
2017-09-02 01:50:31 +00:00
<textarea class="form-control" v-model="text"></textarea>
</div>
</modal>
</template>
<script lang="ts">
2019-01-03 17:38:17 +00:00
import {Component, Hook} from '@f-list/vue-ts';
2019-09-17 17:14:14 +00:00
import {BBCodeElement} from '../bbcode/core';
2017-09-02 01:50:31 +00:00
import CustomDialog from '../components/custom_dialog';
import Modal from '../components/Modal.vue';
2019-09-17 17:14:14 +00:00
import BBCodeParser from './bbcode';
2017-09-02 01:50:31 +00:00
import {errorToString, messageToString} from './common';
import core from './core';
import {Character, Conversation} from './interfaces';
import l from './localize';
@Component({
components: {modal: Modal}
})
export default class ReportDialog extends CustomDialog {
2019-01-03 17:38:17 +00:00
character: Character | undefined;
2017-09-02 01:50:31 +00:00
text = '';
l = l;
error = '';
submitting = false;
2017-09-02 01:50:31 +00:00
2019-01-03 17:38:17 +00:00
@Hook('mounted')
2017-09-02 01:50:31 +00:00
mounted(): void {
(<Element>this.$refs['caption']).appendChild(new BBCodeParser().parseEverything(l('chat.report.description')));
}
2019-01-03 17:38:17 +00:00
@Hook('beforeDestroy')
2017-09-02 01:50:31 +00:00
beforeDestroy(): void {
(<BBCodeElement>(<Element>this.$refs['caption']).firstChild).cleanup!();
}
2019-01-03 17:38:17 +00:00
get conversation(): string {
return core.conversations.selectedConversation.name;
2017-09-02 01:50:31 +00:00
}
report(character?: Character): void {
this.error = '';
this.text = '';
const current = core.conversations.selectedConversation;
2019-01-03 17:38:17 +00:00
this.character = character !== undefined ? character : Conversation.isPrivate(current) ? current.character : undefined;
2017-09-02 01:50:31 +00:00
this.show();
}
async submit(): Promise<void> {
const conversation = core.conversations.selectedConversation;
/*tslint:disable-next-line:no-unnecessary-callback-wrapper*///https://github.com/palantir/tslint/issues/2430
const log = conversation.reportMessages.map((x) => messageToString(x));
const tab = (Conversation.isChannel(conversation) ? `${conversation.name} (${conversation.channel.id})`
: Conversation.isPrivate(conversation) ? `Conversation with ${conversation.name}` : 'Console');
2019-01-03 17:38:17 +00:00
const text = (this.character !== undefined ? `Reporting user: [user]${this.character.name}[/user] | ` : '') + this.text;
2017-09-02 01:50:31 +00:00
const data = {
character: core.connection.character,
reportText: this.text,
log: JSON.stringify(log),
channel: tab,
text: true,
reportUser: <string | undefined>undefined
};
2019-01-03 17:38:17 +00:00
if(this.character !== undefined) data.reportUser = this.character.name;
2017-09-02 01:50:31 +00:00
try {
this.submitting = true;
2019-01-03 17:38:17 +00:00
const report = (await core.connection.queryApi<{log_id?: number}>('report-submit.php', data));
2017-09-02 01:50:31 +00:00
//tslint:disable-next-line:strict-boolean-expressions
if(!report.log_id) return;
core.connection.send('SFC', {action: 'report', logid: report.log_id, report: text, tab: conversation.name});
this.hide();
} catch(e) {
this.error = errorToString(e);
} finally {
this.submitting = false;
2017-09-02 01:50:31 +00:00
}
}
}
</script>