diff options
author | mathieui <mathieui@mathieui.net> | 2011-11-24 23:02:48 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2011-11-24 23:03:43 +0100 |
commit | 77b386d0f16818bb7ccd08199e462f9451b7fc23 (patch) | |
tree | 0de3170b537424c9f4c545b88ec4845578cfd365 /src | |
parent | cd9684043f72ec8f7ae7e500096d356662de7f49 (diff) | |
download | poezio-77b386d0f16818bb7ccd08199e462f9451b7fc23.tar.gz poezio-77b386d0f16818bb7ccd08199e462f9451b7fc23.tar.bz2 poezio-77b386d0f16818bb7ccd08199e462f9451b7fc23.tar.xz poezio-77b386d0f16818bb7ccd08199e462f9451b7fc23.zip |
Handle invitations (and do not show them as a message)
Diffstat (limited to 'src')
-rw-r--r-- | src/core.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core.py b/src/core.py index 4d40a0da..ff1622a5 100644 --- a/src/core.py +++ b/src/core.py @@ -167,6 +167,8 @@ class Core(object): self.xmpp.add_event_handler("session_start", self.on_session_start) self.xmpp.add_event_handler("groupchat_presence", self.on_groupchat_presence) self.xmpp.add_event_handler("groupchat_message", self.on_groupchat_message) + self.xmpp.add_event_handler("groupchat_invite", self.on_groupchat_invite) + self.xmpp.add_event_handler("groupchat_decline", self.on_groupchat_decline) self.xmpp.add_event_handler("groupchat_subject", self.on_groupchat_subject) self.xmpp.add_event_handler("message", self.on_message) self.xmpp.add_event_handler("got_online" , self.on_got_online) @@ -185,6 +187,8 @@ class Core(object): self.connected_events = {} + self.pending_invites = {} + def autoload_plugins(self): plugins = config.get('plugins_autoload', '') for plugin in plugins.split(): @@ -315,6 +319,23 @@ class Core(object): """ self.status = Status(show=pres, message=msg) + def on_groupchat_invite(self, message): + jid = message['from'] + if jid.bare in self.pending_invites: + return + # there are 2 'x' tags in the messages, making message['x'] useless + invite = StanzaBase(self.xmpp, xml=message.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}invite')) + inviter = invite['from'] + reason = invite['reason'] + password = invite['password'] + msg = "You are invited to the room %s by %s" % (jid.full, inviter.full) + if reason: + msg += "because: %s" % reason + if password: + msg += ". The password is \"%s\"." % password + self.information(msg, 'Info') + self.pending_invites[jid.bare] = inviter.full + def command_invite(self, arg): args = common.shell_split(arg) if len(args) < 2: @@ -339,6 +360,9 @@ class Core(object): rooms.append(tab.get_name()) return the_input.auto_completion(rooms, '') + def on_groupchat_decline(self, decline): + pass + def on_data_form(self, message): """ When a data form is received @@ -598,6 +622,8 @@ class Core(object): When receiving private message from a muc OR a normal message (from one of our contacts) """ + if message.find('{http://jabber.org/protocol/muc#user}x/{http://jabber.org/protocol/muc#user}invite') != None: + return if message['type'] == 'groupchat': return # Differentiate both type of messages, and call the appropriate handler. @@ -1459,6 +1485,7 @@ class Core(object): the_input.key_backspace() else: items = [] + items.extend(list(self.pending_invites.keys())) the_input.auto_completion(items, '') else: # we are writing the server: complete the server @@ -1466,6 +1493,7 @@ class Core(object): for tab in self.tabs: if isinstance(tab, tabs.MucTab): serv_list.append('%s@%s'% (jid.user, JID(tab.get_name()).host)) + serv_list.extend(list(self.pending_invites.keys())) the_input.auto_completion(serv_list, '') return True @@ -1553,6 +1581,8 @@ class Core(object): self.information(_("You didn't specify a server for the room you want to join"), 'Error') return room = room.lower() + if room in self.pending_invites: + del self.pending_invites[room] tab = self.get_tab_by_name(room, tabs.MucTab) if len(args) == 2: # a password is provided password = args[1] |