Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / presence / redis-lua / presence-associate-anon.lua
blobed05c1dc2f8d267247f728f534ec86d01f38798b
1 local key_socket_user = KEYS[1];
2 local key_active_sockets = KEYS[2];
3 local key_user_sockets = KEYS[3];
5 local socket_id = ARGV[1];
6 local create_time = ARGV[2];
7 local mobile_connection = tonumber(ARGV[3]);
8 local client_type = ARGV[4];
9 local realtime_library = ARGV[5];
10 local troupe_id = ARGV[6];
11 local oauth_client_id = ARGV[7];
12 local token = ARGV[8];
13 local unique_client_id = ARGV[9];
15 if redis.call("EXISTS", key_socket_user) == 1 then
16 return { 0 }
17 end
19 redis.call("HSET", key_socket_user, "ctime", create_time)
20 redis.call("HSET", key_socket_user, "ct", client_type)
21 if realtime_library ~= "" then
22 redis.call("HSET", key_socket_user, "rl", realtime_library)
23 end
24 redis.call("HSET", key_socket_user, "tid", troupe_id)
25 if oauth_client_id ~= "" then
26 redis.call("HSET", key_socket_user, "ocid", oauth_client_id)
27 end
28 if token ~= "" then
29 redis.call("HSET", key_socket_user, "tok", token)
30 end
31 if unique_client_id ~= "" then
32 redis.call("HSET", key_socket_user, "ucid", unique_client_id)
33 end
35 -- For mobile users, add them to the mobile users collection
36 if mobile_connection == 1 then
37 redis.call("HSET", key_socket_user, "mob", 1)
38 end
40 redis.call("SADD", key_user_sockets, socket_id)
41 local socket_add_result = redis.call("SADD", key_active_sockets, socket_id)
43 return { 1, socket_add_result }