From a15b98aec870e0e6c8fac08f102b5da182aa0470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sat, 12 Oct 2019 15:17:20 +0200 Subject: Add Receipts (XEP-0184) support --- nbxmpp/modules/receipts.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 nbxmpp/modules/receipts.py (limited to 'nbxmpp/modules') diff --git a/nbxmpp/modules/receipts.py b/nbxmpp/modules/receipts.py new file mode 100644 index 0000000..f0be9b5 --- /dev/null +++ b/nbxmpp/modules/receipts.py @@ -0,0 +1,51 @@ +# Copyright (C) 2018 Philipp Hörist +# +# This file is part of nbxmpp. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; If not, see . + +import logging + +from nbxmpp.protocol import NS_RECEIPTS +from nbxmpp.structs import StanzaHandler +from nbxmpp.structs import ReceiptData + +log = logging.getLogger('nbxmpp.m.receipts') + + +class Receipts: + def __init__(self, client): + self._client = client + self.handlers = [ + StanzaHandler(name='message', + callback=self._process_message_receipt, + ns=NS_RECEIPTS, + priority=15), + ] + + def _process_message_receipt(self, _con, stanza, properties): + request = stanza.getTag('request', namespace=NS_RECEIPTS) + if request is not None: + properties.receipt = ReceiptData(request.getName()) + return + + received = stanza.getTag('received', namespace=NS_RECEIPTS) + if received is not None: + id_ = received.getAttr('id') + if id_ is None: + log.warning('Receipt without id attr') + log.warning(stanza) + return + + properties.receipt = ReceiptData(received.getName(), id_) -- cgit v1.2.3