Add annotations

This commit is contained in:
Philipp Hörist 2018-09-12 21:07:59 +02:00 committed by Philipp Hörist
parent 16d0780d92
commit 6ba984d540
4 changed files with 28 additions and 26 deletions

View File

@ -33,7 +33,7 @@ class Annotations:
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 @@ class Annotations:
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 @@ class Annotations:
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 @@ class Annotations:
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

View File

@ -44,7 +44,7 @@ class Blocking:
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 @@ class Blocking:
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 @@ class Blocking:
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())

View File

@ -16,6 +16,7 @@
import logging
import copy
from typing import Optional
from collections import OrderedDict
import nbxmpp
@ -62,7 +63,7 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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 @@ class Bookmarks:
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')

View File

@ -36,12 +36,12 @@ class Ping:
]
@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 @@ class Ping:
'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