Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
90d5e6da by Philipp Hörist at 2019-07-05T20:21:20Z
JID: Add method to make the JID bare
- - - - -
de0a912a by Philipp Hörist at 2019-07-05T20:22:03Z
DiscoInfo: Add property is_muc
- - - - -
c5d36cd0 by Philipp Hörist at 2019-07-05T20:24:15Z
JID: Use isinstance for type check
- - - - -
f39d0057 by Philipp Hörist at 2019-07-05T20:25:40Z
JID: Add copy() method
- - - - -
1795473b by Philipp Hörist at 2019-07-05T20:43:58Z
Add muc_jid attribute to Message and Presence
Attribute contains a bare JID object if the Message or Presence is from a MUC
- - - - -
3 changed files:
- nbxmpp/modules/muc.py
- nbxmpp/protocol.py
- nbxmpp/structs.py
Changes:
=====================================
nbxmpp/modules/muc.py
=====================================
@@ -97,6 +97,8 @@ class MUC:
if muc is None:
return
properties.from_muc = True
+ properties.muc_jid = properties.jid.copy()
+ properties.muc_jid.setBare()
properties.muc_nickname = properties.jid.getResource()
def _process_muc_user_presence(self, _con, stanza, properties):
@@ -104,6 +106,8 @@ class MUC:
if muc_user is None:
return
properties.from_muc = True
+ properties.muc_jid = properties.jid.copy()
+ properties.muc_jid.setBare()
destroy = muc_user.getTag('destroy')
if destroy is not None:
@@ -158,6 +162,8 @@ class MUC:
def _process_groupchat_message(self, _con, stanza, properties):
properties.from_muc = True
+ properties.muc_jid = properties.jid.copy()
+ properties.muc_jid.setBare()
properties.muc_nickname = properties.jid.getResource() or None
muc_user = stanza.getTag('x', namespace=NS_MUC_USER)
@@ -185,6 +191,8 @@ class MUC:
return
properties.from_muc = True
+ properties.muc_jid = properties.jid.copy()
+ properties.muc_jid.setBare()
if not properties.jid.isBare:
return
@@ -249,6 +257,8 @@ class MUC:
return
properties.from_muc = True
+ properties.muc_jid = properties.jid.copy()
+ properties.muc_jid.setBare()
data = {}
@@ -291,6 +301,9 @@ class MUC:
return
properties.voice_request = VoiceRequest(form=data_form)
+ properties.from_muc = True
+ properties.muc_jid = properties.jid.copy()
+ properties.muc_jid.setBare()
@call_on_response('_affiliation_received')
def get_affiliation(self, jid, affiliation):
=====================================
nbxmpp/protocol.py
=====================================
@@ -816,7 +816,8 @@ class JID:
"""
if not jid and not domain:
raise ValueError('JID must contain at least domain name')
- elif type(jid) == type(self):
+
+ if isinstance(jid, JID):
self.node, self.domain = jid.node, jid.domain
self.resource = jid.resource
elif domain:
@@ -824,6 +825,9 @@ class JID:
else:
self.node, self.domain, self.resource = parse_jid(jid)
+ def copy(self):
+ return JID(self)
+
def getNode(self):
"""
Return the node part of the JID
@@ -874,6 +878,12 @@ class JID:
"""
return self.__str__(0)
+ def setBare(self):
+ """
+ Deletes the resource which makes the JID bare
+ """
+ self.resource = ''
+
@property
def isBare(self):
return self.node and self.domain and not self.resource
=====================================
nbxmpp/structs.py
=====================================
@@ -23,6 +23,7 @@ from nbxmpp.protocol import JID
from nbxmpp.protocol import NS_STANZAS
from nbxmpp.protocol import NS_MAM_1
from nbxmpp.protocol import NS_MAM_2
+from nbxmpp.protocol import NS_MUC
from nbxmpp.const import MessageType
from nbxmpp.const import AvatarState
from nbxmpp.const import StatusCode
@@ -131,6 +132,15 @@ class DiscoInfo(namedtuple('DiscoInfo', 'jid node
identities features dataforms'
except Exception:
return None
+ @property
+ def is_muc(self):
+ for identity in self.identities:
+ if identity.category == 'conference':
+ if NS_MUC in self.features:
+ return True
+ return False
+
+
class DiscoIdentity(namedtuple('DiscoIdentity', 'category type name lang')):
@@ -236,6 +246,7 @@ class MessageProperties:
self.http_auth = None
self.nickname = None
self.from_muc = False
+ self.muc_jid = None
self.muc_nickname = None
self.muc_status_codes = None
self.muc_private_message = False
@@ -364,6 +375,7 @@ class PresenceProperties:
self.error = None
self.avatar_sha = None
self.avatar_state = AvatarState.IGNORE
+ self.muc_jid = None
self.muc_status_codes = None
self.muc_user = None
self.muc_nickname = None
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/compare/3946f35bfc334812d969934c41e9d0e7a218f488...1795473b5d699be0b95b511b0b7d03a8ca0ec348
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/compare/3946f35bfc334812d969934c41e9d0e7a218f488...1795473b5d699be0b95b511b0b7d03a8ca0ec348
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits