Comparison

plugins/groupchat.lua @ 215:f86e0b0a0be3

plugins.groupchat: Improve room subject handling, add event
author Kim Alvefur <zash@zash.se>
date Thu, 08 Sep 2011 17:51:11 +0200
parent 207:78f59d7b1ef7
child 231:9712693ae40a
comparison
equal deleted inserted replaced
214:78ae20c875cd 215:f86e0b0a0be3
90 room:event("occupant-left", occupants[nick]); 90 room:event("occupant-left", occupants[nick]);
91 occupants[nick] = nil; 91 occupants[nick] = nil;
92 end 92 end
93 end 93 end
94 end); 94 end);
95 room:hook("message", function(msg) 95 room:hook("message", function(event)
96 local subject = msg.stanza:get_child("subject"); 96 local subject = event.stanza:get_child_text("subject");
97 subject = subject and subject:get_text(); 97 if not subject then return end
98 if subject then 98 subject = #subject > 0 and subject or nil;
99 room.subject = #subject > 0 and subject or nil; 99 if subject ~= room.subject then
100 local old_subject = room.subject;
101 room.subject = subject;
102 return room:event("subject-changed", { from = old_subject, to = subject, by = event.sender, event = event });
100 end 103 end
101 end, 2000); 104 end, 2000);
102 local join_st = verse.presence():tag("x",{xmlns = xmlns_muc}):reset(); 105 local join_st = verse.presence():tag("x",{xmlns = xmlns_muc}):reset();
103 self:event("pre-groupchat/joining", join_st); 106 self:event("pre-groupchat/joining", join_st);
104 room:send(join_st) 107 room:send(join_st)