comparison mod_mam_muc/mod_mam_muc.lua @ 1650:66d67f0bae16

mod_mam_muc: Cleanup [luacheck]
author Kim Alvefur <zash@zash.se>
date Tue, 07 Apr 2015 17:34:43 +0200
parents ab4073468dfb
children c77e9522dc66
comparison
equal deleted inserted replaced
1649:ab4073468dfb 1650:66d67f0bae16
15 local dataform = require "util.dataforms".new; 15 local dataform = require "util.dataforms".new;
16 local it = require"util.iterators"; 16 local it = require"util.iterators";
17 17
18 -- Support both old and new MUC code 18 -- Support both old and new MUC code
19 local mod_muc = module:depends"muc"; 19 local mod_muc = module:depends"muc";
20 local room_mt = mod_muc.room_mt;
21 local rooms = rawget(mod_muc, "rooms"); 20 local rooms = rawget(mod_muc, "rooms");
22 local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end; 21 local each_room = rawget(mod_muc, "each_room") or function() return it.values(rooms); end;
23 local new_muc = not rooms; 22 local new_muc = not rooms;
24 if new_muc then 23 if new_muc then
25 rooms = module:shared"muc/rooms"; 24 rooms = module:shared"muc/rooms";
266 return 265 return
267 end 266 end
268 267
269 local history, i = {}, 1; 268 local history, i = {}, 1;
270 269
271 for id, item, when in data do 270 for _, item, when in data do
272 item.attr.to = to; 271 item.attr.to = to;
273 item:tag("delay", { xmlns = "urn:xmpp:delay", from = room_jid, stamp = timestamp(when) }):up(); -- XEP-0203 272 item:tag("delay", { xmlns = "urn:xmpp:delay", from = room_jid, stamp = timestamp(when) }):up(); -- XEP-0203
274 if maxchars then 273 if maxchars then
275 local chars = #tostring(item); 274 local chars = #tostring(item);
276 if maxchars - chars < 0 then 275 if maxchars - chars < 0 then
279 maxchars = maxchars - chars; 278 maxchars = maxchars - chars;
280 end 279 end
281 history[i], i = item, i+1; 280 history[i], i = item, i+1;
282 -- module:log("debug", tostring(item)); 281 -- module:log("debug", tostring(item));
283 end 282 end
284 function event:next_stanza() 283 function event.next_stanza()
285 i = i - 1; 284 i = i - 1;
286 return history[i]; 285 return history[i];
287 end 286 end
288 return true; 287 return true;
289 end, 1); 288 end, 1);
320 end 319 end
321 end 320 end
322 321
323 -- Handle messages 322 -- Handle messages
324 function save_to_history(self, stanza) 323 function save_to_history(self, stanza)
325 local orig_to = stanza.attr.to;
326 local room = jid_split(self.jid); 324 local room = jid_split(self.jid);
327 325
328 -- Policy check 326 -- Policy check
329 if not logging_enabled(self) then return end -- Don't log 327 if not logging_enabled(self) then return end -- Don't log
330 328