Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits: 828ee78b by lovetox at 2020-04-11T17:35:39+02:00 Websocket: Pass stanza on data-sent
- - - - - 5d2bcd74 by lovetox at 2020-04-11T22:00:24+02:00 Smacks: Copy stanza before adding it to the queue
- - - - - b169eb1a by lovetox at 2020-04-11T22:03:56+02:00 EntityCaps: Add missing node on disco info reply
- - - - -
3 changed files:
- nbxmpp/modules/entity_caps.py - nbxmpp/smacks.py - nbxmpp/websocket.py
Changes:
===================================== nbxmpp/modules/entity_caps.py ===================================== @@ -57,6 +57,7 @@ class EntityCaps(BaseModule): return
iq = stanza.buildReply('result') + iq.setQuerynode(self._node) query = iq.getQuery() for identity in self._caps.identities: query.addChild(node=identity.get_node())
===================================== nbxmpp/smacks.py ===================================== @@ -126,14 +126,13 @@ class Smacks: # We did not yet sent 'enable' so the server # will not count our stanzas return - if (stanza.getName() == 'message' and - stanza.getType() in ('chat', 'groupchat')): - timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) - attrs = {'stamp': timestamp} - if stanza.getType() != 'groupchat': - # Dont leak our JID to Groupchats - attrs['from'] = str(self._client.get_bound_jid()) - stanza.addChild('delay', namespace=NS_DELAY2, attrs=attrs) + + # Make a full copy so we dont run into problems when + # the stanza is modified after sending for some reason + stanza = type(stanza)(node=str(stanza)) + + self._add_delay(stanza) + self._uqueue.append(stanza) self._log.debug('OUT, %s', stanza.getName()) self._out_h += 1 @@ -144,6 +143,22 @@ class Smacks: if (self._in_h - self._acked_h) > 100: self._send_ack()
+ def _add_delay(self, stanza): + if stanza.getName() != 'message': + return + + if stanza.getType() not in ('chat', 'groupchat'): + return + + timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) + attrs = {'stamp': timestamp} + + if stanza.getType() != 'groupchat': + # Dont leak our JID to Groupchats + attrs['from'] = str(self._client.get_bound_jid()) + + stanza.addChild('delay', namespace=NS_DELAY2, attrs=attrs) + def _resend_queue(self): """ Resends unsent stanzas when a new session is established.
===================================== nbxmpp/websocket.py ===================================== @@ -139,7 +139,7 @@ class WebsocketConnection(Connection): data = str(stanza) self._websocket.send_text(data) self._log_stanza(data, received=False) - self.notify('data-sent', data) + self.notify('data-sent', stanza)
def disconnect(self): if self._state == TCPState.CONNECTING:
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/-/compare/852b29d8be3816ea8dbf8c54...