comparison sat/plugins/plugin_xep_0384.py @ 3944:748094d5a74d

plugin XEP-0374, XEP-0384: handle cases where "to" is not set in <message> for `feedback_jid`
author Goffi <goffi@goffi.org>
date Sat, 15 Oct 2022 20:38:33 +0200
parents 8dc6a4cfda4b
children f461f11ea176
comparison
equal deleted inserted replaced
3943:8dc6a4cfda4b 3944:748094d5a74d
72 72
73 __all__ = [ # pylint: disable=unused-variable 73 __all__ = [ # pylint: disable=unused-variable
74 "PLUGIN_INFO", 74 "PLUGIN_INFO",
75 "OMEMO" 75 "OMEMO"
76 ] 76 ]
77
78 77
79 log = cast(Logger, getLogger(__name__)) # type: ignore[no-untyped-call] 78 log = cast(Logger, getLogger(__name__)) # type: ignore[no-untyped-call]
80 79
81 80
82 string_to_domish = cast(Callable[[str], domish.Element], xml_tools.ElementParser()) 81 string_to_domish = cast(Callable[[str], domish.Element], xml_tools.ElementParser())
1570 # I'm not sure why this check is required, this code is copied from the old 1569 # I'm not sure why this check is required, this code is copied from the old
1571 # plugin. 1570 # plugin.
1572 if sender_jid.userhostJID() == client.jid.userhostJID(): 1571 if sender_jid.userhostJID() == client.jid.userhostJID():
1573 # TODO: I've seen this cause an exception "builtins.KeyError: 'to'", seems 1572 # TODO: I've seen this cause an exception "builtins.KeyError: 'to'", seems
1574 # like "to" isn't always set. 1573 # like "to" isn't always set.
1575 feedback_jid = jid.JID(message_elt["to"]) 1574 try:
1575 feedback_jid = jid.JID(message_elt["to"])
1576 except KeyError:
1577 feedback_jid = client.server_jid
1576 else: 1578 else:
1577 feedback_jid = sender_jid 1579 feedback_jid = sender_jid
1578 1580
1579 sender_bare_jid = sender_jid.userhost() 1581 sender_bare_jid = sender_jid.userhost()
1580 1582