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