Philipp Hörist pushed to branch master at gajim / gajim
Commits:
0acfc4c8 by Philipp Hörist at 2019-10-18T21:01:28Z
MAM: Correctly detect if we sent a message
properties.jid always yields the remote JID now after nbxmpp changes
- - - - -
1 changed file:
- gajim/common/modules/mam.py
Changes:
=====================================
gajim/common/modules/mam.py
=====================================
@@ -96,7 +96,7 @@ class MAM(BaseModule):
if properties.is_muc_pm:
return properties.mam.id, properties.id
- if self._con.get_own_jid().bareMatch(properties.jid):
+ if self._con.get_own_jid().bareMatch(properties.from_):
# message we sent
return properties.mam.id, properties.id
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/0acfc4c8087c731296a49e3cd4c489ee09…
--
View it on GitLab: https://dev.gajim.org/gajim/gajim/commit/0acfc4c8087c731296a49e3cd4c489ee09…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
8fb372a5 by Philipp Hörist at 2019-10-16T17:42:10Z
Use monotonic time for timeouts
Fixes #87
- - - - -
1 changed file:
- nbxmpp/idlequeue.py
Changes:
=====================================
nbxmpp/idlequeue.py
=====================================
@@ -22,6 +22,7 @@ import os
import errno
import select
import logging
+import time
log = logging.getLogger('nbxmpp.idlequeue')
# needed for get_idleqeue
@@ -174,8 +175,7 @@ class IdleCommand(IdleObject):
self.pipe = Popen(self._compose_command_args(), stdout=PIPE,
bufsize=1024, shell=True, stderr=STDOUT, stdin=PIPE)
if self.commandtimeout >= 0:
- self.endtime = self.idlequeue.current_time() + \
- (self.commandtimeout * 1e6)
+ self.endtime = self.idlequeue.current_time() + self.commandtimeout
self.idlequeue.set_alarm(self.wait_child, 0.1)
def _start_posix(self):
@@ -253,7 +253,7 @@ class IdleQueue:
"""
Set up a new alarm. alarm_cb will be called after specified seconds.
"""
- alarm_time = self.current_time() + (seconds * 1e6)
+ alarm_time = self.current_time() + seconds
# almost impossible, but in case we have another alarm_cb at this time
if alarm_time in self.alarms:
self.alarms[alarm_time].append(alarm_cb)
@@ -306,7 +306,7 @@ class IdleQueue:
if func:
log_txt += ' with function ' + str(func)
log.info(log_txt)
- timeout = self.current_time() + (seconds * 1e6)
+ timeout = self.current_time() + seconds
if fd in self.read_timeouts:
self.read_timeouts[fd][timeout] = func
else:
@@ -385,8 +385,7 @@ class IdleQueue:
self._remove_idle(fd)
def current_time(self):
- from time import time
- return time() * 1e6
+ return time.monotonic()
def _remove_idle(self, fd):
"""
@@ -571,5 +570,3 @@ class GlibIdleQueue(IdleQueue):
def process(self):
self._check_time_events()
-
- current_time = GLib.get_real_time
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/8fb372a55962a47e4ddf8bb35a…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/8fb372a55962a47e4ddf8bb35a…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
bf53ae00 by Philipp Hörist at 2019-10-16T11:14:46Z
Don't import version from package
__init__.py has too many other imports, this leads to all dependencys beeing imported in the install process before they are downloaded
- - - - -
1 changed file:
- setup.cfg
Changes:
=====================================
setup.cfg
=====================================
@@ -1,6 +1,6 @@
[metadata]
name = nbxmpp
-version = attr: nbxmpp.__version__
+version = 0.9.92
description = Non blocking Jabber/XMPP module
author = Yann Leboulanger, Philipp Hoerist
author_email = gajim-devel(a)gajim.org
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/bf53ae006052d0a3265a1969d9…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/bf53ae006052d0a3265a1969d9…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
8cc2f1d3 by Philipp Hörist at 2019-10-14T15:06:06Z
Add xhtml message attribute
- - - - -
bae3cfd1 by Philipp Hörist at 2019-10-14T16:20:19Z
Add Security Labels (XEP-0258) support
- - - - -
16305759 by Philipp Hörist at 2019-10-14T18:53:27Z
Add Chat State Notifications (XEP-0085) support
- - - - -
6705a89b by Philipp Hörist at 2019-10-14T18:53:31Z
Attention: Don't parse legacy delay tags
- - - - -
8 changed files:
- nbxmpp/const.py
- nbxmpp/dispatcher.py
- nbxmpp/modules/attention.py
- + nbxmpp/modules/chatstates.py
- nbxmpp/modules/message.py
- + nbxmpp/modules/security_labels.py
- nbxmpp/protocol.py
- nbxmpp/structs.py
Changes:
=====================================
nbxmpp/const.py
=====================================
@@ -545,3 +545,12 @@ TUNE_DATA = [
'title',
'track',
'uri']
+
+
+CHATSTATES = [
+ 'active',
+ 'inactive',
+ 'gone',
+ 'composing',
+ 'paused'
+]
\ No newline at end of file
=====================================
nbxmpp/dispatcher.py
=====================================
@@ -76,6 +76,8 @@ from nbxmpp.modules.receipts import Receipts
from nbxmpp.modules.oob import OOB
from nbxmpp.modules.correction import Correction
from nbxmpp.modules.attention import Attention
+from nbxmpp.modules.security_labels import SecurityLabels
+from nbxmpp.modules.chatstates import Chatstates
from nbxmpp.modules.misc import unwrap_carbon
from nbxmpp.modules.misc import unwrap_mam
from nbxmpp.util import get_properties_struct
@@ -219,6 +221,8 @@ class XMPPDispatcher(PlugIn):
self._modules['OOB'] = OOB(self._owner)
self._modules['Correction'] = Correction(self._owner)
self._modules['Attention'] = Attention(self._owner)
+ self._modules['SecurityLabels'] = SecurityLabels(self._owner)
+ self._modules['Chatstates'] = Chatstates(self._owner)
for instance in self._modules.values():
for handler in instance.handlers:
=====================================
nbxmpp/modules/attention.py
=====================================
@@ -45,7 +45,7 @@ class Attention:
if properties.is_carbon_message and properties.carbon.is_sent:
return
- if stanza.getTag('x', namespace=NS_DELAY2) is not None:
+ if stanza.getTag('delay', namespace=NS_DELAY2) is not None:
return
properties.attention = True
=====================================
nbxmpp/modules/chatstates.py
=====================================
@@ -0,0 +1,62 @@
+# 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_CHATSTATES
+from nbxmpp.protocol import NS_DELAY2
+from nbxmpp.structs import StanzaHandler
+from nbxmpp.const import CHATSTATES
+
+log = logging.getLogger('nbxmpp.m.chatstates')
+
+
+class Chatstates:
+ def __init__(self, client):
+ self._client = client
+ self.handlers = [
+ StanzaHandler(name='message',
+ callback=self._process_message_chatstate,
+ ns=NS_CHATSTATES,
+ priority=15),
+ ]
+
+ def _process_message_chatstate(self, _con, stanza, properties):
+ chatstate = parse_chatstate(stanza)
+ if chatstate is None:
+ return
+
+ if properties.is_mam_message:
+ return
+
+ if stanza.getTag('delay', namespace=NS_DELAY2) is not None:
+ return
+
+ if chatstate not in CHATSTATES:
+ log.warning('Invalid chatstate: %s', chatstate)
+ log.warning(stanza)
+ return
+
+ properties.chatstate = chatstate
+
+
+def parse_chatstate(stanza):
+ children = stanza.getChildren()
+ for child in children:
+ if child.getNamespace() == NS_CHATSTATES:
+ return child.getName()
+ return None
=====================================
nbxmpp/modules/message.py
=====================================
@@ -79,6 +79,7 @@ class BaseMessage:
forms = stanza.getTags('x', namespace=NS_DATA)
if forms:
properties.forms = forms
+ properties.xhtml = stanza.getXHTML()
@staticmethod
def _parse_type(stanza):
=====================================
nbxmpp/modules/security_labels.py
=====================================
@@ -0,0 +1,57 @@
+# 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_SECLABEL
+from nbxmpp.structs import StanzaHandler
+from nbxmpp.structs import SecurityLabel
+from nbxmpp.structs import DisplayMarking
+
+log = logging.getLogger('nbxmpp.m.security_labels')
+
+
+class SecurityLabels:
+ def __init__(self, client):
+ self._client = client
+ self.handlers = [
+ StanzaHandler(name='message',
+ callback=self._process_message_security_label,
+ ns=NS_SECLABEL,
+ priority=15),
+ ]
+
+ def _process_message_security_label(self, _con, stanza, properties):
+ security = stanza.getTag('securitylabel', namespace=NS_SECLABEL)
+ if security is None:
+ return
+
+ displaymarking = security.getTag('displaymarking')
+ if displaymarking is None:
+ return
+
+ label = displaymarking.getData()
+ if not label:
+ log.warning('No label found')
+ log.warning(stanza)
+ return
+
+ fgcolor = displaymarking.getAttr('fgcolor')
+ bgcolor = displaymarking.getAttr('bgcolor')
+
+ properties.security_label = SecurityLabel(
+ DisplayMarking(label, fgcolor, bgcolor))
=====================================
nbxmpp/protocol.py
=====================================
@@ -1243,12 +1243,14 @@ class Message(Protocol):
TODO: Returning a DOM could make rendering faster.
"""
- xhtml = self.getTag('html')
+ xhtml = self.getTag('html', namespace=NS_XHTML_IM)
if xhtml:
if xmllang:
- body = xhtml.getTag('body', attrs={'xml:lang': xmllang})
+ body = xhtml.getTag('body',
+ namespace=NS_XHTML,
+ attrs={'xml:lang': xmllang})
else:
- body = xhtml.getTag('body')
+ body = xhtml.getTag('body', namespace=NS_XHTML)
return str(body)
return None
=====================================
nbxmpp/structs.py
=====================================
@@ -125,6 +125,9 @@ OOBData = namedtuple('OOBData', 'url desc')
CorrectionData = namedtuple('CorrectionData', 'id')
+DisplayMarking = namedtuple('DisplayMarking', 'label fgcolor bgcolor')
+SecurityLabel = namedtuple('SecurityLabel', 'displaymarking')
+
class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms timestamp')):
@@ -553,6 +556,9 @@ class MessageProperties:
self.correction = None
self.attention = False
self.forms = None
+ self.xhtml = None
+ self.security_label = None
+ self.chatstate = None
@property
def has_user_delay(self):
@@ -649,6 +655,18 @@ class MessageProperties:
def has_forms(self):
return self.forms is not None
+ @property
+ def has_xhtml(self):
+ return self.xhtml is not None
+
+ @property
+ def has_security_label(self):
+ return self.security_label is not None
+
+ @property
+ def has_chatstate(self):
+ return self.chatstate is not None
+
class IqProperties:
def __init__(self):
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/22ddb4b89a8bdd94d96c7b4b0…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/22ddb4b89a8bdd94d96c7b4b0…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
9ccb310e by Philipp Hörist at 2019-10-13T17:56:50Z
Add Correction (XEP-0308) support
- - - - -
91c6dd86 by Philipp Hörist at 2019-10-13T18:16:58Z
Add Attention (XEP-0224) support
- - - - -
22ddb4b8 by Philipp Hörist at 2019-10-13T19:36:17Z
Add forms message attribute
- - - - -
6 changed files:
- nbxmpp/dispatcher.py
- + nbxmpp/modules/attention.py
- + nbxmpp/modules/correction.py
- nbxmpp/modules/message.py
- nbxmpp/protocol.py
- nbxmpp/structs.py
Changes:
=====================================
nbxmpp/dispatcher.py
=====================================
@@ -74,6 +74,8 @@ 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.attention import Attention
from nbxmpp.modules.misc import unwrap_carbon
from nbxmpp.modules.misc import unwrap_mam
from nbxmpp.util import get_properties_struct
@@ -215,6 +217,8 @@ 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)
+ self._modules['Attention'] = Attention(self._owner)
for instance in self._modules.values():
for handler in instance.handlers:
=====================================
nbxmpp/modules/attention.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_ATTENTION
+from nbxmpp.protocol import NS_DELAY2
+from nbxmpp.structs import StanzaHandler
+
+log = logging.getLogger('nbxmpp.m.attention')
+
+
+class Attention:
+ def __init__(self, client):
+ self._client = client
+ self.handlers = [
+ StanzaHandler(name='message',
+ callback=self._process_message_attention,
+ ns=NS_ATTENTION,
+ priority=15),
+ ]
+
+ def _process_message_attention(self, _con, stanza, properties):
+ attention = stanza.getTag('attention', namespace=NS_ATTENTION)
+ if attention is None:
+ return
+
+ if properties.is_mam_message:
+ return
+
+ if properties.is_carbon_message and properties.carbon.is_sent:
+ return
+
+ if stanza.getTag('x', namespace=NS_DELAY2) is not None:
+ return
+
+ properties.attention = True
=====================================
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_)
=====================================
nbxmpp/modules/message.py
=====================================
@@ -18,6 +18,7 @@
import logging
from nbxmpp.protocol import NodeProcessed
+from nbxmpp.protocol import NS_DATA
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import StanzaIDData
from nbxmpp.util import error_factory
@@ -75,6 +76,9 @@ class BaseMessage:
properties.body = stanza.getBody()
properties.thread = stanza.getThread()
properties.subject = stanza.getSubject()
+ forms = stanza.getTags('x', namespace=NS_DATA)
+ if forms:
+ properties.forms = forms
@staticmethod
def _parse_type(stanza):
=====================================
nbxmpp/protocol.py
=====================================
@@ -1369,6 +1369,12 @@ 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_})
+
+ def setAttention(self):
+ self.setTag('attention', namespace=NS_ATTENTION)
+
class Presence(Protocol):
=====================================
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,9 @@ class MessageProperties:
self.marker = None
self.receipt = None
self.oob = None
+ self.correction = None
+ self.attention = False
+ self.forms = None
@property
def has_user_delay(self):
@@ -632,6 +637,18 @@ class MessageProperties:
def is_oob(self):
return self.oob is not None
+ @property
+ def is_correction(self):
+ return self.correction is not None
+
+ @property
+ def has_attention(self):
+ return self.attention
+
+ @property
+ def has_forms(self):
+ return self.forms is not None
+
class IqProperties:
def __init__(self):
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/af360130ec8655f9c947fc97b…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/af360130ec8655f9c947fc97b…
You're receiving this email because of your account on dev.gajim.org.