feat(Chat): implement chat incident reporting feature
- Added reportChatIncident method in ChatController to handle reporting of chat incidents. - Introduced a new API route for reporting incidents in chatRouter. - Implemented chatService methods to ensure the chat report table is created and to handle incident data storage. - Enhanced frontend components to allow users to report incidents in both multi and random chat dialogs. - Updated internationalization files to include new strings for reporting functionality in multiple languages.
This commit is contained in:
@@ -32,6 +32,14 @@
|
||||
<input type="text" v-model="inputtext" @keyup.enter="sendMessage" />
|
||||
</label>
|
||||
<img src="/images/icons/enter16.png" @click="sendMessage" />
|
||||
<button
|
||||
v-if="partner"
|
||||
type="button"
|
||||
class="report-btn"
|
||||
@click="reportCurrentChat"
|
||||
>
|
||||
{{ $t('chat.randomchat.report') }}
|
||||
</button>
|
||||
<img src="/images/icons/dice16.png" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -61,6 +69,7 @@ import DialogWidget from '@/components/DialogWidget.vue';
|
||||
import { mapGetters } from 'vuex';
|
||||
import axios from 'axios';
|
||||
import DOMPurify from 'dompurify';
|
||||
import { reportChatIncident } from '@/api/chatApi.js';
|
||||
|
||||
export default {
|
||||
name: 'RandomChatDialog',
|
||||
@@ -245,6 +254,37 @@ export default {
|
||||
this.messages.push({ type: 'system', tr: 'chat.randomchat.waitingForMatch' });
|
||||
}
|
||||
},
|
||||
async reportCurrentChat() {
|
||||
if (!this.partner || !this.messages.length) return;
|
||||
const confirmed = window.confirm(this.$t('chat.randomchat.reportConfirm'));
|
||||
if (!confirmed) return;
|
||||
const payload = {
|
||||
context: 'random_chat',
|
||||
reporterHashedId: this.user?.hashedId || null,
|
||||
reporterRandomId: this.userId || null,
|
||||
reporterUsername: this.user?.username || null,
|
||||
offenderRandomId: this.partner?.id || null,
|
||||
offenderUsername: this.$t('chat.randomchat.partner'),
|
||||
incidentAt: new Date().toISOString(),
|
||||
chatHistory: this.messages.map((entry) => ({
|
||||
type: entry?.type || 'message',
|
||||
user: entry?.type === 'self' ? (this.user?.username || 'self') : (entry?.user || 'partner'),
|
||||
text: entry?.tr ? this.$t(entry.tr) : (entry?.text || ''),
|
||||
timestamp: Date.now(),
|
||||
})),
|
||||
metadata: {
|
||||
mode: 'random_chat',
|
||||
partnerAge: this.partner?.age || null,
|
||||
partnerGender: this.partner?.gender || null
|
||||
}
|
||||
};
|
||||
try {
|
||||
await reportChatIncident(payload);
|
||||
this.messages.push({ type: 'system', text: this.$t('chat.randomchat.reportSent') });
|
||||
} catch (_) {
|
||||
this.messages.push({ type: 'system', text: this.$t('chat.randomchat.reportError') });
|
||||
}
|
||||
},
|
||||
|
||||
renderMessage(message) {
|
||||
if (message.type === 'system') {
|
||||
@@ -318,4 +358,8 @@ export default {
|
||||
.inputline>label>input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.report-btn {
|
||||
margin-left: 0.4em;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user