Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 9003:a971023e9b6e
MUC: Bring handling of presence errors to the room more in line with unavailable presence
Related issues: #505, #978
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 09 Jul 2018 17:46:23 +0100 |
parent | 9002:1fcddb4a4d16 |
child | 9007:695904638cfa |
comparison
equal
deleted
inserted
replaced
9002:1fcddb4a4d16 | 9003:a971023e9b6e |
---|---|
219 local base_x = x.base or x; | 219 local base_x = x.base or x; |
220 -- Build real jid and (optionally) occupant jid template presences | 220 -- Build real jid and (optionally) occupant jid template presences |
221 local base_presence do | 221 local base_presence do |
222 -- Try to use main jid's presence | 222 -- Try to use main jid's presence |
223 local pr = occupant:get_presence(); | 223 local pr = occupant:get_presence(); |
224 if pr and (pr.attr.type ~= "unavailable" and occupant.role ~= nil) then | 224 if pr and (occupant.role ~= nil or pr.attr.type == "unavailable") then |
225 base_presence = st.clone(pr); | 225 base_presence = st.clone(pr); |
226 else -- user is leaving but didn't send a leave presence. make one for them | 226 else -- user is leaving but didn't send a leave presence. make one for them |
227 base_presence = st.presence {from = occupant.nick; type = "unavailable";}; | 227 base_presence = st.presence {from = occupant.nick; type = "unavailable";}; |
228 end | 228 end |
229 end | 229 end |
367 if text then | 367 if text then |
368 error_message = error_message..": "..text; | 368 error_message = error_message..": "..text; |
369 end | 369 end |
370 occupant:set_session(real_jid, st.presence({type="unavailable"}) | 370 occupant:set_session(real_jid, st.presence({type="unavailable"}) |
371 :tag('status'):text(error_message)); | 371 :tag('status'):text(error_message)); |
372 self:save_occupant(occupant); | 372 local is_last_session = occupant.jid == real_jid; |
373 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}) | 373 if is_last_session then |
374 :tag("status", {code = "307"}):up() | 374 occupant.role = nil; |
375 :tag("status", {code = "333"}) | 375 end |
376 self:publicise_occupant_status(occupant, x); | 376 local new_occupant = self:save_occupant(occupant); |
377 if occupant.jid == real_jid then -- Was last session | 377 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
378 if is_last_session then | |
379 x:tag("status", {code = "307"}):up() | |
380 :tag("status", {code = "333"}); | |
381 end | |
382 self:publicise_occupant_status(new_occupant or occupant, x); | |
383 if is_last_session then | |
378 module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); | 384 module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;}); |
379 end | 385 end |
380 return true; | 386 return true; |
381 end | 387 end |
382 | 388 |