Przeglądaj źródła

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

j8
jmacelroy 6 lat temu
rodzic
commit
1c6d22b75e

+ 8
- 1
resources/prosody-plugins/mod_muc_poltergeist.lua Wyświetl plik

178
     local name = params["name"];
178
     local name = params["name"];
179
     local avatar = params["avatar"];
179
     local avatar = params["avatar"];
180
     local status = params["status"];
180
     local status = params["status"];
181
+    local conversation = params["conversation"];
181
     local session = {};
182
     local session = {};
182
 
183
 
183
     if not verify_token(params["token"], room_name, group, session) then
184
     if not verify_token(params["token"], room_name, group, session) then
213
        creator_user = session.jitsi_meet_context_user;
214
        creator_user = session.jitsi_meet_context_user;
214
        creator_group = session.jitsi_meet_context_group;
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
     return 200;
224
     return 200;
218
 end
225
 end
219
 
226
 

+ 46
- 20
resources/prosody-plugins/poltergeist.lib.lua Wyświetl plik

49
     return not not room:get_occupant_jid(component.."/"..nick);
49
     return not not room:get_occupant_jid(component.."/"..nick);
50
 end
50
 end
51
 
51
 
52
-
53
 --------------------------------------------------------------------------------
52
 --------------------------------------------------------------------------------
54
 -- Username storage for poltergeist.
53
 -- Username storage for poltergeist.
55
 --
54
 --
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
 -- Adds a poltergeist to the store.
72
 -- Adds a poltergeist to the store.
72
 -- @param room is the room the poltergeist is being added to
73
 -- @param room is the room the poltergeist is being added to
76
 local function store_username(room, user_id, username)
76
 local function store_username(room, user_id, username)
77
     local room_name = jid.node(room.jid)
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
     end
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
 end
85
 end
86
 
86
 
87
 -- Retrieves a poltergeist username from the store if one exists.
87
 -- Retrieves a poltergeist username from the store if one exists.
90
 local function get_username(room, user_id)
90
 local function get_username(room, user_id)
91
     local room_name = jid.node(room.jid)
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
         return nil
94
         return nil
95
     end
95
     end
96
 
96
 
97
-    return usernames[room_name][user_id]
97
+    return state[room_name][user_id]
98
 end
98
 end
99
 
99
 
100
 local function get_username_from_nick(room_name, nick)
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
         return nil
102
         return nil
103
     end
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
 end
107
 end
108
 
108
 
109
 -- Removes the username from the store.
109
 -- Removes the username from the store.
110
 -- @param room is the room the poltergeist is being removed from
110
 -- @param room is the room the poltergeist is being removed from
111
 -- @param nick is the nick of the muc occupant
111
 -- @param nick is the nick of the muc occupant
112
 local function remove_username(room, nick)
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
         return
115
         return
116
     end
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
 end
121
 end
122
 
122
 
123
 -- Removes all poltergeists in the store for the provided room.
123
 -- Removes all poltergeists in the store for the provided room.
124
 -- @param room is the room all poltergiest will be removed from
124
 -- @param room is the room all poltergiest will be removed from
125
 local function remove_room(room)
125
 local function remove_room(room)
126
     local room_name = jid.node(room.jid)
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
     end
146
     end
147
+
148
+    state[room_name][call_id][resource_type] = resource_id
130
 end
149
 end
131
 
150
 
132
 --------------------------------------------------------------------------------
151
 --------------------------------------------------------------------------------
271
 -- @param avatar is the avatar link used for the poltergeist display
290
 -- @param avatar is the avatar link used for the poltergeist display
272
 -- @param context is the session context of the user making the request
291
 -- @param context is the session context of the user making the request
273
 -- @param status is the presence status string to use
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
     local username = uuid.generate()
295
     local username = uuid.generate()
276
     local presence_stanza = original_presence(
296
     local presence_stanza = original_presence(
277
         room,
297
         room,
281
         context,
301
         context,
282
         status
302
         status
283
     )
303
     )
284
-    store_username(room, user_id, username)
304
+
285
     module:log("info", "adding poltergeist: %s/%s", room, create_nick(username))
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
     room:handle_first_presence(
310
     room:handle_first_presence(
287
         prosody.hosts[component],
311
         prosody.hosts[component],
288
         presence_stanza
312
         presence_stanza
289
     )
313
     )
314
+
290
     local remove_delay = 5
315
     local remove_delay = 5
291
     local expiration = expiration_timeout - remove_delay;
316
     local expiration = expiration_timeout - remove_delay;
292
     local nick = create_nick(username)
317
     local nick = create_nick(username)

Ładowanie…
Anuluj
Zapisz