XEP-0045: Better invitation handling
This commit is contained in:
parent
98b9a6f9e3
commit
7033bc0061
2 changed files with 33 additions and 12 deletions
|
@ -109,13 +109,15 @@ class XEP_0045(BasePlugin):
|
||||||
self.xmpp.register_handler(
|
self.xmpp.register_handler(
|
||||||
Callback(
|
Callback(
|
||||||
'MUCInvite',
|
'MUCInvite',
|
||||||
MatchXPath("{%s}message/{%s}x/{%s}invite" % (
|
StanzaPath('message/muc/invite'),
|
||||||
self.xmpp.default_ns,
|
|
||||||
stanza.NS_USER,
|
|
||||||
stanza.NS_USER
|
|
||||||
)),
|
|
||||||
self.handle_groupchat_invite
|
self.handle_groupchat_invite
|
||||||
))
|
))
|
||||||
|
self.xmpp.register_handler(
|
||||||
|
Callback(
|
||||||
|
'MUCDecline',
|
||||||
|
StanzaPath('message/muc/decline'),
|
||||||
|
self.handle_groupchat_decline
|
||||||
|
))
|
||||||
|
|
||||||
def plugin_end(self):
|
def plugin_end(self):
|
||||||
self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
|
self.xmpp.plugin['xep_0030'].del_feature(feature=stanza.NS)
|
||||||
|
@ -124,12 +126,15 @@ class XEP_0045(BasePlugin):
|
||||||
self.xmpp.plugin['xep_0030'].add_feature(stanza.NS)
|
self.xmpp.plugin['xep_0030'].add_feature(stanza.NS)
|
||||||
|
|
||||||
def handle_groupchat_invite(self, inv):
|
def handle_groupchat_invite(self, inv):
|
||||||
""" Handle an invite into a muc.
|
""" Handle an invite into a muc. """
|
||||||
"""
|
|
||||||
logging.debug("MUC invite to %s from %s: %s", inv['to'], inv["from"], inv)
|
|
||||||
if inv['from'] not in self.rooms.keys():
|
if inv['from'] not in self.rooms.keys():
|
||||||
self.xmpp.event("groupchat_invite", inv)
|
self.xmpp.event("groupchat_invite", inv)
|
||||||
|
|
||||||
|
def handle_groupchat_decline(self, decl):
|
||||||
|
"""Handle an invitation decline."""
|
||||||
|
if decl['from'] in self.room.keys():
|
||||||
|
self.xmpp.event('groupchat_decline', decl)
|
||||||
|
|
||||||
def handle_config_change(self, msg):
|
def handle_config_change(self, msg):
|
||||||
"""Handle a MUC configuration change (with status code)."""
|
"""Handle a MUC configuration change (with status code)."""
|
||||||
self.xmpp.event('groupchat_config_status', msg)
|
self.xmpp.event('groupchat_config_status', msg)
|
||||||
|
@ -265,16 +270,24 @@ class XEP_0045(BasePlugin):
|
||||||
iq['mucadmin_query'].append(item)
|
iq['mucadmin_query'].append(item)
|
||||||
await iq.send(**iqkwargs)
|
await iq.send(**iqkwargs)
|
||||||
|
|
||||||
def invite(self, room: JID, jid: JID, reason='', *,
|
def invite(self, room: JID, jid: JID, reason: str = '', *,
|
||||||
mfrom: Optional[JID] = None):
|
mfrom: Optional[JID] = None):
|
||||||
""" Invite a jid to a room."""
|
""" Invite a jid to a room."""
|
||||||
msg = self.xmpp.make_message(room, mfrom=mfrom)
|
msg = self.xmpp.make_message(room, mfrom=mfrom)
|
||||||
msg.enable('muc')
|
msg['muc']['invite']['to'] = jid
|
||||||
msg['muc']['invite'] = jid
|
|
||||||
if reason:
|
if reason:
|
||||||
msg['muc']['invite']['reason'] = reason
|
msg['muc']['invite']['reason'] = reason
|
||||||
self.xmpp.send(msg)
|
self.xmpp.send(msg)
|
||||||
|
|
||||||
|
def decline(self, room: JID, jid: JID, reason: str = '', *,
|
||||||
|
mfrom: Optional[JID] = None):
|
||||||
|
"""Decline a mediated invitation."""
|
||||||
|
msg = self.xmpp.make_message(room, mfrom=mfrom)
|
||||||
|
msg['muc']['decline']['to'] = jid
|
||||||
|
if reason:
|
||||||
|
msg['muc']['decline']['reason'] = reason
|
||||||
|
self.xmpp.send(msg)
|
||||||
|
|
||||||
def leave_muc(self, room: JID, nick: str, msg='', pfrom=None):
|
def leave_muc(self, room: JID, nick: str, msg='', pfrom=None):
|
||||||
""" Leave the specified room.
|
""" Leave the specified room.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -174,7 +174,15 @@ class MUCInvite(ElementBase):
|
||||||
name = 'invite'
|
name = 'invite'
|
||||||
plugin_attrib = 'invite'
|
plugin_attrib = 'invite'
|
||||||
namespace = NS_USER
|
namespace = NS_USER
|
||||||
interfaces = {'to', 'reason'}
|
interfaces = {'to', 'from', 'reason'}
|
||||||
|
sub_interfaces = {'reason'}
|
||||||
|
|
||||||
|
|
||||||
|
class MUCDecline(ElementBase):
|
||||||
|
name = 'decline'
|
||||||
|
plugin_attrib = 'decline'
|
||||||
|
namespace = NS_USER
|
||||||
|
interfaces = {'to', 'from', 'reason'}
|
||||||
sub_interfaces = {'reason'}
|
sub_interfaces = {'reason'}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue