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

View file

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