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
path: root/nbxmpp
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2019-10-13 20:56:50 +0300
committerPhilipp Hörist <philipp@hoerist.com>2019-10-13 20:56:50 +0300
commit9ccb310e9d7a001c89d79add484efd9e826c7307 (patch)
treef511f0d195523b483bc1d1e79c180b7ad39deeba /nbxmpp
parentaf360130ec8655f9c947fc97bee2c033d62d2798 (diff)
Add Correction (XEP-0308) support
Diffstat (limited to 'nbxmpp')
-rw-r--r--nbxmpp/dispatcher.py2
-rw-r--r--nbxmpp/modules/correction.py48
-rw-r--r--nbxmpp/protocol.py3
-rw-r--r--nbxmpp/structs.py7
4 files changed, 60 insertions, 0 deletions
diff --git a/nbxmpp/dispatcher.py b/nbxmpp/dispatcher.py
index 2ba87fc..dfae173 100644
--- a/nbxmpp/dispatcher.py
+++ b/nbxmpp/dispatcher.py
@@ -74,6 +74,7 @@ from nbxmpp.modules.discovery import Discovery
from nbxmpp.modules.chat_markers import ChatMarkers
from nbxmpp.modules.receipts import Receipts
from nbxmpp.modules.oob import OOB
+from nbxmpp.modules.correction import Correction
from nbxmpp.modules.misc import unwrap_carbon
from nbxmpp.modules.misc import unwrap_mam
from nbxmpp.util import get_properties_struct
@@ -215,6 +216,7 @@ class XMPPDispatcher(PlugIn):
self._modules['ChatMarkers'] = ChatMarkers(self._owner)
self._modules['Receipts'] = Receipts(self._owner)
self._modules['OOB'] = OOB(self._owner)
+ self._modules['Correction'] = Correction(self._owner)
for instance in self._modules.values():
for handler in instance.handlers:
diff --git a/nbxmpp/modules/correction.py b/nbxmpp/modules/correction.py
new file mode 100644
index 0000000..d56bd29
--- /dev/null
+++ b/nbxmpp/modules/correction.py
@@ -0,0 +1,48 @@
+# 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_CORRECT
+from nbxmpp.structs import StanzaHandler
+from nbxmpp.structs import CorrectionData
+
+log = logging.getLogger('nbxmpp.m.correction')
+
+
+class Correction:
+ def __init__(self, client):
+ self._client = client
+ self.handlers = [
+ StanzaHandler(name='message',
+ callback=self._process_message_correction,
+ ns=NS_CORRECT,
+ priority=15),
+ ]
+
+ def _process_message_correction(self, _con, stanza, properties):
+ replace = stanza.getTag('replace', namespace=NS_CORRECT)
+ if replace is None:
+ return
+
+ id_ = replace.getAttr('id')
+ if id_ is None:
+ log.warning('Correcton without id attribute')
+ log.warning(stanza)
+ return
+
+ properties.correction = CorrectionData(id_)
diff --git a/nbxmpp/protocol.py b/nbxmpp/protocol.py
index 7f2926e..ccf1e78 100644
--- a/nbxmpp/protocol.py
+++ b/nbxmpp/protocol.py
@@ -1369,6 +1369,9 @@ class Message(Protocol):
if desc is not None:
oob.setTagData('desc', desc)
+ def setCorrection(self, id_):
+ self.setTag('replace', namespace=NS_CORRECT, attrs={'id': id_})
+
class Presence(Protocol):
diff --git a/nbxmpp/structs.py b/nbxmpp/structs.py
index bfb0cdf..3476fe5 100644
--- a/nbxmpp/structs.py
+++ b/nbxmpp/structs.py
@@ -123,6 +123,8 @@ DiscoItem.__new__.__defaults__ = (None, None)
OOBData = namedtuple('OOBData', 'url desc')
+CorrectionData = namedtuple('CorrectionData', 'id')
+
class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms timestamp')):
@@ -548,6 +550,7 @@ class MessageProperties:
self.marker = None
self.receipt = None
self.oob = None
+ self.correction = None
@property
def has_user_delay(self):
@@ -632,6 +635,10 @@ class MessageProperties:
def is_oob(self):
return self.oob is not None
+ @property
+ def is_correction(self):
+ return self.correction is not None
+
class IqProperties:
def __init__(self):