|
|
@@ -66,6 +66,24 @@ function get_username(room, user_id)
|
|
66
|
66
|
return poltergeists[room_name][user_id];
|
|
67
|
67
|
end
|
|
68
|
68
|
|
|
|
69
|
+-- Removes poltergeist values from table
|
|
|
70
|
+-- @param room the room instance
|
|
|
71
|
+-- @param nick the user nick
|
|
|
72
|
+function remove_username(room, nick)
|
|
|
73
|
+ local room_name = jid.node(room.jid);
|
|
|
74
|
+ if (poltergeists[room_name]) then
|
|
|
75
|
+ local user_id_to_remove;
|
|
|
76
|
+ for name,username in pairs(poltergeists[room_name]) do
|
|
|
77
|
+ if (string.sub(username, 0, 8) == nick) then
|
|
|
78
|
+ user_id_to_remove = name;
|
|
|
79
|
+ end
|
|
|
80
|
+ end
|
|
|
81
|
+ if (user_id_to_remove) then
|
|
|
82
|
+ poltergeists[room_name][user_id_to_remove] = nil;
|
|
|
83
|
+ end
|
|
|
84
|
+ end
|
|
|
85
|
+end
|
|
|
86
|
+
|
|
69
|
87
|
-- if we found that a session for a user with id has a poltergiest already
|
|
70
|
88
|
-- created, retrieve its jid and return it to the authentication
|
|
71
|
89
|
-- so we can reuse it and we that real user will replace the poltergiest
|
|
|
@@ -152,6 +170,7 @@ function remove_poltergeist_occupant(room, nick, ignore)
|
|
152
|
170
|
end
|
|
153
|
171
|
room:handle_normal_presence(
|
|
154
|
172
|
prosody.hosts[poltergeist_component], leave_presence);
|
|
|
173
|
+ remove_username(room, nick);
|
|
155
|
174
|
end
|
|
156
|
175
|
|
|
157
|
176
|
-- Checks for existance of a poltergeist occupant
|
|
|
@@ -185,6 +204,14 @@ module:hook("muc-broadcast-presence", function (event)
|
|
185
|
204
|
end
|
|
186
|
205
|
end, -100);
|
|
187
|
206
|
|
|
|
207
|
+-- cleanup room table after room is destroyed
|
|
|
208
|
+module:hook("muc-room-destroyed",function(event)
|
|
|
209
|
+ local room_name = jid.node(event.room.jid);
|
|
|
210
|
+ if (poltergeists[room_name]) then
|
|
|
211
|
+ poltergeists[room_name] = nil;
|
|
|
212
|
+ end
|
|
|
213
|
+end);
|
|
|
214
|
+
|
|
188
|
215
|
--- Handles request for creating/managing poltergeists
|
|
189
|
216
|
-- @param event the http event, holds the request query
|
|
190
|
217
|
-- @return GET response, containing a json with response details
|