Comparison

plugins/groupchat.lua @ 435:cf31a5ef8a9b

verse.plugins.groupchat: Add support for MUC passwords https://xmpp.org/extensions/xep-0045.html#example-27
author Seve Ferrer <seve@delape.net>
date Fri, 02 Oct 2020 16:42:37 +0200
parent 418:40b8cc364274
child 490:6b2f31da9610
comparison
equal deleted inserted replaced
426:9813b17ee096 435:cf31a5ef8a9b
36 local ret = room:event(stanza.name, event); 36 local ret = room:event(stanza.name, event);
37 return ret or (stanza.name == "message") or nil; 37 return ret or (stanza.name == "message") or nil;
38 end 38 end
39 end, 500); 39 end, 500);
40 40
41 function stream:join_room(jid, nick, opts) 41 function stream:join_room(jid, nick, opts, password)
42 if not nick then 42 if not nick then
43 return false, "no nickname supplied" 43 return false, "no nickname supplied"
44 end 44 end
45 opts = opts or {}; 45 opts = opts or {};
46 local room = setmetatable(verse.eventable{ 46 local room = setmetatable(verse.eventable{
102 room.subject = subject; 102 room.subject = subject;
103 return room:event("subject-changed", { from = old_subject, to = subject, by = event.sender, event = event }); 103 return room:event("subject-changed", { from = old_subject, to = subject, by = event.sender, event = event });
104 end 104 end
105 end, 2000); 105 end, 2000);
106 local join_st = verse.presence():tag("x",{xmlns = xmlns_muc}):reset(); 106 local join_st = verse.presence():tag("x",{xmlns = xmlns_muc}):reset();
107 if password then
108 join_st:get_child("x", xmlns_muc):tag("password"):text(password):reset();
109 end
107 self:event("pre-groupchat/joining", join_st); 110 self:event("pre-groupchat/joining", join_st);
108 room:send(join_st) 111 room:send(join_st)
109 self:event("groupchat/joining", room); 112 self:event("groupchat/joining", room);
110 return room; 113 return room;
111 end 114 end