feat(RandomChatDialog): enhance chat reporting functionality
All checks were successful
Deploy to production / deploy (push) Successful in 2m1s

- Added logic to enable the reporting button based on chat state and message presence.
- Introduced a computed property to determine if the chat can be reported.
- Updated the reporting method to accommodate the last partner in case the current partner is unavailable.
- Improved handling of partner details in the reporting payload for better accuracy.
This commit is contained in:
Torsten Schulz (local)
2026-04-27 15:23:48 +02:00
parent ff68fb72c4
commit e94ae4350d

View File

@@ -33,9 +33,9 @@
</label> </label>
<img src="/images/icons/enter16.png" @click="sendMessage" /> <img src="/images/icons/enter16.png" @click="sendMessage" />
<button <button
v-if="partner"
type="button" type="button"
class="report-btn" class="report-btn"
:disabled="!canReportChat"
@click="reportCurrentChat" @click="reportCurrentChat"
> >
{{ $t('chat.randomchat.report') }} {{ $t('chat.randomchat.report') }}
@@ -82,6 +82,9 @@ export default {
// Use translation key; DialogWidget will translate when isTitleTranslated=true // Use translation key; DialogWidget will translate when isTitleTranslated=true
return [{ text: 'chat.randomchat.close' }]; return [{ text: 'chat.randomchat.close' }];
}, },
canReportChat() {
return this.messages.length > 0 && !!this.lastPartner;
},
}, },
data() { data() {
return { return {
@@ -101,6 +104,7 @@ export default {
searchInterval: null, searchInterval: null,
messages: [], messages: [],
partner: null, partner: null,
lastPartner: null,
messagesInterval: null, messagesInterval: null,
}; };
}, },
@@ -158,6 +162,7 @@ export default {
// Reset state and close widget // Reset state and close widget
this.chatIsRunning = false; this.chatIsRunning = false;
this.partner = null; this.partner = null;
this.lastPartner = null;
this.messages = []; this.messages = [];
this.$refs.dialog.close(); this.$refs.dialog.close();
}, },
@@ -185,14 +190,15 @@ export default {
if (response.data.status === 'matched') { if (response.data.status === 'matched') {
this.searching = false; this.searching = false;
clearInterval(this.searchInterval); clearInterval(this.searchInterval);
const initText = this.$t('chat.randomchat.chatpartner') const initText = this.$t('chat.randomchat.chatpartner')
.replace( .replace(
'<gender>', '<gender>',
this.$t(`chat.randomchat.partnergender${response.data.user.gender}`) this.$t(`chat.randomchat.partnergender${response.data.user.gender}`)
) )
.replace('<age>', response.data.user.age); .replace('<age>', response.data.user.age);
this.messages = [{ type: 'system', text: initText }]; this.messages = [{ type: 'system', text: initText }];
this.partner = response.data.user; this.partner = response.data.user;
this.lastPartner = response.data.user;
this.messagesInterval = setInterval(this.getNewMessages, 250); this.messagesInterval = setInterval(this.getNewMessages, 250);
} else if (this.autosearch && !this.searchInterval) { } else if (this.autosearch && !this.searchInterval) {
this.searchInterval = setInterval(this.findMatch, 500); this.searchInterval = setInterval(this.findMatch, 500);
@@ -255,7 +261,8 @@ export default {
} }
}, },
async reportCurrentChat() { async reportCurrentChat() {
if (!this.partner || !this.messages.length) return; const offender = this.lastPartner;
if (!offender || !this.messages.length) return;
const confirmed = window.confirm(this.$t('chat.randomchat.reportConfirm')); const confirmed = window.confirm(this.$t('chat.randomchat.reportConfirm'));
if (!confirmed) return; if (!confirmed) return;
const payload = { const payload = {
@@ -263,7 +270,7 @@ export default {
reporterHashedId: this.user?.hashedId || null, reporterHashedId: this.user?.hashedId || null,
reporterRandomId: this.userId || null, reporterRandomId: this.userId || null,
reporterUsername: this.user?.username || null, reporterUsername: this.user?.username || null,
offenderRandomId: this.partner?.id || null, offenderRandomId: offender?.id || null,
offenderUsername: this.$t('chat.randomchat.partner'), offenderUsername: this.$t('chat.randomchat.partner'),
incidentAt: new Date().toISOString(), incidentAt: new Date().toISOString(),
chatHistory: this.messages.map((entry) => ({ chatHistory: this.messages.map((entry) => ({
@@ -274,8 +281,8 @@ export default {
})), })),
metadata: { metadata: {
mode: 'random_chat', mode: 'random_chat',
partnerAge: this.partner?.age || null, partnerAge: offender?.age || null,
partnerGender: this.partner?.gender || null partnerGender: offender?.gender || null
} }
}; };
try { try {