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

Commits:

4 changed files:

Changes:

  • nbxmpp/dispatcher.py
    ... ... @@ -73,6 +73,7 @@ from nbxmpp.modules.ibb import IBB
    73 73
     from nbxmpp.modules.discovery import Discovery
    
    74 74
     from nbxmpp.modules.chat_markers import ChatMarkers
    
    75 75
     from nbxmpp.modules.receipts import Receipts
    
    76
    +from nbxmpp.modules.oob import OOB
    
    76 77
     from nbxmpp.modules.misc import unwrap_carbon
    
    77 78
     from nbxmpp.modules.misc import unwrap_mam
    
    78 79
     from nbxmpp.util import get_properties_struct
    
    ... ... @@ -213,6 +214,7 @@ class XMPPDispatcher(PlugIn):
    213 214
             self._modules['Discovery'] = Discovery(self._owner)
    
    214 215
             self._modules['ChatMarkers'] = ChatMarkers(self._owner)
    
    215 216
             self._modules['Receipts'] = Receipts(self._owner)
    
    217
    +        self._modules['OOB'] = OOB(self._owner)
    
    216 218
     
    
    217 219
             for instance in self._modules.values():
    
    218 220
                 for handler in instance.handlers:
    

  • nbxmpp/modules/oob.py
    1
    +# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
    
    2
    +#
    
    3
    +# This file is part of nbxmpp.
    
    4
    +#
    
    5
    +# This program is free software; you can redistribute it and/or
    
    6
    +# modify it under the terms of the GNU General Public License
    
    7
    +# as published by the Free Software Foundation; either version 3
    
    8
    +# of the License, or (at your option) any later version.
    
    9
    +#
    
    10
    +# This program is distributed in the hope that it will be useful,
    
    11
    +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    12
    +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    
    13
    +# GNU General Public License for more details.
    
    14
    +#
    
    15
    +# You should have received a copy of the GNU General Public License
    
    16
    +# along with this program; If not, see <http://www.gnu.org/licenses/>.
    
    17
    +
    
    18
    +import logging
    
    19
    +
    
    20
    +from nbxmpp.protocol import NS_X_OOB
    
    21
    +from nbxmpp.structs import StanzaHandler
    
    22
    +from nbxmpp.structs import OOBData
    
    23
    +
    
    24
    +log = logging.getLogger('nbxmpp.m.oob')
    
    25
    +
    
    26
    +
    
    27
    +class OOB:
    
    28
    +    def __init__(self, client):
    
    29
    +        self._client = client
    
    30
    +        self.handlers = [
    
    31
    +            StanzaHandler(name='message',
    
    32
    +                          callback=self._process_message_oob,
    
    33
    +                          ns=NS_X_OOB,
    
    34
    +                          priority=15),
    
    35
    +        ]
    
    36
    +
    
    37
    +    def _process_message_oob(self, _con, stanza, properties):
    
    38
    +        oob = stanza.getTag('x', namespace=NS_X_OOB)
    
    39
    +        if oob is None:
    
    40
    +            return
    
    41
    +
    
    42
    +        url = oob.getTagData('url')
    
    43
    +        if url is None:
    
    44
    +            log.warning('OOB data without url')
    
    45
    +            log.warning(stanza)
    
    46
    +            return
    
    47
    +
    
    48
    +        desc = oob.getTagData('desc')
    
    49
    +        properties.oob = OOBData(url, desc)

  • nbxmpp/protocol.py
    ... ... @@ -1363,6 +1363,12 @@ class Message(Protocol):
    1363 1363
         def setReceiptReceived(self, id_):
    
    1364 1364
             self.setTag('received', namespace=NS_RECEIPTS, attrs={'id': id_})
    
    1365 1365
     
    
    1366
    +    def setOOB(self, url, desc=None):
    
    1367
    +        oob = self.setTag('x', namespace=NS_X_OOB)
    
    1368
    +        oob.setTagData('url', url)
    
    1369
    +        if desc is not None:
    
    1370
    +            oob.setTagData('desc', desc)
    
    1371
    +
    
    1366 1372
     
    
    1367 1373
     class Presence(Protocol):
    
    1368 1374
     
    

  • nbxmpp/structs.py
    ... ... @@ -121,6 +121,8 @@ DiscoItems = namedtuple('DiscoItems', 'jid node items')
    121 121
     DiscoItem = namedtuple('DiscoItem', 'jid name node')
    
    122 122
     DiscoItem.__new__.__defaults__ = (None, None)
    
    123 123
     
    
    124
    +OOBData = namedtuple('OOBData', 'url desc')
    
    125
    +
    
    124 126
     
    
    125 127
     class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms timestamp')):
    
    126 128
     
    
    ... ... @@ -545,6 +547,7 @@ class MessageProperties:
    545 547
             self.pgp_legacy = None
    
    546 548
             self.marker = None
    
    547 549
             self.receipt = None
    
    550
    +        self.oob = None
    
    548 551
     
    
    549 552
         @property
    
    550 553
         def has_user_delay(self):
    
    ... ... @@ -625,6 +628,10 @@ class MessageProperties:
    625 628
         def is_receipt(self):
    
    626 629
             return self.receipt is not None
    
    627 630
     
    
    631
    +    @property
    
    632
    +    def is_oob(self):
    
    633
    +        return self.oob is not None
    
    634
    +
    
    628 635
     
    
    629 636
     class IqProperties:
    
    630 637
         def __init__(self):