Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Link Mauve
python-nbxmpp
Commits
5d2bcd74
Commit
5d2bcd74
authored
Apr 11, 2020
by
Philipp Hörist
Browse files
Smacks: Copy stanza before adding it to the queue
parent
828ee78b
Changes
1
Hide whitespace changes
Inline
Side-by-side
nbxmpp/smacks.py
View file @
5d2bcd74
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment