Comparison

plugins/muc/muc.lib.lua @ 5982:2d5685c6262f

MUC: Split saving to history into a separate method
author Kim Alvefur <zash@zash.se>
date Sat, 18 Jan 2014 18:05:42 +0100
parent 5854:16a2bb97c5f5
child 5983:930109558aa2
comparison
equal deleted inserted replaced
5980:787df1130965 5982:2d5685c6262f
105 self:_route_stanza(stanza); 105 self:_route_stanza(stanza);
106 end 106 end
107 end 107 end
108 stanza.attr.to = to; 108 stanza.attr.to = to;
109 if historic then -- add to history 109 if historic then -- add to history
110 local history = self._data['history']; 110 return self:save_to_history(stanza)
111 if not history then history = {}; self._data['history'] = history; end 111 end
112 stanza = st.clone(stanza); 112 end
113 stanza.attr.to = ""; 113 function room_mt:save_to_history(stanza)
114 local stamp = datetime.datetime(); 114 local history = self._data['history'];
115 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203 115 if not history then history = {}; self._data['history'] = history; end
116 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) 116 stanza = st.clone(stanza);
117 local entry = { stanza = stanza, stamp = stamp }; 117 stanza.attr.to = "";
118 t_insert(history, entry); 118 local stamp = datetime.datetime();
119 while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end 119 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203
120 end 120 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
121 local entry = { stanza = stanza, stamp = stamp };
122 t_insert(history, entry);
123 while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end
121 end 124 end
122 function room_mt:broadcast_except_nick(stanza, nick) 125 function room_mt:broadcast_except_nick(stanza, nick)
123 for rnick, occupant in pairs(self._occupants) do 126 for rnick, occupant in pairs(self._occupants) do
124 if rnick ~= nick then 127 if rnick ~= nick then
125 for jid in pairs(occupant.sessions) do 128 for jid in pairs(occupant.sessions) do