Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6137:7db24f237a83
plugins/muc/muc.lib: Add muc-broadcast-message event. Use it for saving to history
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Mon, 24 Mar 2014 13:10:54 -0400 |
parent | 6136:2068242028ff |
child | 6138:fa746d834424 |
comparison
equal
deleted
inserted
replaced
6136:2068242028ff | 6137:7db24f237a83 |
---|---|
117 stanza:tag("status", {code='110'}):up(); | 117 stanza:tag("status", {code='110'}):up(); |
118 stanza.attr.to = sid; | 118 stanza.attr.to = sid; |
119 self:_route_stanza(stanza); | 119 self:_route_stanza(stanza); |
120 end | 120 end |
121 function room_mt:broadcast_message(stanza, historic) | 121 function room_mt:broadcast_message(stanza, historic) |
122 module:fire_event("muc-broadcast-message", {room = self, stanza = stanza, historic = historic}); | |
122 for occupant_jid, o_data in pairs(self._occupants) do | 123 for occupant_jid, o_data in pairs(self._occupants) do |
123 self:route_to_occupant(o_data, stanza) | 124 self:route_to_occupant(o_data, stanza) |
124 end | 125 end |
125 if historic then -- add to history | 126 end |
126 return self:save_to_history(stanza) | 127 |
127 end | 128 -- add to history |
128 end | 129 module:hook("muc-broadcast-message", function(event) |
129 function room_mt:save_to_history(stanza) | 130 if event.historic then |
130 local history = self._data['history']; | 131 local room = event.room |
131 if not history then history = {}; self._data['history'] = history; end | 132 local history = room._data['history']; |
132 stanza = st.clone(stanza); | 133 if not history then history = {}; room._data['history'] = history; end |
133 stanza.attr.to = ""; | 134 local stanza = st.clone(event.stanza); |
134 local stamp = datetime.datetime(); | 135 stanza.attr.to = ""; |
135 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203 | 136 local stamp = datetime.datetime(); |
136 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) | 137 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = module.host, stamp = stamp}):up(); -- XEP-0203 |
137 local entry = { stanza = stanza, stamp = stamp }; | 138 stanza:tag("x", {xmlns = "jabber:x:delay", from = module.host, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
138 t_insert(history, entry); | 139 local entry = { stanza = stanza, stamp = stamp }; |
139 while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end | 140 t_insert(history, entry); |
140 end | 141 while #history > room:get_historylength() do t_remove(history, 1) end |
142 end | |
143 end) | |
144 | |
141 function room_mt:broadcast_except_nick(stanza, nick) | 145 function room_mt:broadcast_except_nick(stanza, nick) |
142 for rnick, occupant in pairs(self._occupants) do | 146 for rnick, occupant in pairs(self._occupants) do |
143 if rnick ~= nick then | 147 if rnick ~= nick then |
144 self:route_to_occupant(occupant, stanza) | 148 self:route_to_occupant(occupant, stanza) |
145 end | 149 end |