only bugs man

This commit is contained in:
Mekan1206
2026-08-16 17:56:17 +05:00
parent 5a9ba0cc23
commit 9fd01d6f78
2 changed files with 32 additions and 10 deletions

View File

@@ -87,10 +87,15 @@ class SupportChatController extends Controller
public function read(Conversation $conversation): JsonResponse
{
$sender = $this->assertCanReply(request()->user(), $conversation);
$actor = request()->user();
$this->assertCanView($actor, $conversation);
$excludeId = ChatSupport::isOperator($actor)
? ChatSupport::user()->id
: $actor->id;
$conversation->messages()
->where('user_id', '!=', $sender->id)
->where('user_id', '!=', $excludeId)
->whereNull('seen_at')
->update(['seen_at' => now()]);

View File

@@ -194,9 +194,13 @@
}
}
async function markRead(conversationId) {
async function markRead(conversationId, force) {
if (!conversationId || conversationId !== state.activeId) {
return;
}
const conversation = state.conversations.find((item) => item.id === conversationId);
if (!conversation || conversation.can_reply === false) {
if (!conversation || (!force && !conversation.unread_count)) {
return;
}
@@ -228,7 +232,7 @@
setComposer(conversation);
renderInbox();
await loadMessages(conversationId, true);
await markRead(conversationId);
await markRead(conversationId, true);
subscribeThread(conversationId);
}
@@ -273,7 +277,7 @@
state.messages.push(message);
renderMessages();
}
markRead(message.conversation_id);
markRead(message.conversation_id, true);
}
loadInbox();
@@ -374,7 +378,7 @@
async function mergeActiveMessages() {
if (!state.activeId || state.loadingMessages) {
return;
return false;
}
const payload = await request(
@@ -398,6 +402,8 @@
);
renderMessages();
}
return added;
}
formEl.addEventListener("submit", sendMessage);
@@ -420,10 +426,21 @@
loadInbox();
bootEcho();
setInterval(() => {
loadInbox().then(() => {
if (state.activeId) {
mergeActiveMessages();
loadInbox().then(async () => {
if (!state.activeId) {
return;
}
const added = await mergeActiveMessages();
const conversation = state.conversations.find((item) => item.id === state.activeId);
if (added || (conversation && conversation.unread_count > 0)) {
await markRead(state.activeId, true);
}
});
}, 4000);
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "visible" && state.activeId) {
markRead(state.activeId);
}
});
})();