Mercurial Hosting > lang
comparison src/save_chat.js.luan @ 29:505185272dd7
edit chat
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sat, 02 Aug 2025 22:39:48 -0600 |
| parents | src/save_rename_chat.js.luan@b1adec083e44 |
| children | 1e7d855afde3 |
comparison
equal
deleted
inserted
replaced
| 28:99b71a377f2c | 29:505185272dd7 |
|---|---|
| 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 setChat(<%= json_string(chat.info()) %>); | |
| 27 <% | |
| 28 end |
