only bugs man
This commit is contained in:
1 parent
5a9ba0cc23
commit
9fd01d6f78
2 files changed
+32
-10
No files matched your search
@@ -87,10 +87,15 @@ public function send(ChatSendMessageRequest $request, Conversation $conversation
|
|||||||
|
|
||||||
public function read(Conversation $conversation): JsonResponse
|
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()
|
$conversation->messages()
|
||||||
->where('user_id', '!=', $sender->id)
|
->where('user_id', '!=', $excludeId)
|
||||||
->whereNull('seen_at')
|
->whereNull('seen_at')
|
||||||
->update(['seen_at' => now()]);
|
->update(['seen_at' => now()]);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
const conversation = state.conversations.find((item) => item.id === conversationId);
|
||||||
if (!conversation || conversation.can_reply === false) {
|
if (!conversation || (!force && !conversation.unread_count)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +232,7 @@
|
|||||||
setComposer(conversation);
|
setComposer(conversation);
|
||||||
renderInbox();
|
renderInbox();
|
||||||
await loadMessages(conversationId, true);
|
await loadMessages(conversationId, true);
|
||||||
await markRead(conversationId);
|
await markRead(conversationId, true);
|
||||||
subscribeThread(conversationId);
|
subscribeThread(conversationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,7 +277,7 @@
|
|||||||
state.messages.push(message);
|
state.messages.push(message);
|
||||||
renderMessages();
|
renderMessages();
|
||||||
}
|
}
|
||||||
markRead(message.conversation_id);
|
markRead(message.conversation_id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadInbox();
|
loadInbox();
|
||||||
@@ -374,7 +378,7 @@
|
|||||||
|
|
||||||
async function mergeActiveMessages() {
|
async function mergeActiveMessages() {
|
||||||
if (!state.activeId || state.loadingMessages) {
|
if (!state.activeId || state.loadingMessages) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = await request(
|
const payload = await request(
|
||||||
@@ -398,6 +402,8 @@
|
|||||||
);
|
);
|
||||||
renderMessages();
|
renderMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
formEl.addEventListener("submit", sendMessage);
|
formEl.addEventListener("submit", sendMessage);
|
||||||
@@ -420,10 +426,21 @@
|
|||||||
loadInbox();
|
loadInbox();
|
||||||
bootEcho();
|
bootEcho();
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
loadInbox().then(() => {
|
loadInbox().then(async () => {
|
||||||
if (state.activeId) {
|
if (!state.activeId) {
|
||||||
mergeActiveMessages();
|
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);
|
}, 4000);
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
if (document.visibilityState === "visible" && state.activeId) {
|
||||||
|
markRead(state.activeId);
|
||||||
|
}
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
Reference in new issue
Block a user