Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
c58e9751 by Philipp Hörist at 2018-12-08T00:16:11Z
Count outgoing stanzas after session resume
- - - - -
1 changed file:
- nbxmpp/smacks.py
Changes:
=====================================
nbxmpp/smacks.py
=====================================
@@ -60,7 +60,6 @@ class Smacks(PlugIn):
self._session_id = None
self._location = None
- self._enable_sent = False
def get_resume_data(self):
if self.resume_supported:
@@ -128,7 +127,7 @@ class Smacks(PlugIn):
self._in_h += 1
def save_in_queue(self, stanza):
- if not self._enable_sent:
+ if not self._enable_sent and not self.resumed:
# We did not yet sent 'enable' so the server
# will not count our stanzas
return
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/c58e9751d779d09cb3460db03d…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/c58e9751d779d09cb3460db03d…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch gajim_1.1 at gajim / gajim
Commits:
6c2df541 by Philipp Hörist at 2018-12-06T19:52:30Z
Determine delay timestamp correctly
- Check the from attr on the delay node to determine if its a user timestamp or from the server
- Dont use user timestamp for sorting
- Record the user timestamp in additional data so its saved to the database
Fixes #9444
- - - - -
b4f43acb by Philipp Hörist at 2018-12-06T19:52:51Z
Encode resource with correct profile
Fixes #9465
- - - - -
5 changed files:
- gajim/common/helpers.py
- gajim/common/modules/mam.py
- gajim/common/modules/message.py
- gajim/common/modules/misc.py
- + test/no_gui/unit/test_helpers.py
Changes:
=====================================
gajim/common/helpers.py
=====================================
@@ -153,7 +153,7 @@ def parse_resource(resource):
"""
if resource:
try:
- return resource.encode('Nickname').decode('utf-8')
+ return resource.encode('OpaqueString').decode('utf-8')
except UnicodeError:
raise InvalidFormat('Invalid character in resource.')
=====================================
gajim/common/modules/mam.py
=====================================
@@ -130,12 +130,13 @@ class MAM:
raise nbxmpp.NodeProcessed
# Timestamp parsing
- timestamp = parse_delay(forwarded)
- if timestamp is None:
+ # Most servers dont set the 'from' attr, so we cant check for it
+ delay_timestamp = parse_delay(forwarded)
+ if delay_timestamp is None:
+ log.warning('No timestamp on MAM message')
+ log.warning(stanza)
raise nbxmpp.NodeProcessed
- user_timestamp = parse_delay(message)
-
# Fix for self messaging
if not groupchat:
to = message.getTo()
@@ -180,8 +181,7 @@ class MAM:
{'conn': self._con,
'additional_data': {},
'encrypted': False,
- 'timestamp': timestamp,
- 'user_timestamp': user_timestamp,
+ 'timestamp': delay_timestamp,
'self_message': self_message,
'groupchat': groupchat,
'muc_pm': muc_pm,
@@ -248,7 +248,12 @@ class MAM:
# For example Chatstates, Receipts, Chatmarkers
log.debug(event.message.getProperties())
return
- log.debug(event.msgtxt)
+
+ user_timestamp = parse_delay(event.stanza)
+ if user_timestamp is not None:
+ # Record it as a user timestamp
+ event.additional_data.set_value(
+ 'gajim', 'user_timestamp', user_timestamp)
event.correct_id = parse_correction(event.message)
parse_oob(event.message, event.additional_data)
=====================================
gajim/common/modules/message.py
=====================================
@@ -223,15 +223,40 @@ class Message:
except nbxmpp.NodeProcessed:
return
- timestamp, delayed = parse_delay(event.stanza), True
- if timestamp is None:
+ subject = event.stanza.getSubject()
+ groupchat = event.mtype == 'groupchat'
+ muc_subject = subject and groupchat
+
+ # Determine timestamps
+ if groupchat:
+ delay_entity_jid = event.jid
+ else:
+ delay_entity_jid = self._con.get_own_jid().getDomain()
+
+ if muc_subject:
+ # MUC Subjects can have a delay timestamp
+ # to indicate when the user has set the subject,
+ # the 'from' attr on these delays is the MUC server
+ # but we treat it as user timestamp
timestamp = time.time()
- delayed = False
+ user_timestamp = parse_delay(event.stanza, from_=delay_entity_jid)
+
+ else:
+ timestamp = parse_delay(event.stanza, from_=delay_entity_jid)
+ if timestamp is None:
+ timestamp = time.time()
+
+ user_timestamp = parse_delay(event.stanza,
+ not_from=[delay_entity_jid])
+
+ if user_timestamp is not None:
+ event.additional_data.set_value(
+ 'gajim', 'user_timestamp', user_timestamp)
event_attr = {
'popup': False,
'msg_log_id': None,
- 'subject': event.stanza.getSubject(),
+ 'subject': subject,
'displaymarking': parse_securitylabel(event.stanza),
'attention': parse_attention(event.stanza),
'correct_id': parse_correction(event.stanza),
@@ -239,7 +264,7 @@ class Message:
'form_node': parse_form(event.stanza),
'xhtml': parse_xhtml(event.stanza),
'timestamp': timestamp,
- 'delayed': delayed,
+ 'delayed': user_timestamp is not None,
}
parse_oob(event.stanza, event.additional_data)
@@ -257,7 +282,7 @@ class Message:
event.session, event.fjid, timestamp)
return
- if event.mtype == 'groupchat':
+ if groupchat:
app.nec.push_incoming_event(GcMessageReceivedEvent(
None,
conn=self._con,
=====================================
gajim/common/modules/misc.py
=====================================
@@ -65,18 +65,45 @@ def parse_eme(stanza):
# XEP-0203: Delayed Delivery
-def parse_delay(stanza, epoch=True, convert='utc'):
- timestamp = None
- delay = stanza.getTagAttr(
- 'delay', 'stamp', namespace=nbxmpp.NS_DELAY2)
- if delay is not None:
- timestamp = parse_datetime(delay, check_utc=True,
+def parse_delay(stanza, epoch=True, convert='utc', from_=None, not_from=None):
+ '''
+ Returns the first valid delay timestamp that matches
+
+ :param epoch: Returns the timestamp as epoch
+
+ :param convert: Converts the timestamp to either utc or local
+
+ :param from_: Matches only delays that have the according
+ from attr set
+
+ :param not_from: Matches only delays that have the according
+ from attr not set
+ '''
+ delays = stanza.getTags('delay', namespace=nbxmpp.NS_DELAY2)
+
+ for delay in delays:
+ stamp = delay.getAttr('stamp')
+ if stamp is None:
+ log.warning('Invalid timestamp received: %s', stamp)
+ log.warning(stanza)
+ continue
+
+ delay_from = delay.getAttr('from')
+ if from_ is not None:
+ if delay_from != from_:
+ continue
+ if not_from is not None:
+ if delay_from in not_from:
+ continue
+
+ timestamp = parse_datetime(stamp, check_utc=True,
epoch=epoch, convert=convert)
if timestamp is None:
- log.warning('Invalid timestamp received: %s', delay)
+ log.warning('Invalid timestamp received: %s', stamp)
log.warning(stanza)
+ continue
- return timestamp
+ return timestamp
# XEP-0066: Out of Band Data
=====================================
test/no_gui/unit/test_helpers.py
=====================================
@@ -0,0 +1,30 @@
+import unittest
+
+import nbxmpp
+
+from gajim.common.modules.misc import parse_delay
+
+class TestHelpers(unittest.TestCase):
+
+ def test_parse_delay(self):
+
+ node = """
+ <message>
+ <delay xmlns='urn:xmpp:delay' from='capulet.com' stamp='2002-09-10T23:08:25Z' />
+ <delay xmlns='urn:xmpp:delay' from='romeo.com' stamp='2010-09-10T23:08:25Z' />
+ <delay xmlns='urn:xmpp:delay' stamp='2015-09-10T23:08:25Z' />
+ </message>
+ """
+ message = nbxmpp.Node(node=node)
+
+ timestamp = parse_delay(message)
+ self.assertEqual(timestamp, 1031699305.0)
+
+ timestamp = parse_delay(message, from_='capulet.com')
+ self.assertEqual(timestamp, 1031699305.0)
+
+ timestamp = parse_delay(message, from_='romeo.com')
+ self.assertEqual(timestamp, 1284160105.0)
+
+ timestamp = parse_delay(message, not_from=['romeo.com'])
+ self.assertEqual(timestamp, 1031699305.0)
\ No newline at end of file
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/b2ecc14cae3500507dda2361a437d8aa6…
--
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/b2ecc14cae3500507dda2361a437d8aa6…
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:
0aed4447 by Philipp Hörist at 2018-12-04T19:25:22Z
Add new namespace
- - - - -
1 changed file:
- nbxmpp/protocol.py
Changes:
=====================================
nbxmpp/protocol.py
=====================================
@@ -188,6 +188,7 @@ NS_HASHES_SHA3_512 = 'urn:xmpp:hash-function-text-names:sha3-512'
NS_HASHES_BLAKE2B_256 = 'urn:xmpp:hash-function-text-names:id-blake2b256'
NS_HASHES_BLAKE2B_512 = 'urn:xmpp:hash-function-text-names:id-blake2b512'
NS_OPENPGP = 'urn:xmpp:openpgp:0'
+NS_BOOKMARK_CONVERSION = 'urn:xmpp:bookmarks-conversion:0'
#xmpp_stream_error_conditions = '''
#bad-format -- -- -- The entity has sent XML that cannot be processed.
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/0aed44470bac25c42e85de268c…
--
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/commit/0aed44470bac25c42e85de268c…
You're receiving this email because of your account on dev.gajim.org.
Philipp Hörist pushed to branch master at gajim / gajim
Commits:
86bbdd21 by Philipp Hörist at 2018-12-04T18:43:13Z
Encode resource with correct profile
Fixes #9465
- - - - -
c2e2dd9a by Philipp Hörist at 2018-12-04T18:43:55Z
Fix MUC nick change
- - - - -
2 changed files:
- gajim/common/helpers.py
- gajim/groupchat_control.py
Changes:
=====================================
gajim/common/helpers.py
=====================================
@@ -154,7 +154,7 @@ def parse_resource(resource):
"""
if resource:
try:
- return resource.encode('Nickname').decode('utf-8')
+ return resource.encode('OpaqueString').decode('utf-8')
except UnicodeError:
raise InvalidFormat('Invalid character in resource.')
=====================================
gajim/groupchat_control.py
=====================================
@@ -1812,7 +1812,7 @@ class GroupchatControl(ChatControlBase):
elif '303' in obj.status_code: # Someone changed their nick
if obj.new_nick == self.new_nick or obj.nick == self.nick:
# We changed our nick
- self.change_nick(obj.new_nick)
+ self._change_nick(obj.new_nick)
self.new_nick = ''
s = _('You are now known as %s') % self.nick
else:
@@ -1882,7 +1882,7 @@ class GroupchatControl(ChatControlBase):
if not iter_:
if '210' in obj.status_code:
# Server changed our nick
- self.change_nick(obj.nick)
+ self._change_nick(obj.nick)
s = _('You are now known as %s') % nick
self.print_conversation(s, 'info', graphics=False)
iter_ = self.add_contact_to_roster(obj.nick, obj.show, role,
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/932377f533a97d25aabf210b4fe52fb0a…
--
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/932377f533a97d25aabf210b4fe52fb0a…
You're receiving this email because of your account on dev.gajim.org.