Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Sebastiaan Lokhorst
gajim
Commits
7b9278ae
Commit
7b9278ae
authored
Oct 14, 2019
by
Philipp Hörist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chatstate: Use StanzaHandler instead of delegate()
parent
1af5612d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
37 deletions
+22
-37
gajim/common/modules/chatstates.py
gajim/common/modules/chatstates.py
+22
-25
gajim/common/modules/message.py
gajim/common/modules/message.py
+0
-5
gajim/common/zeroconf/connection_handlers_zeroconf.py
gajim/common/zeroconf/connection_handlers_zeroconf.py
+0
-7
No files found.
gajim/common/modules/chatstates.py
View file @
7b9278ae
...
...
@@ -51,17 +51,6 @@ def ensure_enabled(func):
return
func_wrapper
def
parse_chatstate
(
stanza
:
nbxmpp
.
Message
)
->
Optional
[
str
]:
if
stanza
.
getTag
(
'delay'
,
namespace
=
nbxmpp
.
NS_DELAY2
)
is
not
None
:
return
None
children
=
stanza
.
getChildren
()
for
child
in
children
:
if
child
.
getNamespace
()
==
nbxmpp
.
NS_CHATSTATES
:
return
child
.
getName
()
return
None
class
Chatstate
(
BaseModule
):
def
__init__
(
self
,
con
:
ConnectionT
)
->
None
:
BaseModule
.
__init__
(
self
,
con
)
...
...
@@ -69,6 +58,10 @@ class Chatstate(BaseModule):
self
.
handlers
=
[
StanzaHandler
(
name
=
'presence'
,
callback
=
self
.
_presence_received
),
StanzaHandler
(
name
=
'message'
,
callback
=
self
.
_process_chatstate
,
ns
=
nbxmpp
.
NS_CHATSTATES
,
priority
=
46
),
]
# Our current chatstate with a specific contact
...
...
@@ -144,35 +137,39 @@ class Chatstate(BaseModule):
account
=
self
.
_account
,
contact
=
contact
))
def
delegate
(
self
,
event
:
Any
)
->
None
:
if
self
.
_con
.
get_own_jid
().
bareMatch
(
event
.
jid
)
or
event
.
sent
:
# Dont show chatstates from our own resources
def
_process_chatstate
(
self
,
_con
,
_stanza
,
properties
):
if
not
properties
.
has_chatstate
:
return
if
event
.
mtype
==
'groupchat'
:
# Not implemented yet
if
(
properties
.
is_self_message
or
properties
.
type
.
is_groupchat
or
properties
.
is_carbon_message
and
properties
.
carbon
.
is_sent
):
if
properties
.
chatstate
in
(
'inactive'
,
'gone'
,
'composing'
,
'paused'
):
raise
nbxmpp
.
NodeProcessed
return
chatstate
=
parse_chatstate
(
event
.
stanza
)
if
chatstate
is
None
:
return
if
event
.
muc_pm
:
if
properties
.
is_muc_pm
:
contact
=
app
.
contacts
.
get_gc_contact
(
self
.
_account
,
event
.
jid
,
event
.
resource
)
self
.
_account
,
properties
.
jid
.
getBare
(),
properties
.
jid
.
getResource
())
else
:
contact
=
app
.
contacts
.
get_contact_from_full_jid
(
self
.
_account
,
event
.
f
jid
)
self
.
_account
,
str
(
properties
.
jid
)
)
if
contact
is
None
:
return
contact
.
chatstate
=
chatstate
self
.
_log
.
info
(
'Recv: %-10s - %s'
,
chatstate
,
event
.
f
jid
)
contact
.
chatstate
=
properties
.
chatstate
self
.
_log
.
info
(
'Recv: %-10s - %s'
,
properties
.
chatstate
,
properties
.
jid
)
app
.
nec
.
push_outgoing_event
(
NetworkEvent
(
'chatstate-received'
,
account
=
self
.
_account
,
contact
=
contact
))
if
properties
.
chatstate
in
(
'inactive'
,
'gone'
,
'composing'
,
'paused'
):
raise
nbxmpp
.
NodeProcessed
@
ensure_enabled
def
_check_last_interaction
(
self
)
->
GLib
.
SOURCE_CONTINUE
:
now
=
time
.
time
()
...
...
gajim/common/modules/message.py
View file @
7b9278ae
...
...
@@ -198,11 +198,6 @@ class Message(BaseModule):
self
.
_on_message_decrypted
(
event
)
def
_on_message_decrypted
(
self
,
event
):
try
:
self
.
_con
.
get_module
(
'Chatstate'
).
delegate
(
event
)
except
nbxmpp
.
NodeProcessed
:
return
groupchat
=
event
.
mtype
==
'groupchat'
event_attr
=
{
...
...
gajim/common/zeroconf/connection_handlers_zeroconf.py
View file @
7b9278ae
...
...
@@ -22,8 +22,6 @@
import
time
import
logging
import
nbxmpp
from
gajim.common
import
app
from
gajim.common
import
connection_handlers
...
...
@@ -135,11 +133,6 @@ class ConnectionHandlersZeroconf(connection_handlers.ConnectionHandlersBase):
self
.
_on_message_decrypted
(
event
)
def
_on_message_decrypted
(
self
,
event
):
try
:
self
.
get_module
(
'Chatstate'
).
delegate
(
event
)
except
nbxmpp
.
NodeProcessed
:
return
event_attr
=
{
'popup'
:
False
,
'msg_log_id'
:
None
,
...
...
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