comparison src/save_rename_chat.js.luan @ 4:b1adec083e44

chat work
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Jul 2025 22:15:41 -0600
parents
children
comparison
equal deleted inserted replaced
3:eee6d4f59811 4:b1adec083e44
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local Parsers = require "luan:Parsers.luan"
4 local json_string = Parsers.json_string or error()
5 local Io = require "luan:Io.luan"
6 local Http = require "luan:http/Http.luan"
7 local Chat = require "site:/lib/Chat.luan"
8 local get_chat_by_id = Chat.get_by_id or error()
9 local User = require "site:/lib/User.luan"
10 local current_user = User.current or error()
11 local Db = require "site:/lib/Db.luan"
12 local run_in_transaction = Db.run_in_transaction or error()
13
14
15 return function()
16 local chat = Http.request.parameters.chat or error()
17 local name = Http.request.parameters.name or error()
18 run_in_transaction( function()
19 chat = get_chat_by_id(chat) or error()
20 chat.user_id == current_user().id or error()
21 chat.name = name
22 chat.save()
23 end )
24 Io.stdout = Http.response.text_writer()
25 %>
26 document.querySelector('[content] [name]').textContent = <%=json_string(name)%>;
27 <%
28 end