11
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
56
|
3 local Io = require "luan:Io.luan"
|
11
|
4 local Http = require "luan:http/Http.luan"
|
|
5 local User = require "site:/lib/User.luan"
|
|
6 local current_user = User.current or error()
|
|
7 local Chat = require "site:/lib/Chat.luan"
|
|
8 local get_chat_by_id = Chat.get_by_id or error()
|
16
|
9 local Shared = require "site:/lib/Shared.luan"
|
|
10 local http_push_to_users = Shared.http_push_to_users or error()
|
17
|
11 local Utils = require "site:/lib/Utils.luan"
|
|
12 local is_in_list = Utils.is_in_list or error()
|
11
|
13
|
|
14
|
|
15 return function()
|
|
16 local chat = Http.request.parameters.chat or error()
|
|
17 chat = get_chat_by_id(chat) or error()
|
17
|
18 local user_ids = chat.user_ids
|
11
|
19 local user = current_user() or error()
|
17
|
20 is_in_list( user.id, user_ids ) or error()
|
11
|
21 chat.delete()
|
16
|
22 local js = "getChats(null)"
|
17
|
23 http_push_to_users( user_ids, js )
|
56
|
24 Io.stdout = Http.response.text_writer()
|
|
25 %>
|
|
26 location = '/';
|
|
27 <%
|
11
|
28 end
|