summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-04-19 23:17:10 +0200
committermathieui <mathieui@mathieui.net>2021-04-19 23:17:10 +0200
commit8828a5b99dcf9134b200efe1bc4a60e2f0d350bb (patch)
treefd93ce5100124c6df544c908adb90b9b056d5bee
parent0d52344a31d67b9899b551cc1ef551def4b98eea (diff)
downloadslixmpp-8828a5b99dcf9134b200efe1bc4a60e2f0d350bb.tar.gz
slixmpp-8828a5b99dcf9134b200efe1bc4a60e2f0d350bb.tar.bz2
slixmpp-8828a5b99dcf9134b200efe1bc4a60e2f0d350bb.tar.xz
slixmpp-8828a5b99dcf9134b200efe1bc4a60e2f0d350bb.zip
XEP-0115: add a broadcast parameter to update_caps
and do not send a presence after updating if it is false
-rw-r--r--slixmpp/plugins/xep_0115/caps.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/slixmpp/plugins/xep_0115/caps.py b/slixmpp/plugins/xep_0115/caps.py
index e469f6ff..c52d1166 100644
--- a/slixmpp/plugins/xep_0115/caps.py
+++ b/slixmpp/plugins/xep_0115/caps.py
@@ -8,6 +8,7 @@ import hashlib
import base64
from asyncio import Future
+from typing import Optional
from slixmpp import __version__
from slixmpp.stanza import StreamFeatures, Presence, Iq
@@ -15,10 +16,10 @@ from slixmpp.xmlstream import register_stanza_plugin, JID
from slixmpp.xmlstream.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.util import MemoryCache
-from slixmpp import asyncio
-from slixmpp.exceptions import XMPPError, IqError, IqTimeout
+from slixmpp.exceptions import XMPPError
from slixmpp.plugins import BasePlugin
from slixmpp.plugins.xep_0115 import stanza, StaticCaps
+from slixmpp.types import OptJidStr
log = logging.getLogger(__name__)
@@ -285,7 +286,17 @@ class XEP_0115(BasePlugin):
binary = hash(S.encode('utf8')).digest()
return base64.b64encode(binary).decode('utf-8')
- async def update_caps(self, jid=None, node=None, preserve=False):
+ async def update_caps(self, jid: OptJidStr = None,
+ node: Optional[str] = None,
+ preserve: bool = False,
+ broadcast: bool = True):
+ """Update caps for a local JID based on current data.
+
+ :param jid: JID whose info to update
+ :param node: Node to fetch info from
+ :param broadcast: Send a presence after updating.
+ :param preserve: Send presence only to contacts found in the roster.
+ """
try:
info = await self.xmpp['xep_0030'].get_info(jid, node, local=True)
if isinstance(info, Iq):
@@ -299,7 +310,7 @@ class XEP_0115(BasePlugin):
await self.cache_caps(ver, info)
await self.assign_verstring(jid, ver)
- if self.xmpp.sessionstarted and self.broadcast:
+ if broadcast and self.xmpp.sessionstarted and self.broadcast:
if self.xmpp.is_component or preserve:
for contact in self.xmpp.roster[jid]:
self.xmpp.roster[jid][contact].send_last_presence()