core (xmpp/messages): Optimize and avoir exception on parse_message:
- When we want to disco a bare JID, disco its server instead, to avoid many uncached requests. In most case, the server disco is enough to discover JID origin. - Avoid exception on `exceptions.ExternalRequestError`, print a warning instead.
This commit is contained in:
parent
5dced35020
commit
46440d8409
1 changed files with 29 additions and 17 deletions
|
|
@ -1649,24 +1649,36 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
|||
|
||||
# origin
|
||||
if not from_jid_bare in (client.jid.userhostJID(), client.server_jid):
|
||||
disco_infos = await G.host.memory.disco.get_infos(client, from_jid_bare)
|
||||
if from_jid_bare.user:
|
||||
domain_disco_infos = await G.host.memory.disco.get_infos(
|
||||
client, jid.JID(from_jid_bare.host)
|
||||
try:
|
||||
# For bare JIDs, query the server instead: bare jids are not cached by
|
||||
# XEP-0115, so we'll have an actual disco request each time. On the other
|
||||
# hand, server disco is cached after first request, and should gives us
|
||||
# the gateway/origin info we need.
|
||||
# FIXME: Check if this cause trouble in practice.
|
||||
query_jid = from_jid if from_jid.resource else jid.JID(from_jid.host)
|
||||
disco_infos = await G.host.memory.disco.get_infos(client, query_jid)
|
||||
if from_jid_bare.user:
|
||||
domain_disco_infos = await G.host.memory.disco.get_infos(
|
||||
client, jid.JID(from_jid_bare.host)
|
||||
)
|
||||
else:
|
||||
domain_disco_infos = disco_infos
|
||||
if ("client", "bot") in disco_infos.identities:
|
||||
extra["is-bot"] = True
|
||||
for (
|
||||
category,
|
||||
type_,
|
||||
), identities_map in domain_disco_infos.identities.items():
|
||||
for lang, identity in identities_map.items():
|
||||
if category == "gateway":
|
||||
extra["origin"] = identity.type
|
||||
if identity.name:
|
||||
extra["origin_name"] = identity.name
|
||||
except exceptions.ExternalRequestError:
|
||||
log.warning(
|
||||
f"Disco query failed for {from_jid.full()}, skipping identity "
|
||||
"detection"
|
||||
)
|
||||
else:
|
||||
domain_disco_infos = disco_infos
|
||||
if ("client", "bot") in disco_infos.identities:
|
||||
extra["is-bot"] = True
|
||||
for (
|
||||
category,
|
||||
type_,
|
||||
), identities_map in domain_disco_infos.identities.items():
|
||||
for lang, identity in identities_map.items():
|
||||
if category == "gateway":
|
||||
extra["origin"] = identity.type
|
||||
if identity.name:
|
||||
extra["origin_name"] = identity.name
|
||||
|
||||
# message
|
||||
for e in message_elt.elements(C.NS_CLIENT, "body"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue