plugin XEP-0092: use client instead of profile_key in version_get
This commit is contained in:
parent
ce8623dc97
commit
9c41493ff9
1 changed files with 24 additions and 16 deletions
|
|
@ -17,12 +17,16 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from sat.core.constants import Const as C
|
||||
from twisted.internet import reactor, defer
|
||||
from typing import Tuple
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from wokkel import compat
|
||||
|
||||
from sat.core import exceptions
|
||||
from sat.core.constants import Const as C
|
||||
from sat.core.core_types import SatXMPPEntity
|
||||
from sat.core.i18n import _
|
||||
from sat.core.log import getLogger
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
|
@ -65,22 +69,26 @@ class XEP_0092(object):
|
|||
name, version, os = data
|
||||
return (name or "", version or "", os or "")
|
||||
|
||||
d = self.version_get(jid.JID(entity_jid_s), profile_key)
|
||||
client = self.host.get_client(profile_key)
|
||||
d = self.version_get(client, jid.JID(entity_jid_s))
|
||||
d.addCallback(prepare_for_bridge)
|
||||
return d
|
||||
|
||||
def version_get(self, jid_, profile_key=C.PROF_KEY_NONE):
|
||||
""" Ask version of the client that jid_ is running
|
||||
@param jid_: jid from who we want to know client's version
|
||||
@param profile_key: %(doc_profile_key)s
|
||||
@return (tuple): a defered which fire a tuple with the following data (None if not available):
|
||||
- name: Natural language name of the software
|
||||
- version: specific version of the software
|
||||
- os: operating system of the queried entity
|
||||
"""
|
||||
client = self.host.get_client(profile_key)
|
||||
def version_get(
|
||||
self,
|
||||
client: SatXMPPEntity,
|
||||
jid_: jid.JID,
|
||||
) -> Tuple[str, str, str]:
|
||||
"""Ask version of the client that jid_ is running
|
||||
|
||||
def version_get(__):
|
||||
@param jid_: jid from who we want to know client's version
|
||||
@return: a defered which fire a tuple with the following data (None if not available):
|
||||
- name: Natural language name of the software
|
||||
- version: specific version of the software
|
||||
- os: operating system of the queried entity
|
||||
"""
|
||||
|
||||
def do_version_get(__):
|
||||
iq_elt = compat.IQ(client.xmlstream, "get")
|
||||
iq_elt["to"] = jid_.full()
|
||||
iq_elt.addElement("query", NS_VERSION)
|
||||
|
|
@ -89,7 +97,7 @@ class XEP_0092(object):
|
|||
return d
|
||||
|
||||
d = self.host.check_feature(client, NS_VERSION, jid_)
|
||||
d.addCallback(version_get)
|
||||
d.addCallback(do_version_get)
|
||||
reactor.callLater(
|
||||
TIMEOUT, d.cancel
|
||||
) # XXX: timeout needed because some clients don't answer the IQ
|
||||
|
|
@ -111,7 +119,7 @@ class XEP_0092(object):
|
|||
return tuple(ret)
|
||||
|
||||
def _whois(self, client, whois_msg, mess_data, target_jid):
|
||||
""" Add software/OS information to whois """
|
||||
"""Add software/OS information to whois"""
|
||||
|
||||
def version_cb(version_data):
|
||||
name, version, os = version_data
|
||||
|
|
@ -129,6 +137,6 @@ class XEP_0092(object):
|
|||
else:
|
||||
whois_msg.append(_("Client software version request timeout"))
|
||||
|
||||
d = self.version_get(target_jid, client.profile)
|
||||
d = self.version_get(client, target_jid)
|
||||
d.addCallbacks(version_cb, version_eb)
|
||||
return d
|
||||
|
|
|
|||
Loading…
Reference in a new issue