diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-07-10 15:40:45 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-07-13 14:10:20 +0200 |
commit | d4eaac958d3c5c68a6e4bfd47ababb61bd9fd524 (patch) | |
tree | 764e6c528b1fcd8ff830449cc2e1156dcf1b96cb /server.js | |
parent | 9479b226f6cbfb53d66123a397f46cca0f682d45 (diff) | |
download | server-d4eaac958d3c5c68a6e4bfd47ababb61bd9fd524.tar.gz |
Use sequential per-game chat ids.
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -1053,7 +1053,7 @@ const SQL_INSERT_UNREAD_CHAT = SQL("insert or ignore into unread_chats (user_id, const SQL_DELETE_UNREAD_CHAT = SQL("delete from unread_chats where user_id = ? and game_id = ?") const SQL_SELECT_GAME_CHAT = SQL("SELECT chat_id,unixepoch(time),name,message FROM game_chat_view WHERE game_id=? AND chat_id>?").raw() -const SQL_INSERT_GAME_CHAT = SQL("INSERT INTO game_chat (game_id,user_id,message) VALUES (?,?,?) RETURNING chat_id,unixepoch(time),NULL,message").raw() +const SQL_INSERT_GAME_CHAT = SQL("INSERT INTO game_chat (game_id,chat_id,user_id,message) VALUES (?, (select coalesce(max(chat_id), 0) + 1 from game_chat where game_id=?), ?,?) RETURNING chat_id,unixepoch(time),NULL,message").raw() const SQL_SELECT_GAME_NOTE = SQL("SELECT note FROM game_notes WHERE game_id=? AND role=?").pluck() const SQL_UPDATE_GAME_NOTE = SQL("INSERT OR REPLACE INTO game_notes (game_id,role,note) VALUES (?,?,?)") @@ -2202,7 +2202,7 @@ function on_getchat(socket, seen) { function on_chat(socket, message) { message = message.substring(0,4000) try { - let chat = SQL_INSERT_GAME_CHAT.get(socket.game_id, socket.user.user_id, message) + let chat = SQL_INSERT_GAME_CHAT.get(socket.game_id, socket.game_id, socket.user.user_id, message) chat[2] = socket.user.name SLOG(socket, "CHAT") for (let other of game_clients[socket.game_id]) |