23
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Http = require "luan:http/Http.luan"
|
|
4 local User = require "site:/lib/User.luan"
|
|
5 local current_user = User.current or error()
|
|
6 local Chat = require "site:/lib/Chat.luan"
|
|
7 local get_chat_by_id = Chat.get_by_id or error()
|
|
8 local Post = require "site:/lib/Post.luan"
|
|
9 local get_post_by_id = Post.get_by_id or error()
|
|
10 local Utils = require "site:/lib/Utils.luan"
|
|
11 local is_in_list = Utils.is_in_list or error()
|
|
12
|
|
13
|
|
14 return function()
|
|
15 local post = Http.request.parameters.post or error()
|
|
16 post = get_post_by_id(post) or error()
|
|
17 local chat = get_chat_by_id(post.chat_id) or error()
|
|
18 local user_ids = chat.user_ids
|
|
19 local user = current_user() or error()
|
|
20 is_in_list( user.id, user_ids ) or error()
|
|
21 post.delete()
|
|
22 local js = "deleted('"..post.id.."')"
|
|
23 chat.http_push(js)
|
|
24 end
|