view 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
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local User = require "site:/lib/User.luan"
local current_user = User.current or error()
local Chat = require "site:/lib/Chat.luan"
local get_chat_by_id = Chat.get_by_id or error()
local Shared = require "site:/lib/Shared.luan"
local http_push_to_users = Shared.http_push_to_users or error()
local Utils = require "site:/lib/Utils.luan"
local is_in_list = Utils.is_in_list or error()


return function()
	local chat = Http.request.parameters.chat or error()
	chat = get_chat_by_id(chat) or error()
	local user_ids = chat.user_ids
	local user = current_user() or error()
	is_in_list( user.id, user_ids ) or error()
	chat.delete()
	local js = "getChats(null)"
	http_push_to_users( user_ids, js )
	Io.stdout = Http.response.text_writer()
%>
	location = '/';
<%
end