Handle invitations (and do not show them as a message)
This commit is contained in:
parent
cd9684043f
commit
77b386d0f1
1 changed files with 30 additions and 0 deletions
30
src/core.py
30
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("session_start", self.on_session_start)
|
||||||
self.xmpp.add_event_handler("groupchat_presence", self.on_groupchat_presence)
|
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_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("groupchat_subject", self.on_groupchat_subject)
|
||||||
self.xmpp.add_event_handler("message", self.on_message)
|
self.xmpp.add_event_handler("message", self.on_message)
|
||||||
self.xmpp.add_event_handler("got_online" , self.on_got_online)
|
self.xmpp.add_event_handler("got_online" , self.on_got_online)
|
||||||
|
@ -185,6 +187,8 @@ class Core(object):
|
||||||
|
|
||||||
self.connected_events = {}
|
self.connected_events = {}
|
||||||
|
|
||||||
|
self.pending_invites = {}
|
||||||
|
|
||||||
def autoload_plugins(self):
|
def autoload_plugins(self):
|
||||||
plugins = config.get('plugins_autoload', '')
|
plugins = config.get('plugins_autoload', '')
|
||||||
for plugin in plugins.split():
|
for plugin in plugins.split():
|
||||||
|
@ -315,6 +319,23 @@ class Core(object):
|
||||||
"""
|
"""
|
||||||
self.status = Status(show=pres, message=msg)
|
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):
|
def command_invite(self, arg):
|
||||||
args = common.shell_split(arg)
|
args = common.shell_split(arg)
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
|
@ -339,6 +360,9 @@ class Core(object):
|
||||||
rooms.append(tab.get_name())
|
rooms.append(tab.get_name())
|
||||||
return the_input.auto_completion(rooms, '')
|
return the_input.auto_completion(rooms, '')
|
||||||
|
|
||||||
|
def on_groupchat_decline(self, decline):
|
||||||
|
pass
|
||||||
|
|
||||||
def on_data_form(self, message):
|
def on_data_form(self, message):
|
||||||
"""
|
"""
|
||||||
When a data form is received
|
When a data form is received
|
||||||
|
@ -598,6 +622,8 @@ class Core(object):
|
||||||
When receiving private message from a muc OR a normal message
|
When receiving private message from a muc OR a normal message
|
||||||
(from one of our contacts)
|
(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':
|
if message['type'] == 'groupchat':
|
||||||
return
|
return
|
||||||
# Differentiate both type of messages, and call the appropriate handler.
|
# Differentiate both type of messages, and call the appropriate handler.
|
||||||
|
@ -1459,6 +1485,7 @@ class Core(object):
|
||||||
the_input.key_backspace()
|
the_input.key_backspace()
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
|
items.extend(list(self.pending_invites.keys()))
|
||||||
the_input.auto_completion(items, '')
|
the_input.auto_completion(items, '')
|
||||||
else:
|
else:
|
||||||
# we are writing the server: complete the server
|
# we are writing the server: complete the server
|
||||||
|
@ -1466,6 +1493,7 @@ class Core(object):
|
||||||
for tab in self.tabs:
|
for tab in self.tabs:
|
||||||
if isinstance(tab, tabs.MucTab):
|
if isinstance(tab, tabs.MucTab):
|
||||||
serv_list.append('%s@%s'% (jid.user, JID(tab.get_name()).host))
|
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, '')
|
the_input.auto_completion(serv_list, '')
|
||||||
return True
|
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')
|
self.information(_("You didn't specify a server for the room you want to join"), 'Error')
|
||||||
return
|
return
|
||||||
room = room.lower()
|
room = room.lower()
|
||||||
|
if room in self.pending_invites:
|
||||||
|
del self.pending_invites[room]
|
||||||
tab = self.get_tab_by_name(room, tabs.MucTab)
|
tab = self.get_tab_by_name(room, tabs.MucTab)
|
||||||
if len(args) == 2: # a password is provided
|
if len(args) == 2: # a password is provided
|
||||||
password = args[1]
|
password = args[1]
|
||||||
|
|
Loading…
Reference in a new issue