diff --git a/src/xmpp.coffee b/src/xmpp.coffee index 02ffa1b..529fe8c 100644 --- a/src/xmpp.coffee +++ b/src/xmpp.coffee @@ -151,6 +151,12 @@ class XmppBot extends Adapter @client.send pong readMessage: (stanza) => + + if (x = stanza.getChild('x', 'jabber:x:conference')) and x?.attrs? + @robot.logger.debug '[joining room]', x.attrs + @options.rooms.push x.attrs + @joinRoom x.attrs + # ignore non-messages return if stanza.attrs.type not in ['groupchat', 'direct', 'chat'] return if stanza.attrs.from is undefined diff --git a/test/adapter-test.coffee b/test/adapter-test.coffee index fcf46bd..4af7bb8 100644 --- a/test/adapter-test.coffee +++ b/test/adapter-test.coffee @@ -67,6 +67,36 @@ describe 'XmppBot', -> done() bot.joinRoom protectedRoom + describe '#invites', -> + + it 'joins when invited', (done) -> + + bot = Bot.use() + + bot.client = + stub: 'xmpp client' + + bot.robot = + name: 'bot' + logger: + debug: () -> + room = + jid: 'test@example.com' + password: false + + stanza = new Xmpp.Stanza 'message' + stanza.c 'x', {xmlns: 'jabber:x:conference', jid: room.jid, password: room.password} + + bot.options = {rooms:[]} + + bot.joinRoom = (r) -> + assert r.jid is room.jid, 'jid match' + assert r.password is room.password, 'password match' + done() + + bot.readMessage.call bot, stanza + + describe '#leaveRoom()', -> bot = Bot.use() bot.client =