Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6254:da4c04df90e3
Merge with daurnimator
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 23 May 2014 20:37:16 +0100 |
parent | 6233:f400a4cdf352 |
parent | 6253:2df9e7a67e56 |
child | 6267:8dc9a89ada7d |
comparison
equal
deleted
inserted
replaced
6233:f400a4cdf352 | 6254:da4c04df90e3 |
---|---|
77 function room_mt:each_occupant(read_only) | 77 function room_mt:each_occupant(read_only) |
78 return next_copied_occupant, self._occupants, nil; | 78 return next_copied_occupant, self._occupants, nil; |
79 end | 79 end |
80 end | 80 end |
81 | 81 |
82 function room_mt:has_occupant() | |
83 return next(self._occupants, nil) ~= nil | |
84 end | |
85 | |
82 function room_mt:get_occupant_by_real_jid(real_jid) | 86 function room_mt:get_occupant_by_real_jid(real_jid) |
83 local occupant_jid = self:get_occupant_jid(real_jid); | 87 local occupant_jid = self:get_occupant_jid(real_jid); |
84 if occupant_jid == nil then return nil end | 88 if occupant_jid == nil then return nil end |
85 return self:get_occupant_by_nick(occupant_jid); | 89 return self:get_occupant_by_nick(occupant_jid); |
86 end | 90 end |
94 if old_occupant then | 98 if old_occupant then |
95 for real_jid in pairs(old_occupant.sessions) do | 99 for real_jid in pairs(old_occupant.sessions) do |
96 self._jid_nick[real_jid] = nil; | 100 self._jid_nick[real_jid] = nil; |
97 end | 101 end |
98 end | 102 end |
99 if occupant.role ~= nil and next(occupant.sessions) then | 103 |
104 local has_live_session = false | |
105 if occupant.role ~= nil then | |
100 for real_jid, presence in occupant:each_session() do | 106 for real_jid, presence in occupant:each_session() do |
101 self._jid_nick[real_jid] = occupant.nick; | 107 if presence.attr.type == nil then |
102 end | 108 has_live_session = true |
103 else | 109 self._jid_nick[real_jid] = occupant.nick; |
110 end | |
111 end | |
112 if not has_live_session then | |
113 -- Has no live sessions left; they have left the room. | |
114 occupant.role = nil | |
115 end | |
116 end | |
117 if not has_live_session then | |
104 occupant = nil | 118 occupant = nil |
105 end | 119 end |
106 self._occupants[id] = occupant | 120 self._occupants[id] = occupant |
107 end | 121 end |
108 | 122 |
109 function room_mt:route_to_occupant(occupant, stanza) | 123 function room_mt:route_to_occupant(occupant, stanza) |
110 local to = stanza.attr.to; | 124 local to = stanza.attr.to; |
111 for jid, pr in occupant:each_session() do | 125 for jid, pr in occupant:each_session() do |
112 if pr.attr.type ~= "unavailable" then | 126 stanza.attr.to = jid; |
113 stanza.attr.to = jid; | 127 self:route_stanza(stanza); |
114 self:route_stanza(stanza); | |
115 end | |
116 end | 128 end |
117 stanza.attr.to = to; | 129 stanza.attr.to = to; |
118 end | 130 end |
119 | 131 |
120 -- actor is the attribute table | 132 -- actor is the attribute table |
394 if orig_occupant ~= nil and orig_occupant ~= dest_occupant then | 406 if orig_occupant ~= nil and orig_occupant ~= dest_occupant then |
395 local orig_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); | 407 local orig_x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user";}); |
396 local dest_nick; | 408 local dest_nick; |
397 if dest_occupant == nil then -- Session is leaving | 409 if dest_occupant == nil then -- Session is leaving |
398 log("debug", "session %s is leaving occupant %s", real_jid, orig_occupant.nick); | 410 log("debug", "session %s is leaving occupant %s", real_jid, orig_occupant.nick); |
399 orig_occupant.role = nil; | 411 if is_last_orig_session then |
412 orig_occupant.role = nil; | |
413 end | |
400 orig_occupant:set_session(real_jid, stanza); | 414 orig_occupant:set_session(real_jid, stanza); |
401 else | 415 else |
402 log("debug", "session %s is changing from occupant %s to %s", real_jid, orig_occupant.nick, dest_occupant.nick); | 416 log("debug", "session %s is changing from occupant %s to %s", real_jid, orig_occupant.nick, dest_occupant.nick); |
403 local generated_unavail = st.presence {from = orig_occupant.nick, to = real_jid, type = "unavailable"}; | 417 local generated_unavail = st.presence {from = orig_occupant.nick, to = real_jid, type = "unavailable"}; |
404 orig_occupant:set_session(real_jid, generated_unavail); | 418 orig_occupant:set_session(real_jid, generated_unavail); |
447 if orig_occupant == nil and self:get_whois() == "anyone" then | 461 if orig_occupant == nil and self:get_whois() == "anyone" then |
448 dest_x:tag("status", {code = "100"}):up(); | 462 dest_x:tag("status", {code = "100"}):up(); |
449 end | 463 end |
450 self:save_occupant(dest_occupant); | 464 self:save_occupant(dest_occupant); |
451 | 465 |
452 if orig_occupant == nil and is_first_dest_session then | 466 if orig_occupant == nil then |
453 -- Send occupant list to newly joined user | 467 -- Send occupant list to newly joined user |
454 self:send_occupant_list(real_jid, function(nick, occupant) | 468 self:send_occupant_list(real_jid, function(nick, occupant) |
455 -- Don't include self | 469 -- Don't include self |
456 return occupant:get_presence(real_jid) == nil; | 470 return occupant:get_presence(real_jid) == nil; |
457 end) | 471 end) |
1108 room_mt.get_historylength = history.get_length; | 1122 room_mt.get_historylength = history.get_length; |
1109 room_mt.set_historylength = history.set_length; | 1123 room_mt.set_historylength = history.set_length; |
1110 | 1124 |
1111 local _M = {}; -- module "muc" | 1125 local _M = {}; -- module "muc" |
1112 | 1126 |
1113 _M.set_max_history_length = history.set_max_length; | |
1114 | |
1115 function _M.new_room(jid, config) | 1127 function _M.new_room(jid, config) |
1116 return setmetatable({ | 1128 return setmetatable({ |
1117 jid = jid; | 1129 jid = jid; |
1118 _jid_nick = {}; | 1130 _jid_nick = {}; |
1119 _occupants = {}; | 1131 _occupants = {}; |