Procházet zdrojové kódy

Adding state to poltergeist store for correlating external resources with calls.

j8
jmacelroy před 6 roky
rodič
revize
1c6d22b75e

+ 8
- 1
resources/prosody-plugins/mod_muc_poltergeist.lua Zobrazit soubor

@@ -178,6 +178,7 @@ function handle_create_poltergeist (event)
178 178
     local name = params["name"];
179 179
     local avatar = params["avatar"];
180 180
     local status = params["status"];
181
+    local conversation = params["conversation"];
181 182
     local session = {};
182 183
 
183 184
     if not verify_token(params["token"], room_name, group, session) then
@@ -213,7 +214,13 @@ function handle_create_poltergeist (event)
213 214
        creator_user = session.jitsi_meet_context_user;
214 215
        creator_group = session.jitsi_meet_context_group;
215 216
     };
216
-    poltergeist.add_to_muc(room, user_id, name, avatar, context, status)
217
+
218
+    local resources = {};
219
+    if conversation ~= nil then
220
+        resources["conversation"] = conversation
221
+    end
222
+
223
+    poltergeist.add_to_muc(room, user_id, name, avatar, context, status, resources)
217 224
     return 200;
218 225
 end
219 226
 

+ 46
- 20
resources/prosody-plugins/poltergeist.lib.lua Zobrazit soubor

@@ -49,7 +49,6 @@ function occupies(room, nick)
49 49
     return not not room:get_occupant_jid(component.."/"..nick);
50 50
 end
51 51
 
52
-
53 52
 --------------------------------------------------------------------------------
54 53
 -- Username storage for poltergeist.
55 54
 --
@@ -66,8 +65,9 @@ end
66 65
 --   }
67 66
 -- }
68 67
 --------------------------------------------------------------------------------
69
-local usernames = {}
68
+-- state is the table where poltergeist usernames and call resources are stored
69
+-- for a given xmpp muc.
70
+local state = module:shared("state")
70 71
 
71 72
 -- Adds a poltergeist to the store.
72 73
 -- @param room is the room the poltergeist is being added to
@@ -76,12 +76,12 @@ local usernames = {}
76 76
 local function store_username(room, user_id, username)
77 77
     local room_name = jid.node(room.jid)
78 78
 
79
-    if not usernames[room_name] then
80
-        usernames[room_name] = {}
79
+    if not state[room_name] then
80
+        state[room_name] = {}
81 81
     end
82 82
 
83
-    usernames[room_name][user_id] = username
84
-    usernames[room_name][create_nick(username)] = user_id
83
+    state[room_name][user_id] = username
84
+    state[room_name][create_nick(username)] = user_id
85 85
 end
86 86
 
87 87
 -- Retrieves a poltergeist username from the store if one exists.
@@ -90,43 +90,62 @@ end
90 90
 local function get_username(room, user_id)
91 91
     local room_name = jid.node(room.jid)
92 92
 
93
-    if not usernames[room_name] then
93
+    if not state[room_name] then
94 94
         return nil
95 95
     end
96 96
 
97
-    return usernames[room_name][user_id]
97
+    return state[room_name][user_id]
98 98
 end
99 99
 
100 100
 local function get_username_from_nick(room_name, nick)
101
-    if not usernames[room_name] then
101
+    if not state[room_name] then
102 102
         return nil
103 103
     end
104 104
 
105
-    local user_id = usernames[room_name][nick]
106
-    return usernames[room_name][user_id]
105
+    local user_id = state[room_name][nick]
106
+    return state[room_name][user_id]
107 107
 end
108 108
 
109 109
 -- Removes the username from the store.
110 110
 -- @param room is the room the poltergeist is being removed from
111 111
 -- @param nick is the nick of the muc occupant
112 112
 local function remove_username(room, nick)
113
-    local room_name = jid.node(room.jid);
114
-    if not usernames[room_name] then
113
+    local room_name = jid.node(room.jid)
114
+    if not state[room_name] then
115 115
         return
116 116
     end
117 117
 
118
-    local user_id = usernames[room_name][nick]
119
-    usernames[room_name][user_id] = nil
120
-    usernames[room_name][nick] = nil
118
+    local user_id = state[room_name][nick]
119
+    state[room_name][user_id] = nil
120
+    state[room_name][nick] = nil
121 121
 end
122 122
 
123 123
 -- Removes all poltergeists in the store for the provided room.
124 124
 -- @param room is the room all poltergiest will be removed from
125 125
 local function remove_room(room)
126 126
     local room_name = jid.node(room.jid)
127
-    if usernames[room_name] then
128
-        usernames[room_name] = nil
127
+    if state[room_name] then
128
+        state[room_name] = nil
129
+    end
130
+end
131
+
132
+-- Adds a resource that is associated with a a call in a room. There
133
+-- is only one resource for each type.
134
+-- @param room is the room the call and poltergeist is in.
135
+-- @param call_id is the unique id for the call.
136
+-- @param resource_type is type of resource being added.
137
+-- @param resource_id is the id of the resource being added.
138
+local function add_call_resource(room, call_id, resource_type, resource_id)
139
+    local room_name = jid.node(room.jid)
140
+    if not state[room_name] then
141
+        state[room_name] = {}
142
+    end
143
+
144
+    if not state[room_name][call_id] then
145
+        state[room_name][call_id] = {}
129 146
     end
147
+
148
+    state[room_name][call_id][resource_type] = resource_id
130 149
 end
131 150
 
132 151
 --------------------------------------------------------------------------------
@@ -271,7 +290,8 @@ end
271 290
 -- @param avatar is the avatar link used for the poltergeist display
272 291
 -- @param context is the session context of the user making the request
273 292
 -- @param status is the presence status string to use
274
-local function add_to_muc(room, user_id, display_name, avatar, context, status)
293
+-- @param resources is a table of resource types and resource ids to correlate.
294
+local function add_to_muc(room, user_id, display_name, avatar, context, status, resources)
275 295
     local username = uuid.generate()
276 296
     local presence_stanza = original_presence(
277 297
         room,
@@ -281,12 +301,17 @@ local function add_to_muc(room, user_id, display_name, avatar, context, status)
281 301
         context,
282 302
         status
283 303
     )
284
-    store_username(room, user_id, username)
304
+
285 305
     module:log("info", "adding poltergeist: %s/%s", room, create_nick(username))
306
+    store_username(room, user_id, username)
307
+    for k, v in pairs(resources) do
308
+        add_call_resource(room, username, k, v)
309
+    end
286 310
     room:handle_first_presence(
287 311
         prosody.hosts[component],
288 312
         presence_stanza
289 313
     )
314
+
290 315
     local remove_delay = 5
291 316
     local expiration = expiration_timeout - remove_delay;
292 317
     local nick = create_nick(username)

Načítá se…
Zrušit
Uložit