view src/delete_user.js.luan @ 17:7230c821c368

push fixes
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Nov 2024 14:44:35 -0700
parents e22a1ba4b2ed
children f4708943f29e
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local stringify = Luan.stringify or 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 chat_search = Chat.search or error()
local Utils = require "site:/lib/Utils.luan"
local list_to_set = Utils.list_to_set or error()
local set_to_list = Utils.set_to_list or error()
local Shared = require "site:/lib/Shared.luan"
local http_push_to_users = Shared.http_push_to_users or error()
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "delete_user.js"


return function()
	local user = current_user()
	if user ~= nil then
		local user_ids = list_to_set{}
		local chats = chat_search( "chat_user_ids:"..user.id, "chat_updated desc" )
		for _, chat in ipairs(chats) do
			for _, user_id in ipairs(chat.user_ids) do
				user_ids[user_id] = true
			end
		end
		user_ids = set_to_list(user_ids)
		local js = "getChats(null)"
		user.delete()
		http_push_to_users( user_ids, js )
	end
	Io.stdout = Http.response.text_writer()
%>
	logout();
<%
end