plugin XEP-0163: type hints
This commit is contained in:
parent
502d9aad19
commit
dce577bf3a
1 changed files with 10 additions and 5 deletions
|
|
@ -17,7 +17,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import Optional, Callable
|
||||
from typing import TYPE_CHECKING, Callable, cast
|
||||
|
||||
from twisted.python.failure import Failure
|
||||
from libervia.backend.core.core_types import SatXMPPEntity
|
||||
|
|
@ -30,9 +30,13 @@ from twisted.words.xish import domish
|
|||
|
||||
from tx_xmpp import disco, pubsub
|
||||
from tx_xmpp.formats import Mood
|
||||
from libervia.backend.plugins.plugin_xep_0060 import XEP_0060
|
||||
from libervia.backend.tools.common import data_format
|
||||
from libervia.backend.tools import utils
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from libervia.backend.core.main import LiberviaBackend
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
NS_USER_MOOD = "http://jabber.org/protocol/mood"
|
||||
|
|
@ -50,12 +54,13 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
|
||||
class XEP_0163(object):
|
||||
def __init__(self, host):
|
||||
class XEP_0163:
|
||||
def __init__(self, host: "LiberviaBackend"):
|
||||
log.info(_("PEP plugin initialization"))
|
||||
self.host = host
|
||||
self.pep_events = set()
|
||||
self.pep_out_cb = {}
|
||||
self._ps = cast(XEP_0060, host.plugins["XEP-0060"])
|
||||
host.trigger.add("PubSub Disco Info", self.diso_info_trigger)
|
||||
host.bridge.add_method(
|
||||
"pep_send",
|
||||
|
|
@ -129,7 +134,7 @@ class XEP_0163(object):
|
|||
d = utils.as_deferred(in_callback, itemsEvent, client.profile)
|
||||
d.addErrback(self.log_error)
|
||||
|
||||
self.host.plugins["XEP-0060"].add_managed_node(node, items_cb=filter_pep_event)
|
||||
self._ps.add_managed_node(node, items_cb=filter_pep_event)
|
||||
|
||||
def send_pep_event(self, node, data, profile):
|
||||
"""Publish the event data
|
||||
|
|
@ -140,7 +145,7 @@ class XEP_0163(object):
|
|||
"""
|
||||
client = self.host.get_client(profile)
|
||||
item = pubsub.Item(payload=data)
|
||||
return self.host.plugins["XEP-0060"].publish(client, None, node, [item])
|
||||
return self._ps.publish(client, None, node, [item])
|
||||
|
||||
def pep_send(self, event_type, data, profile_key=C.PROF_KEY_NONE):
|
||||
"""Send personal event after checking the data is alright
|
||||
|
|
|
|||
Loading…
Reference in a new issue