Comparison

plugins/muc/muc.lib.lua @ 6204:c3254827698d

plugins/muc/muc.lib: Move description functions out to own file
author daurnimator <quae@daurnimator.com>
date Wed, 02 Apr 2014 15:14:52 -0400
parent 6203:b6ffce01e6cf
child 6206:f937bb5c83c3
comparison
equal deleted inserted replaced
6203:b6ffce01e6cf 6204:c3254827698d
428 end); 428 end);
429 module:hook("muc-disco#info", function(event) 429 module:hook("muc-disco#info", function(event)
430 event.reply:tag("feature", {var = event.room:get_whois() ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up(); 430 event.reply:tag("feature", {var = event.room:get_whois() ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up();
431 end); 431 end);
432 module:hook("muc-disco#info", function(event) 432 module:hook("muc-disco#info", function(event)
433 table.insert(event.form, { name = "muc#roominfo_description", label = "Description", value = event.room:get_description() });
434 end);
435 module:hook("muc-disco#info", function(event)
436 local count = 0; for _ in event.room:each_occupant() do count = count + 1; end 433 local count = 0; for _ in event.room:each_occupant() do count = count + 1; end
437 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); 434 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) });
438 end); 435 end);
439 436
440 function room_mt:get_disco_items(stanza) 437 function room_mt:get_disco_items(stanza)
492 if self.save then self:save(true); end 489 if self.save then self:save(true); end
493 end 490 end
494 end 491 end
495 function room_mt:get_name() 492 function room_mt:get_name()
496 return self._data.name or jid_split(self.jid); 493 return self._data.name or jid_split(self.jid);
497 end
498 function room_mt:set_description(description)
499 if description == "" or type(description) ~= "string" then description = nil; end
500 if self._data.description ~= description then
501 self._data.description = description;
502 if self.save then self:save(true); end
503 end
504 end
505 function room_mt:get_description()
506 return self._data.description;
507 end 494 end
508 function room_mt:set_password(password) 495 function room_mt:set_password(password)
509 if password == "" or type(password) ~= "string" then password = nil; end 496 if password == "" or type(password) ~= "string" then password = nil; end
510 if self._data.password ~= password then 497 if self._data.password ~= password then
511 self._data.password = password; 498 self._data.password = password;
926 value = event.room:get_name() or "", 913 value = event.room:get_name() or "",
927 }); 914 });
928 end); 915 end);
929 module:hook("muc-config-form", function(event) 916 module:hook("muc-config-form", function(event)
930 table.insert(event.form, { 917 table.insert(event.form, {
931 name = 'muc#roomconfig_roomdesc',
932 type = 'text-single',
933 label = 'Description',
934 value = event.room:get_description() or "",
935 });
936 end);
937 module:hook("muc-config-form", function(event)
938 table.insert(event.form, {
939 name = 'muc#roomconfig_persistentroom', 918 name = 'muc#roomconfig_persistentroom',
940 type = 'boolean', 919 type = 'boolean',
941 label = 'Make Room Persistent?', 920 label = 'Make Room Persistent?',
942 value = event.room:get_persistent() 921 value = event.room:get_persistent()
943 }); 922 });
1046 end 1025 end
1047 return true; 1026 return true;
1048 end 1027 end
1049 module:hook("muc-config-submitted", function(event) 1028 module:hook("muc-config-submitted", function(event)
1050 event.update_option("name", "muc#roomconfig_roomname"); 1029 event.update_option("name", "muc#roomconfig_roomname");
1051 end);
1052 module:hook("muc-config-submitted", function(event)
1053 event.update_option("description", "muc#roomconfig_roomdesc");
1054 end); 1030 end);
1055 module:hook("muc-config-submitted", function(event) 1031 module:hook("muc-config-submitted", function(event)
1056 event.update_option("persistent", "muc#roomconfig_persistentroom"); 1032 event.update_option("persistent", "muc#roomconfig_persistentroom");
1057 end); 1033 end);
1058 module:hook("muc-config-submitted", function(event) 1034 module:hook("muc-config-submitted", function(event)
1556 self:save_occupant(occupant); 1532 self:save_occupant(occupant);
1557 self:publicise_occupant_status(occupant, x, actor, reason); 1533 self:publicise_occupant_status(occupant, x, actor, reason);
1558 return true; 1534 return true;
1559 end 1535 end
1560 1536
1537 local description = module:require "muc/description";
1538 room_mt.get_description = description.get;
1539 room_mt.set_description = description.set;
1540
1561 local _M = {}; -- module "muc" 1541 local _M = {}; -- module "muc"
1562 1542
1563 function _M.new_room(jid, config) 1543 function _M.new_room(jid, config)
1564 return setmetatable({ 1544 return setmetatable({
1565 jid = jid; 1545 jid = jid;