annotate src/delete_chat.js.luan @ 16:82b55186a4a0

fix delete_chat
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Nov 2024 21:22:06 -0700
parents 9f45d32670ae
children 7230c821c368
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()
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 return function()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local chat = Http.request.parameters.chat or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 chat = get_chat_by_id(chat) or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local user = current_user() or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 chat.delete()
16
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
17 local js = "getChats(null)"
82b55186a4a0 fix delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
18 http_push_to_users( chat.user_ids, js )
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 end