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