annotate src/delete_chat.js.luan @ 17:7230c821c368

push fixes
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Nov 2024 14:44:35 -0700
parents 82b55186a4a0
children 323ddacc1593
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Http = require "luan:http/Http.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local User = require "site:/lib/User.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local current_user = User.current or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Chat = require "site:/lib/Chat.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local get_chat_by_id = Chat.get_by_id or error()
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
8 local Shared = require "site:/lib/Shared.luan"
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
9 local http_push_to_users = Shared.http_push_to_users or error()
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
10 local Utils = require "site:/lib/Utils.luan"
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
11 local is_in_list = Utils.is_in_list or error()
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 return function()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local chat = Http.request.parameters.chat or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 chat = get_chat_by_id(chat) or error()
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
17 local user_ids = chat.user_ids
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local user = current_user() or error()
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
19 is_in_list( user.id, user_ids ) or error()
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 chat.delete()
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
21 local js = "getChats(null)"
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
22 http_push_to_users( user_ids, js )
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 end