add /ping command in groupchat to ping occupants

This commit is contained in:
Yann Leboulanger 2014-08-22 15:44:07 +02:00
parent ae8c6a644e
commit 1b6550a0e3
4 changed files with 30 additions and 7 deletions

View file

@ -211,11 +211,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return return
self.print_conversation(_('Ping?'), 'status') self.print_conversation(_('Ping?'), 'status')
def _nec_ping_reply(self, obj):
if self.contact != obj.contact:
return
self.print_conversation(_('Pong! (%s s.)') % obj.seconds, 'status')
def _nec_ping_error(self, obj): def _nec_ping_error(self, obj):
if self.contact != obj.contact: if self.contact != obj.contact:
return return
@ -2884,6 +2879,15 @@ class ChatControl(ChatControlBase):
return return
self.update_ui() self.update_ui()
def _nec_ping_reply(self, obj):
if obj.control:
if obj.control != self:
return
else:
if self.contact != obj.contact:
return
self.print_conversation(_('Pong! (%s s.)') % obj.seconds, 'status')
def set_control_active(self, state): def set_control_active(self, state):
ChatControlBase.set_control_active(self, state) ChatControlBase.set_control_active(self, state)
# send chatstate inactive to the one we're leaving # send chatstate inactive to the one we're leaving

View file

@ -410,3 +410,12 @@ class StandardGroupChatCommands(CommandContainer):
@doc(_("Allow an occupant to send you public or private messages")) @doc(_("Allow an occupant to send you public or private messages"))
def unblock(self, who): def unblock(self, who):
self.on_unblock(None, who) self.on_unblock(None, who)
@command
@doc(_("Send a ping to the contact"))
def ping(self, nick):
if self.account == gajim.ZEROCONF_ACC_NAME:
raise CommandError(_('Command is not supported for zeroconf accounts'))
gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
gajim.connections[self.account].sendPing(gc_c, self)

View file

@ -1569,10 +1569,11 @@ class Connection(CommonConnection, ConnectionHandlers):
assert id_ == self.awaiting_xmpp_ping_id assert id_ == self.awaiting_xmpp_ping_id
self.awaiting_xmpp_ping_id = None self.awaiting_xmpp_ping_id = None
def sendPing(self, pingTo=None): def sendPing(self, pingTo=None, control=None):
""" """
Send XMPP Ping (XEP-0199) request. If pingTo is not set, ping is sent to Send XMPP Ping (XEP-0199) request. If pingTo is not set, ping is sent to
server to detect connection failure at application level server to detect connection failure at application level
If control is set, display result there
""" """
if not gajim.account_is_connected(self.name): if not gajim.account_is_connected(self.name):
return return
@ -1595,7 +1596,7 @@ class Connection(CommonConnection, ConnectionHandlers):
return return
timeDiff = round(timePong - timePing, 2) timeDiff = round(timePong - timePing, 2)
gajim.nec.push_incoming_event(PingReplyEvent(None, conn=self, gajim.nec.push_incoming_event(PingReplyEvent(None, conn=self,
contact=pingTo, seconds=timeDiff)) contact=pingTo, seconds=timeDiff, control=control))
if pingTo: if pingTo:
timePing = time_time() timePing = time_time()
self.connection.SendAndCallForResponse(iq, _on_response) self.connection.SendAndCallForResponse(iq, _on_response)

View file

@ -1374,6 +1374,15 @@ class GroupchatControl(ChatControlBase):
obj.xhtml, self.session, msg_id=obj.msg_id, obj.xhtml, self.session, msg_id=obj.msg_id,
encrypted=obj.encrypted, displaymarking=obj.displaymarking) encrypted=obj.encrypted, displaymarking=obj.displaymarking)
def _nec_ping_reply(self, obj):
if obj.control:
if obj.control != self:
return
else:
if self.contact != obj.contact:
return
self.print_conversation(_('Pong! (%s s.)') % obj.seconds)
def got_connected(self): def got_connected(self):
# Make autorejoin stop. # Make autorejoin stop.
if self.autorejoin: if self.autorejoin: