Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fd01d6f78 | ||
|
|
5a9ba0cc23 |
No files matched your search
+8
-5
@@ -51,7 +51,8 @@ AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
CHAT_SUPPORT_USER_ID=
|
||||
|
||||
# Laravel Reverb (`php artisan reverb:start` / supervisor).
|
||||
# PHP broadcasts to this host. Browsers use nginx at wss://mm.com.tm/app.
|
||||
# PHP publishes events to 127.0.0.1:8080 (REVERB_BROADCAST_* / SERVER_PORT).
|
||||
# Browsers use nginx at wss://mm.com.tm/app (VITE_REVERB_*).
|
||||
# Local:
|
||||
REVERB_APP_ID=
|
||||
REVERB_APP_KEY=
|
||||
@@ -61,10 +62,12 @@ REVERB_PORT=8080
|
||||
REVERB_SCHEME=http
|
||||
REVERB_SERVER_HOST=0.0.0.0
|
||||
REVERB_SERVER_PORT=8080
|
||||
# Production (keep SERVER_* on 8080; PHP can still use 127.0.0.1:8080):
|
||||
# REVERB_HOST=127.0.0.1
|
||||
# REVERB_PORT=8080
|
||||
# REVERB_SCHEME=http
|
||||
REVERB_BROADCAST_HOST=127.0.0.1
|
||||
REVERB_BROADCAST_PORT=8080
|
||||
REVERB_BROADCAST_SCHEME=http
|
||||
# Production: keep BROADCAST_* and SERVER_* on 127.0.0.1:8080.
|
||||
# Set VITE_REVERB_HOST=mm.com.tm VITE_REVERB_PORT=443 VITE_REVERB_SCHEME=https
|
||||
# on the frontend build. Do not point PHP at mm.com.tm:443.
|
||||
|
||||
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
|
||||
VITE_REVERB_HOST="${REVERB_HOST}"
|
||||
|
||||
@@ -87,10 +87,15 @@ public function send(ChatSendMessageRequest $request, Conversation $conversation
|
||||
|
||||
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()]);
|
||||
|
||||
|
||||
@@ -36,10 +36,10 @@
|
||||
'secret' => env('REVERB_APP_SECRET'),
|
||||
'app_id' => env('REVERB_APP_ID'),
|
||||
'options' => [
|
||||
'host' => env('REVERB_HOST'),
|
||||
'port' => env('REVERB_PORT', 443),
|
||||
'scheme' => env('REVERB_SCHEME', 'https'),
|
||||
'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
|
||||
'host' => env('REVERB_BROADCAST_HOST', '127.0.0.1'),
|
||||
'port' => (int) env('REVERB_BROADCAST_PORT', env('REVERB_SERVER_PORT', 8080)),
|
||||
'scheme' => env('REVERB_BROADCAST_SCHEME', 'http'),
|
||||
'useTLS' => env('REVERB_BROADCAST_SCHEME', 'http') === 'https',
|
||||
'path' => env('REVERB_SERVER_PATH', ''),
|
||||
],
|
||||
'client_options' => [
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user