Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
gajim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
194
Issues
194
List
Boards
Labels
Service Desk
Milestones
Merge Requests
20
Merge Requests
20
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gajim
gajim
Commits
a7f98f7c
Commit
a7f98f7c
authored
Oct 26, 2020
by
Philipp Hörist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ping: Refactor module
parent
9add1bc0
Pipeline
#6685
failed with stages
in 38 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
63 deletions
+41
-63
gajim/chat_control.py
gajim/chat_control.py
+2
-1
gajim/command_system/implementation/standard.py
gajim/command_system/implementation/standard.py
+2
-0
gajim/common/modules/ping.py
gajim/common/modules/ping.py
+32
-61
gajim/groupchat_control.py
gajim/groupchat_control.py
+5
-1
No files found.
gajim/chat_control.py
View file @
a7f98f7c
...
...
@@ -651,6 +651,7 @@ def _on_zeroconf_error(self, event):
def
_on_update_roster_avatar
(
self
,
obj
):
self
.
_update_avatar
()
@
event_filter
([
'account'
])
def
_nec_ping
(
self
,
event
):
if
self
.
contact
!=
event
.
contact
:
return
...
...
@@ -660,7 +661,7 @@ def _nec_ping(self, event):
self
.
add_info_message
(
_
(
'Pong! (%s seconds)'
)
%
event
.
seconds
)
elif
event
.
name
==
'ping-error'
:
self
.
add_info_message
(
_
(
'Error.'
)
)
self
.
add_info_message
(
event
.
error
)
def
change_resource
(
self
,
resource
):
old_full_jid
=
self
.
get_full_jid
()
...
...
gajim/command_system/implementation/standard.py
View file @
a7f98f7c
...
...
@@ -419,4 +419,6 @@ def ping(self, nick):
raise
CommandError
(
_
(
'Command is not supported for zeroconf accounts'
))
gc_c
=
app
.
contacts
.
get_gc_contact
(
self
.
account
,
self
.
room_jid
,
nick
)
if
gc_c
is
None
:
raise
CommandError
(
_
(
"Unknown nickname"
))
app
.
connections
[
self
.
account
].
get_module
(
'Ping'
).
send_ping
(
gc_c
)
gajim/common/modules/ping.py
View file @
a7f98f7c
...
...
@@ -19,91 +19,62 @@
import
time
import
nbxmpp
from
nbxmpp.namespaces
import
Namespace
from
nbxmpp.structs
import
StanzaHandler
from
nbxmpp.errors
import
is_error
from
gajim.common
import
app
from
gajim.common.nec
import
Network
Incoming
Event
from
gajim.common.nec
import
NetworkEvent
from
gajim.common.types
import
ConnectionT
from
gajim.common.types
import
ContactsT
from
gajim.common.modules.base
import
BaseModule
from
gajim.common.modules.util
import
as_task
class
Ping
(
BaseModule
):
_nbxmpp_extends
=
'Ping'
_nbxmpp_methods
=
[
'ping'
,
]
def
__init__
(
self
,
con
:
ConnectionT
)
->
None
:
BaseModule
.
__init__
(
self
,
con
)
self
.
handlers
=
[
StanzaHandler
(
name
=
'iq'
,
callback
=
self
.
_answer_request
,
typ
=
'get'
,
ns
=
Namespace
.
PING
),
]
@
staticmethod
def
_get_ping_iq
(
to
:
str
)
->
nbxmpp
.
Iq
:
iq
=
nbxmpp
.
Iq
(
'get'
,
to
=
to
)
iq
.
addChild
(
name
=
'ping'
,
namespace
=
Namespace
.
PING
)
return
iq
self
.
handlers
=
[]
@
as_task
def
send_ping
(
self
,
contact
:
ContactsT
)
->
None
:
_task
=
yield
if
not
app
.
account_is_available
(
self
.
_account
):
return
to
=
contact
.
get_full_jid
()
iq
=
self
.
_get_ping_iq
(
to
)
jid
=
contact
.
get_full_jid
()
self
.
_log
.
info
(
'Send ping to %s'
,
to
)
self
.
_log
.
info
(
'Send ping to %s'
,
jid
)
self
.
_con
.
connection
.
SendAndCallForResponse
(
iq
,
self
.
_pong_received
,
{
'ping_time'
:
time
.
time
()
,
'contact'
:
contact
}
)
app
.
nec
.
push_incoming_event
(
NetworkEvent
(
'ping-sent'
,
account
=
self
.
_account
,
contact
=
contact
)
)
app
.
nec
.
push_incoming_event
(
PingSentEvent
(
None
,
conn
=
self
.
_con
,
contact
=
contact
))
ping_time
=
time
.
time
()
def
_pong_received
(
self
,
_nbxmpp_client
:
Any
,
stanza
:
nbxmpp
.
Iq
,
ping_time
:
int
,
contact
:
ContactsT
)
->
None
:
if
not
nbxmpp
.
isResultNode
(
stanza
):
self
.
_log
.
info
(
'Error: %s'
,
stanza
.
getError
())
app
.
nec
.
push_incoming_event
(
PingErrorEvent
(
None
,
conn
=
self
.
_con
,
contact
=
contact
))
response
=
yield
self
.
ping
(
jid
,
timeout
=
10
)
if
is_error
(
response
):
app
.
nec
.
push_incoming_event
(
NetworkEvent
(
'ping-error'
,
account
=
self
.
_account
,
contact
=
contact
,
error
=
str
(
response
)))
return
diff
=
round
(
time
.
time
()
-
ping_time
,
2
)
self
.
_log
.
info
(
'Received pong from %s after %s seconds'
,
stanza
.
getFrom
(),
diff
)
app
.
nec
.
push_incoming_event
(
PingReplyEvent
(
None
,
conn
=
self
.
_con
,
contact
=
contact
,
seconds
=
diff
))
def
_answer_request
(
self
,
_con
:
ConnectionT
,
stanza
:
nbxmpp
.
Iq
,
_properties
:
Any
)
->
None
:
iq
=
stanza
.
buildReply
(
'result'
)
ping
=
iq
.
getTag
(
'ping'
)
if
ping
is
not
None
:
iq
.
delChild
(
ping
)
self
.
_con
.
connection
.
send
(
iq
)
self
.
_log
.
info
(
'Send pong to %s'
,
stanza
.
getFrom
())
raise
nbxmpp
.
NodeProcessed
class
PingSentEvent
(
NetworkIncomingEvent
):
name
=
'ping-sent'
class
PingReplyEvent
(
NetworkIncomingEvent
):
name
=
'ping-reply'
response
.
jid
,
diff
)
class
PingErrorEvent
(
NetworkIncomingEvent
):
name
=
'ping-error'
app
.
nec
.
push_incoming_event
(
NetworkEvent
(
'ping-reply'
,
account
=
self
.
_account
,
contact
=
contact
,
seconds
=
diff
))
def
get_instance
(
*
args
:
Any
,
**
kwargs
:
Any
)
->
Tuple
[
Ping
,
str
]:
...
...
gajim/groupchat_control.py
View file @
a7f98f7c
...
...
@@ -1070,7 +1070,11 @@ def _nec_our_status(self, event):
if
self
.
parent_win
:
self
.
parent_win
.
redraw_tab
(
self
)
@
event_filter
([
'account'
])
def
_nec_ping
(
self
,
event
):
if
not
event
.
contact
.
is_groupchat
:
return
if
self
.
contact
.
jid
!=
event
.
contact
.
room_jid
:
return
...
...
@@ -1082,7 +1086,7 @@ def _nec_ping(self, event):
_
(
'Pong! (%(nick)s %(delay)s s.)'
)
%
{
'nick'
:
nick
,
'delay'
:
event
.
seconds
})
elif
event
.
name
==
'ping-error'
:
self
.
add_info_message
(
_
(
'Error.'
)
)
self
.
add_info_message
(
event
.
error
)
@
property
def
is_connected
(
self
)
->
bool
:
...
...
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