Commit 64aec8ad authored by Philipp Hörist's avatar Philipp Hörist

Add annotations

parent ee254d25
......@@ -33,7 +33,7 @@ def __init__(self, con):
self.handlers = []
self.annotations = {}
def get_annotations(self):
def get_annotations(self) -> None:
if not app.account_is_connected(self._account):
return
......@@ -44,7 +44,7 @@ def get_annotations(self):
self._con.connection.SendAndCallForResponse(iq, self._result_received)
def _result_received(self, stanza):
def _result_received(self, stanza: nbxmpp.Iq) -> None:
if not nbxmpp.isResultNode(stanza):
log.info('Error: %s', stanza.getError())
return
......@@ -69,7 +69,7 @@ def _result_received(self, stanza):
continue
self.annotations[jid] = note.getData()
def store_annotations(self):
def store_annotations(self) -> None:
if not app.account_is_connected(self._account):
return
......@@ -86,7 +86,7 @@ def store_annotations(self):
iq, self._store_result_received)
@staticmethod
def _store_result_received(stanza):
def _store_result_received(stanza: nbxmpp.Iq) -> None:
if not nbxmpp.isResultNode(stanza):
log.warning('Storing rosternotes failed: %s', stanza.getError())
return
......
......@@ -44,7 +44,7 @@ def pass_disco(self, from_, _identities, features, _data, _node):
self.supported = True
log.info('Discovered blocking: %s', from_)
def get_blocking_list(self):
def get_blocking_list(self) -> None:
if not self.supported:
return
iq = nbxmpp.Iq('get', nbxmpp.NS_BLOCKING)
......@@ -53,7 +53,7 @@ def get_blocking_list(self):
self._con.connection.SendAndCallForResponse(
iq, self._blocking_list_received)
def _blocking_list_received(self, stanza):
def _blocking_list_received(self, stanza: nbxmpp.Iq) -> None:
if not nbxmpp.isResultNode(stanza):
log.info('Error: %s', stanza.getError())
return
......@@ -118,12 +118,12 @@ def _blocking_push_received(self, _con, stanza):
raise nbxmpp.NodeProcessed
def _set_contact_offline(self, jid):
def _set_contact_offline(self, jid: str) -> None:
contact_list = app.contacts.get_contacts(self._account, jid)
for contact in contact_list:
contact.show = 'offline'
def _presence_probe(self, jid):
def _presence_probe(self, jid: str) -> None:
log.info('Presence probe: %s', jid)
# Send a presence Probe to get the current Status
probe = nbxmpp.Presence(jid, 'probe', frm=self._con.get_own_jid())
......
......@@ -16,6 +16,7 @@
import logging
import copy
from typing import Optional
from collections import OrderedDict
import nbxmpp
......@@ -62,7 +63,7 @@ def get_sorted_bookmarks(self, short_name=False):
sorted(sorted_bookmarks.items(),
key=lambda bookmark: bookmark[1]['name'].lower()))
def _pubsub_support(self):
def _pubsub_support(self) -> bool:
return (self._con.get_module('PEP').supported and
self._con.get_module('PubSub').publish_options)
......@@ -80,7 +81,7 @@ def get_bookmarks(self, storage_type=None):
log.info('Request Bookmarks (PrivateStorage)')
self._request_private_bookmarks()
def _request_pubsub_bookmarks(self):
def _request_pubsub_bookmarks(self) -> None:
log.info('Request Bookmarks (PubSub)')
self._con.get_module('PubSub').send_pb_retrieve(
'', 'storage:bookmarks',
......@@ -98,7 +99,7 @@ def _pubsub_bookmarks_received(self, _con, stanza):
self._parse_bookmarks(stanza)
self._request_private_bookmarks()
def _request_private_bookmarks(self):
def _request_private_bookmarks(self) -> None:
if not app.account_is_connected(self._account):
return
......@@ -109,7 +110,7 @@ def _request_private_bookmarks(self):
self._con.connection.SendAndCallForResponse(
iq, self._private_bookmarks_received)
def _private_bookmarks_received(self, stanza):
def _private_bookmarks_received(self, stanza: nbxmpp.Iq) -> None:
if not nbxmpp.isResultNode(stanza):
log.info('No private bookmarks: %s', stanza.getError())
else:
......@@ -154,11 +155,12 @@ def _get_storage_node(stanza):
return
return storage
def _parse_bookmarks(self, stanza, check_merge=False):
def _parse_bookmarks(self, stanza: nbxmpp.Iq,
check_merge: bool = False) -> bool:
merged = False
storage = self._get_storage_node(stanza)
if storage is None:
return
return False
confs = storage.getTags('conference')
for conf in confs:
......@@ -204,7 +206,7 @@ def _parse_bookmarks(self, stanza, check_merge=False):
return merged
def _build_storage_node(self):
def _build_storage_node(self) -> nbxmpp.Node:
storage_node = nbxmpp.Node(
tag='storage', attrs={'xmlns': 'storage:bookmarks'})
for jid, bm in self.bookmarks.items():
......@@ -228,7 +230,7 @@ def _build_storage_node(self):
return storage_node
@staticmethod
def get_bookmark_publish_options():
def get_bookmark_publish_options() -> nbxmpp.Node:
options = nbxmpp.Node(nbxmpp.NS_DATA + ' x',
attrs={'type': 'submit'})
field = options.addChild('field',
......@@ -254,14 +256,14 @@ def store_bookmarks(self, storage_type=None):
elif storage_type == BookmarkStorageType.PRIVATE:
self._private_store(storage_node)
def _pubsub_store(self, storage_node):
def _pubsub_store(self, storage_node: nbxmpp.Node) -> None:
self._con.get_module('PubSub').send_pb_publish(
'', 'storage:bookmarks', storage_node, 'current',
options=self.get_bookmark_publish_options(),
cb=self._pubsub_store_result)
log.info('Publish Bookmarks (PubSub)')
def _private_store(self, storage_node):
def _private_store(self, storage_node: nbxmpp.Node) -> None:
iq = nbxmpp.Iq('set', nbxmpp.NS_PRIVATE, payload=storage_node)
log.info('Publish Bookmarks (PrivateStorage)')
self._con.connection.SendAndCallForResponse(
......@@ -274,12 +276,12 @@ def _pubsub_store_result(_con, stanza):
return
@staticmethod
def _private_store_result(stanza):
def _private_store_result(stanza: nbxmpp.Iq) -> None:
if not nbxmpp.isResultNode(stanza):
log.error('Error: %s', stanza.getError())
return
def auto_join_bookmarks(self):
def auto_join_bookmarks(self) -> None:
if app.is_invisible(self._account):
return
for jid, bm in self.bookmarks.items():
......@@ -306,14 +308,14 @@ def add_bookmark(self, name, jid, autojoin,
app.nec.push_incoming_event(BookmarksReceivedEvent(
None, account=self._account))
def get_name_from_bookmark(self, jid):
def get_name_from_bookmark(self, jid: str) -> str:
fallback = jid.split('@')[0]
try:
return self.bookmarks[jid]['name'] or fallback
except KeyError:
return fallback
def purge_pubsub_bookmarks(self):
def purge_pubsub_bookmarks(self) -> None:
log.info('Purge/Delete Bookmarks on PubSub, '
'because publish options are not available')
self._con.get_module('PubSub').send_pb_purge('', 'storage:bookmarks')
......
......@@ -36,12 +36,12 @@ def __init__(self, con):
]
@staticmethod
def _get_ping_iq(to):
def _get_ping_iq(to: str) -> nbxmpp.Iq:
iq = nbxmpp.Iq('get', to=to)
iq.addChild(name='ping', namespace=nbxmpp.NS_PING)
return iq
def send_keepalive_ping(self):
def send_keepalive_ping(self) -> None:
if not app.account_is_connected(self._account):
return
......@@ -55,11 +55,11 @@ def send_keepalive_ping(self):
'time_for_ping_alive_answer')
self._alarm_time = app.idlequeue.set_alarm(self._reconnect, seconds)
def _keepalive_received(self, _stanza):
def _keepalive_received(self, _stanza: nbxmpp.Iq) -> None:
log.info('Received keepalive')
app.idlequeue.remove_alarm(self._reconnect, self._alarm_time)
def _reconnect(self):
def _reconnect(self) -> None:
if not app.config.get_per('accounts', self._account, 'active'):
# Account may have been disabled
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment