Mercurial Hosting > chat
diff src/index.html.luan @ 58:7b6691bd65c3
chat_key
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 04 Mar 2025 07:38:43 -0700 |
parents | 323ddacc1593 |
children | 8270106644db |
line wrap: on
line diff
--- a/src/index.html.luan Tue Mar 04 07:05:12 2025 -0700 +++ b/src/index.html.luan Tue Mar 04 07:38:43 2025 -0700 @@ -25,37 +25,29 @@ local Db = require "site:/lib/Db.luan" local run_in_transaction = Db.run_in_transaction or error() local Chat = require "site:/lib/Chat.luan" -local chat_search = Chat.search or error() +local get_chat_by_user_ids = Chat.get_by_user_ids or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "index.html" local function get_chat(with) - local t = {} local ids = {} for email in pairs(with) do local with_user = get_user_by_email(email) or error() local id = with_user.id - t[#t+1] = "+chat_user_ids:"..id ids[#ids+1] = id end - local query = concat(t," ") local need_push = false local chat = run_in_transaction( function() - local chats = chat_search(query) - local n = #chats - if n == 0 then - local chat = Chat.new{ + local chat = get_chat_by_user_ids(ids) + if chat == nil then + chat = Chat.new{ user_ids = ids } chat.save() need_push = true - return chat - elseif n == 1 then - return chats[1] - else - error("multiple chats for: "..query) end + return chat end ) if need_push then local js = "getChats('"..chat.id.."')"