Philipp Hörist pushed to branch master at gajim / python-nbxmpp

Commits:

3 changed files:

Changes:

  • nbxmpp/modules/muc.py
    ... ... @@ -97,6 +97,8 @@ class MUC:
    97 97
             if muc is None:
    
    98 98
                 return
    
    99 99
             properties.from_muc = True
    
    100
    +        properties.muc_jid = properties.jid.copy()
    
    101
    +        properties.muc_jid.setBare()
    
    100 102
             properties.muc_nickname = properties.jid.getResource()
    
    101 103
     
    
    102 104
         def _process_muc_user_presence(self, _con, stanza, properties):
    
    ... ... @@ -104,6 +106,8 @@ class MUC:
    104 106
             if muc_user is None:
    
    105 107
                 return
    
    106 108
             properties.from_muc = True
    
    109
    +        properties.muc_jid = properties.jid.copy()
    
    110
    +        properties.muc_jid.setBare()
    
    107 111
     
    
    108 112
             destroy = muc_user.getTag('destroy')
    
    109 113
             if destroy is not None:
    
    ... ... @@ -158,6 +162,8 @@ class MUC:
    158 162
     
    
    159 163
         def _process_groupchat_message(self, _con, stanza, properties):
    
    160 164
             properties.from_muc = True
    
    165
    +        properties.muc_jid = properties.jid.copy()
    
    166
    +        properties.muc_jid.setBare()
    
    161 167
             properties.muc_nickname = properties.jid.getResource() or None
    
    162 168
     
    
    163 169
             muc_user = stanza.getTag('x', namespace=NS_MUC_USER)
    
    ... ... @@ -185,6 +191,8 @@ class MUC:
    185 191
                 return
    
    186 192
     
    
    187 193
             properties.from_muc = True
    
    194
    +        properties.muc_jid = properties.jid.copy()
    
    195
    +        properties.muc_jid.setBare()
    
    188 196
     
    
    189 197
             if not properties.jid.isBare:
    
    190 198
                 return
    
    ... ... @@ -249,6 +257,8 @@ class MUC:
    249 257
                 return
    
    250 258
     
    
    251 259
             properties.from_muc = True
    
    260
    +        properties.muc_jid = properties.jid.copy()
    
    261
    +        properties.muc_jid.setBare()
    
    252 262
     
    
    253 263
             data = {}
    
    254 264
     
    
    ... ... @@ -291,6 +301,9 @@ class MUC:
    291 301
                 return
    
    292 302
     
    
    293 303
             properties.voice_request = VoiceRequest(form=data_form)
    
    304
    +        properties.from_muc = True
    
    305
    +        properties.muc_jid = properties.jid.copy()
    
    306
    +        properties.muc_jid.setBare()
    
    294 307
     
    
    295 308
         @call_on_response('_affiliation_received')
    
    296 309
         def get_affiliation(self, jid, affiliation):
    

  • nbxmpp/protocol.py
    ... ... @@ -816,7 +816,8 @@ class JID:
    816 816
             """
    
    817 817
             if not jid and not domain:
    
    818 818
                 raise ValueError('JID must contain at least domain name')
    
    819
    -        elif type(jid) == type(self):
    
    819
    +
    
    820
    +        if isinstance(jid, JID):
    
    820 821
                 self.node, self.domain = jid.node, jid.domain
    
    821 822
                 self.resource = jid.resource
    
    822 823
             elif domain:
    
    ... ... @@ -824,6 +825,9 @@ class JID:
    824 825
             else:
    
    825 826
                 self.node, self.domain, self.resource = parse_jid(jid)
    
    826 827
     
    
    828
    +    def copy(self):
    
    829
    +        return JID(self)
    
    830
    +
    
    827 831
         def getNode(self):
    
    828 832
             """
    
    829 833
             Return the node part of the JID
    
    ... ... @@ -874,6 +878,12 @@ class JID:
    874 878
             """
    
    875 879
             return self.__str__(0)
    
    876 880
     
    
    881
    +    def setBare(self):
    
    882
    +        """
    
    883
    +        Deletes the resource which makes the JID bare
    
    884
    +        """
    
    885
    +        self.resource = ''
    
    886
    +
    
    877 887
         @property
    
    878 888
         def isBare(self):
    
    879 889
             return self.node and self.domain and not self.resource
    

  • nbxmpp/structs.py
    ... ... @@ -23,6 +23,7 @@ from nbxmpp.protocol import JID
    23 23
     from nbxmpp.protocol import NS_STANZAS
    
    24 24
     from nbxmpp.protocol import NS_MAM_1
    
    25 25
     from nbxmpp.protocol import NS_MAM_2
    
    26
    +from nbxmpp.protocol import NS_MUC
    
    26 27
     from nbxmpp.const import MessageType
    
    27 28
     from nbxmpp.const import AvatarState
    
    28 29
     from nbxmpp.const import StatusCode
    
    ... ... @@ -131,6 +132,15 @@ class DiscoInfo(namedtuple('DiscoInfo', 'jid node identities features dataforms'
    131 132
             except Exception:
    
    132 133
                 return None
    
    133 134
     
    
    135
    +    @property
    
    136
    +    def is_muc(self):
    
    137
    +        for identity in self.identities:
    
    138
    +            if identity.category == 'conference':
    
    139
    +                if NS_MUC in self.features:
    
    140
    +                    return True
    
    141
    +        return False
    
    142
    +    
    
    143
    +
    
    134 144
     
    
    135 145
     class DiscoIdentity(namedtuple('DiscoIdentity', 'category type name lang')):
    
    136 146
     
    
    ... ... @@ -236,6 +246,7 @@ class MessageProperties:
    236 246
             self.http_auth = None
    
    237 247
             self.nickname = None
    
    238 248
             self.from_muc = False
    
    249
    +        self.muc_jid = None
    
    239 250
             self.muc_nickname = None
    
    240 251
             self.muc_status_codes = None
    
    241 252
             self.muc_private_message = False
    
    ... ... @@ -364,6 +375,7 @@ class PresenceProperties:
    364 375
             self.error = None
    
    365 376
             self.avatar_sha = None
    
    366 377
             self.avatar_state = AvatarState.IGNORE
    
    378
    +        self.muc_jid = None
    
    367 379
             self.muc_status_codes = None
    
    368 380
             self.muc_user = None
    
    369 381
             self.muc_nickname = None