83
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local pairs = Luan.pairs or error()
|
|
4 local Table = require "luan:Table.luan"
|
|
5 local concat = Table.concat or error()
|
|
6 local Html = require "luan:Html.luan"
|
|
7 local url_encode = Html.url_encode or error()
|
|
8 local Io = require "luan:Io.luan"
|
|
9 local Http = require "luan:http/Http.luan"
|
|
10 local User = require "site:/lib/User.luan"
|
|
11 local get_user_by_email = User.get_by_email or error()
|
|
12 local get_user_by_id = User.get_by_id or error()
|
|
13 local current_user = User.current or error()
|
|
14 local Chat = require "site:/lib/Chat.luan"
|
|
15 local get_chat_by_id = Chat.get_by_id or error()
|
|
16 local Utils = require "site:/lib/Utils.luan"
|
|
17 local list_to_set = Utils.list_to_set or error()
|
|
18
|
|
19
|
|
20 return function()
|
|
21 local email = Http.request.parameters.email or error()
|
|
22 local add_user = get_user_by_email(email)
|
|
23 Io.stdout = Http.response.text_writer()
|
|
24 if add_user == nil then
|
|
25 %>
|
|
26 addToChatError('email not found');
|
|
27 <%
|
|
28 return
|
|
29 end
|
|
30 local user = current_user() or error()
|
|
31 local chat = Http.request.parameters.chat or error()
|
|
32 chat = get_chat_by_id(chat) or error()
|
|
33 local set = list_to_set(chat.user_ids)
|
|
34 set[user.id] or error()
|
|
35 set[add_user.id] = true
|
|
36 local t = {}
|
|
37 for id in pairs(set) do
|
|
38 local user = get_user_by_id(id)
|
|
39 t[#t+1] = "with="..url_encode(user.email)
|
|
40 end
|
|
41 %>
|
|
42 location = 'chat?<%= concat(t,"&") %>';
|
|
43 <%
|
|
44 end
|