XEP-0108: Fix return values and typing

This commit is contained in:
mathieui 2021-02-03 22:23:44 +01:00
parent f2878e1764
commit f6761e513d
2 changed files with 23 additions and 29 deletions

View File

@ -1,10 +1,7 @@
""" # Slixmpp: The Slick XMPP Library
Slixmpp: The Slick XMPP Library # Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout # This file is part of Slixmpp.
This file is part of Slixmpp. # See the file LICENSE for copying permission.
See the file LICENSE for copying permission.
"""
from slixmpp.xmlstream import ElementBase, ET from slixmpp.xmlstream import ElementBase, ET

View File

@ -1,13 +1,12 @@
""" # Slixmpp: The Slick XMPP Library
Slixmpp: The Slick XMPP Library # Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout
Copyright (C) 2011 Nathanael C. Fritz, Lance J.T. Stout # This file is part of Slixmpp.
This file is part of Slixmpp. # See the file LICENSE for copying permission.
See the file LICENSE for copying permission.
"""
import logging import logging
from asyncio import Future
from typing import Optional
from slixmpp.plugins.base import BasePlugin from slixmpp.plugins.base import BasePlugin
from slixmpp.plugins.xep_0108 import stanza, UserActivity from slixmpp.plugins.xep_0108 import stanza, UserActivity
@ -33,9 +32,8 @@ class XEP_0108(BasePlugin):
def session_bind(self, jid): def session_bind(self, jid):
self.xmpp['xep_0163'].register_pep('user_activity', UserActivity) self.xmpp['xep_0163'].register_pep('user_activity', UserActivity)
def publish_activity(self, general, specific=None, text=None, def publish_activity(self, general: str, specific: Optional[str] = None,
options=None, ifrom=None, callback=None, text: Optional[str] = None, **pubsubkwargs) -> Future:
timeout=None, timeout_callback=None):
""" """
Publish the user's current activity. Publish the user's current activity.
@ -44,24 +42,23 @@ class XEP_0108(BasePlugin):
of the general category. of the general category.
:param text: Optional natural-language description or reason :param text: Optional natural-language description or reason
for the activity. for the activity.
:param options: Optional form of publish options.
""" """
activity = UserActivity() activity = UserActivity()
activity['value'] = (general, specific) activity['value'] = (general, specific)
activity['text'] = text activity['text'] = text
self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace, return self.xmpp['xep_0163'].publish(
options=options, ifrom=ifrom, activity,
callback=callback, node=UserActivity.namespace,
timeout=timeout, **pubsubkwargs
timeout_callback=timeout_callback) )
def stop(self, ifrom=None, callback=None, timeout=None, def stop(self, **pubsubkwargs) -> Future:
timeout_callback=None):
""" """
Clear existing user activity information to stop notifications. Clear existing user activity information to stop notifications.
""" """
activity = UserActivity() activity = UserActivity()
self.xmpp['xep_0163'].publish(activity, node=UserActivity.namespace, return self.xmpp['xep_0163'].publish(
ifrom=ifrom, callback=callback, activity,
timeout=timeout, node=UserActivity.namespace,
timeout_callback=timeout_callback) **pubsubkwargs
)