Skip to content

Commit cbff89e

Browse files
committed
fix
1 parent f5a44b7 commit cbff89e

6 files changed

Lines changed: 28 additions & 9 deletions

File tree

services.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ async def _broadcast_balance(chat_id: str, balance: int) -> None:
7676
async def _broadcast_claim(chat_id: str, claimed_by_id: str | None, claimed_by_name: str | None) -> None:
7777
payload = {
7878
"type": "claim",
79-
"claimed_by_id": claimed_by_id,
8079
"claimed_by_name": claimed_by_name,
8180
}
8281
await _broadcast_chat(chat_id, payload)
@@ -197,7 +196,7 @@ async def get_public_chat(categories_id: str, chat_id: str) -> ChatSession:
197196
chat = await get_chat_for_category(categories_id, chat_id)
198197
if not chat:
199198
raise ValueError("Chat not found.")
200-
return chat
199+
return _sanitize_public_chat(chat)
201200

202201

203202
def _ensure_participant(chat: ChatSession, sender_id: str, sender_name: str, sender_role: str) -> None:
@@ -213,6 +212,20 @@ def _ensure_participant(chat: ChatSession, sender_id: str, sender_name: str, sen
213212
chat.participants.append(_serialize_participant(ChatParticipant(id=sender_id, name=sender_name, role=sender_role)))
214213

215214

215+
def _sanitize_public_chat(chat: ChatSession) -> ChatSession:
216+
sanitized = chat.copy(deep=True)
217+
sanitized.claimed_by_id = None
218+
for participant in sanitized.participants:
219+
if participant.get("role") == "admin":
220+
name = participant.get("name") or "admin"
221+
participant["id"] = f"admin-{name}"
222+
for message in sanitized.messages:
223+
if message.get("sender_role") == "admin":
224+
name = message.get("sender_name") or "admin"
225+
message["sender_id"] = f"admin-{name}"
226+
return sanitized
227+
228+
216229
async def _append_message(chat: ChatSession, message: ChatMessage, unread: bool) -> ChatSession:
217230
payload = _serialize_message(message)
218231
chat.messages.append(payload)

static/embed.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ window.PageChatEmbed = {
4848
publicChatLink() {
4949
if (!this.categoriesId || !this.chatId) return ''
5050
return `${window.location.origin}/chat/${this.categoriesId}/${this.chatId}`
51+
},
52+
isClaimedByMe() {
53+
if (!this.authUser?.username) return false
54+
return this.chatData.claimed_by_name === this.authUser.username
5155
}
5256
},
5357
methods: {
@@ -398,7 +402,6 @@ window.PageChatEmbed = {
398402
this.applyBalanceUpdate(payload.balance)
399403
}
400404
if (payload.type === 'claim') {
401-
this.chatData.claimed_by_id = payload.claimed_by_id
402405
this.chatData.claimed_by_name = payload.claimed_by_name
403406
}
404407
} catch (err) {

static/embed.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@
112112
flat
113113
color="primary"
114114
:label="
115-
chatData.claimed_by_id === authUser.id
115+
isClaimedByMe
116116
? 'Release'
117-
: chatData.claimed_by_id
117+
: chatData.claimed_by_name
118118
? 'Steal'
119119
: 'Claim'
120120
"

static/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ window.PageChat = {
296296
this.sending = true
297297
try {
298298
const payload = {
299-
sender_id: `admin-${this.g.user.id}`,
299+
sender_id: `admin-${this.g.user.username || 'support'}`,
300300
sender_name: this.g.user.username || 'support',
301301
sender_role: 'admin',
302302
message: messageText

static/public_page.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ window.PageChatPublic = {
4040
this.publicPageData?.claim_split ?? this.publicPageData?.claimSplit
4141
const value = Number(raw)
4242
return Number.isFinite(value) ? value : 0
43+
},
44+
isClaimedByMe() {
45+
if (!this.authUser?.username) return false
46+
return this.chatData.claimed_by_name === this.authUser.username
4347
}
4448
},
4549

@@ -425,7 +429,6 @@ window.PageChatPublic = {
425429
this.applyBalanceUpdate(payload.balance)
426430
}
427431
if (payload.type === 'claim') {
428-
this.chatData.claimed_by_id = payload.claimed_by_id
429432
this.chatData.claimed_by_name = payload.claimed_by_name
430433
}
431434
} catch (err) {

static/public_page.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@
115115
outline
116116
color="primary"
117117
:label="
118-
chatData.claimed_by_id === authUser.id
118+
isClaimedByMe
119119
? 'Release'
120-
: chatData.claimed_by_id
120+
: chatData.claimed_by_name
121121
? 'Steal'
122122
: 'Claim'
123123
"

0 commit comments

Comments
 (0)