annotate src/delete_chat.js.luan @ 56:323ddacc1593

start invite
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Mar 2025 07:00:42 -0700
parents 7230c821c368
children
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
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
3 local Io = require "luan:Io.luan"
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local User = require "site:/lib/User.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local current_user = User.current or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Chat = require "site:/lib/Chat.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 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
9 local Shared = require "site:/lib/Shared.luan"
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
10 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
11 local Utils = require "site:/lib/Utils.luan"
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
12 local is_in_list = Utils.is_in_list or error()
11
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
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 return function()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local chat = Http.request.parameters.chat or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 chat = get_chat_by_id(chat) or error()
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
18 local user_ids = chat.user_ids
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local user = current_user() or error()
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
20 is_in_list( user.id, user_ids ) or error()
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 chat.delete()
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
22 local js = "getChats(null)"
17
7230c821c368 push fixes
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
23 http_push_to_users( user_ids, js )
56
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
24 Io.stdout = Http.response.text_writer()
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
25 %>
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
26 location = '/';
323ddacc1593 start invite
Franklin Schmidt <fschmidt@gmail.com>
parents: 17
diff changeset
27 <%
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 end