4
|
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()
|
34
|
13 local Logging = require "luan:logging/Logging.luan"
|
|
14 local logger = Logging.logger "save_chat.js"
|
4
|
15
|
|
16
|
|
17 return function()
|
|
18 local chat = Http.request.parameters.chat or error()
|
|
19 local name = Http.request.parameters.name or error()
|
32
|
20 local language_region = Http.request.parameters.language_region or error()
|
31
|
21 local voice = Http.request.parameters.voice or error()
|
34
|
22 local show_text = Http.request.parameters.show_text
|
36
|
23 local autoplay = Http.request.parameters.autoplay
|
4
|
24 run_in_transaction( function()
|
|
25 chat = get_chat_by_id(chat) or error()
|
|
26 chat.user_id == current_user().id or error()
|
|
27 chat.name = name
|
32
|
28 chat.language_region = language_region
|
31
|
29 chat.voice = voice
|
34
|
30 chat.show_text = show_text ~= nil
|
36
|
31 chat.autoplay = autoplay ~= nil
|
4
|
32 chat.save()
|
|
33 end )
|
|
34 Io.stdout = Http.response.text_writer()
|
|
35 %>
|
29
|
36 setChat(<%= json_string(chat.info()) %>);
|
4
|
37 <%
|
|
38 end
|