Skip to content

Commit 78c5168

Browse files
committed
auto unload of chat
1 parent 959ab7a commit 78c5168

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/public/shells/chat/src/chat.mjs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @typedef {import('../../../../decl/charAPI.ts').CharAPI_t} CharAPI_t */
2-
/** @typedef {import('../../../../decl/WorldAPI.ts').WorldAPI_t} WorldAPI_t */
3-
/** @typedef {import('../../../../decl/UserAPI.ts').UserAPI_t} UserAPI_t */
2+
/** @typedef {import('../../../../decl/worldAPI.ts').WorldAPI_t} WorldAPI_t */
3+
/** @typedef {import('../../../../decl/userAPI.ts').UserAPI_t} UserAPI_t */
44
/** @typedef {import('../../../../decl/basedefs.ts').locale_t} locale_t */
55

66
import { Buffer } from 'node:buffer'
@@ -30,7 +30,7 @@ import { addfile, getfile } from './files.mjs'
3030
const chatMetadatas = new Map()
3131
const chatUiSockets = new Map()
3232
const chatDeleteTimers = new Map()
33-
const CHAT_DELETE_TIMEOUT = ms('30m')
33+
const CHAT_UNLOAD_TIMEOUT = ms('30m')
3434

3535
export function registerChatUiSocket(chatid, ws) {
3636
if (chatDeleteTimers.has(chatid)) {
@@ -49,17 +49,21 @@ export function registerChatUiSocket(chatid, ws) {
4949
socketSet.delete(ws)
5050
console.log(`Chat UI WebSocket disconnected for chat ${chatid}. Total: ${socketSet.size}`)
5151
const chatData = chatMetadatas.get(chatid)
52-
if (!socketSet.size && chatUiSockets.delete(chatid) && !is_VividChat(chatData?.chatMetadata)) {
52+
if (!socketSet.size && chatUiSockets.delete(chatid)) {
5353
clearTimeout(chatDeleteTimers.get(chatid))
5454
chatDeleteTimers.set(chatid, setTimeout(async () => {
5555
try {
56-
if (chatUiSockets.has(chatid) || is_VividChat(chatData.chatMetadata)) return
57-
await deleteChat([chatid], chatData.username)
56+
if (chatUiSockets.has(chatid)) return
57+
if (is_VividChat(chatData?.chatMetadata)) {
58+
await saveChat(chatid)
59+
chatData.chatMetadata = null
60+
}
61+
else await deleteChat([chatid], chatData.username)
5862
}
5963
finally {
6064
chatDeleteTimers.delete(chatid)
6165
}
62-
}, CHAT_DELETE_TIMEOUT))
66+
}, CHAT_UNLOAD_TIMEOUT))
6367
}
6468
})
6569
}

src/server/server.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs'
2-
import path from 'node:path'
32
import http from 'node:http'
43
import https from 'node:https'
4+
import path from 'node:path'
55
import process from 'node:process'
66

77
import { on_shutdown } from 'npm:on-shutdown'

0 commit comments

Comments
 (0)