Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2019-10-12 16:17:20 +0300
committerPhilipp Hörist <philipp@hoerist.com>2019-10-12 16:17:20 +0300
commita15b98aec870e0e6c8fac08f102b5da182aa0470 (patch)
treee87004f322cdf374c9bcb7c4d553e24471536b01 /nbxmpp/modules
parent64b8f9b754610ac1f6e8c8f55f0a117bfaa4ffcf (diff)
Add Receipts (XEP-0184) support
Diffstat (limited to 'nbxmpp/modules')
-rw-r--r--nbxmpp/modules/receipts.py51
1 files changed, 51 insertions, 0 deletions
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 <philipp AT hoerist.com>
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+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_)