Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -44,7 +44,7 @@ class ProfileManager(object):
|
|||
# and a way to keep some XMLUI request between sessions is expected in backend
|
||||
host = None
|
||||
bridge = None
|
||||
cache_keys_to_get = ['avatar', 'nicknames']
|
||||
cache_keys_to_get = ["avatar", "nicknames"]
|
||||
|
||||
def __init__(self, profile):
|
||||
self.profile = profile
|
||||
|
|
@ -136,10 +136,13 @@ class ProfileManager(object):
|
|||
|
||||
def _plug_profile_get_features_cb(self, features):
|
||||
self.host.features = features
|
||||
self.host.bridge.entities_data_get([], ProfileManager.cache_keys_to_get,
|
||||
profile=self.profile,
|
||||
callback=self._plug_profile_got_cached_values,
|
||||
errback=self._plug_profile_failed_cached_values)
|
||||
self.host.bridge.entities_data_get(
|
||||
[],
|
||||
ProfileManager.cache_keys_to_get,
|
||||
profile=self.profile,
|
||||
callback=self._plug_profile_got_cached_values,
|
||||
errback=self._plug_profile_failed_cached_values,
|
||||
)
|
||||
|
||||
def _plug_profile_failed_cached_values(self, failure):
|
||||
log.error("Couldn't get cached values: {}".format(failure))
|
||||
|
|
@ -153,7 +156,9 @@ class ProfileManager(object):
|
|||
self.host.entity_data_updated_handler(entity_s, key, value, self.profile)
|
||||
|
||||
if not self.connected:
|
||||
self.host.set_presence_status(C.PRESENCE_UNAVAILABLE, "", profile=self.profile)
|
||||
self.host.set_presence_status(
|
||||
C.PRESENCE_UNAVAILABLE, "", profile=self.profile
|
||||
)
|
||||
else:
|
||||
|
||||
contact_list.fill()
|
||||
|
|
@ -258,8 +263,12 @@ class QuickApp:
|
|||
AUTO_RESYNC = True
|
||||
|
||||
def __init__(
|
||||
self, bridge_factory, xmlui, check_options=None, connect_bridge=True,
|
||||
async_bridge_factory=None
|
||||
self,
|
||||
bridge_factory,
|
||||
xmlui,
|
||||
check_options=None,
|
||||
connect_bridge=True,
|
||||
async_bridge_factory=None,
|
||||
):
|
||||
"""Create a frontend application
|
||||
|
||||
|
|
@ -276,7 +285,7 @@ class QuickApp:
|
|||
self._plugs_in_progress = set()
|
||||
self.ready_profiles = set() # profiles which are connected and ready
|
||||
self.signals_cache = {} # used to keep signal received between start of
|
||||
# plug_profile and when the profile is actualy ready
|
||||
# plug_profile and when the profile is actualy ready
|
||||
self.contact_lists = quick_contact_list.QuickContactListHandler(self)
|
||||
self.widgets = quick_widgets.QuickWidgetsManager(self)
|
||||
if check_options is not None:
|
||||
|
|
@ -289,7 +298,7 @@ class QuickApp:
|
|||
|
||||
# listeners are callable watching events
|
||||
self._listeners = {} # key: listener type ("avatar", "selected", etc),
|
||||
# value: list of callbacks
|
||||
# value: list of callbacks
|
||||
|
||||
# cf. [register_action_handler]
|
||||
self._action_handlers: dict[str, Callable[[dict, str, int, str], None]] = {}
|
||||
|
|
@ -391,13 +400,14 @@ class QuickApp:
|
|||
def on_backend_ready(self):
|
||||
log.info("backend is ready")
|
||||
self.bridge.namespaces_get(
|
||||
callback=self._namespaces_get_cb, errback=self._namespaces_get_eb)
|
||||
callback=self._namespaces_get_cb, errback=self._namespaces_get_eb
|
||||
)
|
||||
# we cache available encryption plugins, as we'll use them on each
|
||||
# new chat widget
|
||||
self.bridge.encryption_plugins_get(
|
||||
callback=self._encryption_plugins_get_cb,
|
||||
errback=self._encryption_plugins_get_eb)
|
||||
|
||||
errback=self._encryption_plugins_get_eb,
|
||||
)
|
||||
|
||||
@property
|
||||
def current_profile(self):
|
||||
|
|
@ -596,7 +606,8 @@ class QuickApp:
|
|||
if not ignore_missing:
|
||||
log.error(
|
||||
f"Trying to remove an inexisting listener (type = {type_}): "
|
||||
f"{callback}")
|
||||
f"{callback}"
|
||||
)
|
||||
|
||||
def call_listeners(self, type_, *args, **kwargs):
|
||||
"""Call the methods which listen type_ event. If a profiles filter has
|
||||
|
|
@ -769,17 +780,28 @@ class QuickApp:
|
|||
def contact_new_handler(self, jid_s, attributes, groups, profile):
|
||||
entity = jid.JID(jid_s)
|
||||
groups = list(groups)
|
||||
self.contact_lists[profile].set_contact(entity, groups, attributes, in_roster=True)
|
||||
self.contact_lists[profile].set_contact(
|
||||
entity, groups, attributes, in_roster=True
|
||||
)
|
||||
|
||||
def message_new_handler(
|
||||
self, uid, timestamp, from_jid_s, to_jid_s, msg, subject, type_, extra_s,
|
||||
profile):
|
||||
self, uid, timestamp, from_jid_s, to_jid_s, msg, subject, type_, extra_s, profile
|
||||
):
|
||||
from_jid = jid.JID(from_jid_s)
|
||||
to_jid = jid.JID(to_jid_s)
|
||||
extra = data_format.deserialise(extra_s)
|
||||
if not self.trigger.point(
|
||||
"messageNewTrigger", uid, timestamp, from_jid, to_jid, msg, subject, type_,
|
||||
extra, profile=profile,):
|
||||
"messageNewTrigger",
|
||||
uid,
|
||||
timestamp,
|
||||
from_jid,
|
||||
to_jid,
|
||||
msg,
|
||||
subject,
|
||||
type_,
|
||||
extra,
|
||||
profile=profile,
|
||||
):
|
||||
return
|
||||
|
||||
from_me = from_jid.bare == self.profiles[profile].whoami.bare
|
||||
|
|
@ -800,9 +822,9 @@ class QuickApp:
|
|||
self.widgets.get_or_create_widget(
|
||||
quick_chat.QuickChat,
|
||||
target,
|
||||
type_ = C.CHAT_GROUP if is_room else C.CHAT_ONE2ONE,
|
||||
on_new_widget = None,
|
||||
profile = profile,
|
||||
type_=C.CHAT_GROUP if is_room else C.CHAT_ONE2ONE,
|
||||
on_new_widget=None,
|
||||
profile=profile,
|
||||
)
|
||||
|
||||
if (
|
||||
|
|
@ -824,24 +846,34 @@ class QuickApp:
|
|||
def message_encryption_started_handler(self, destinee_jid_s, plugin_data, profile):
|
||||
destinee_jid = jid.JID(destinee_jid_s)
|
||||
plugin_data = data_format.deserialise(plugin_data)
|
||||
for widget in self.widgets.get_widgets(quick_chat.QuickChat,
|
||||
target=destinee_jid.bare,
|
||||
profiles=(profile,)):
|
||||
for widget in self.widgets.get_widgets(
|
||||
quick_chat.QuickChat, target=destinee_jid.bare, profiles=(profile,)
|
||||
):
|
||||
widget.message_encryption_started(plugin_data)
|
||||
|
||||
def message_encryption_stopped_handler(self, destinee_jid_s, plugin_data, profile):
|
||||
destinee_jid = jid.JID(destinee_jid_s)
|
||||
for widget in self.widgets.get_widgets(quick_chat.QuickChat,
|
||||
target=destinee_jid.bare,
|
||||
profiles=(profile,)):
|
||||
for widget in self.widgets.get_widgets(
|
||||
quick_chat.QuickChat, target=destinee_jid.bare, profiles=(profile,)
|
||||
):
|
||||
widget.message_encryption_stopped(plugin_data)
|
||||
|
||||
def message_state_handler(self, uid, status, profile):
|
||||
for widget in self.widgets.get_widgets(quick_chat.QuickChat, profiles=(profile,)):
|
||||
widget.on_message_state(uid, status, profile)
|
||||
|
||||
def message_send(self, to_jid, message, subject=None, mess_type="auto", extra=None, callback=None, errback=None, profile_key=C.PROF_KEY_NONE):
|
||||
if not subject and not extra and (not message or message == {'': ''}):
|
||||
def message_send(
|
||||
self,
|
||||
to_jid,
|
||||
message,
|
||||
subject=None,
|
||||
mess_type="auto",
|
||||
extra=None,
|
||||
callback=None,
|
||||
errback=None,
|
||||
profile_key=C.PROF_KEY_NONE,
|
||||
):
|
||||
if not subject and not extra and (not message or message == {"": ""}):
|
||||
log.debug("Not sending empty message")
|
||||
return
|
||||
|
||||
|
|
@ -853,13 +885,23 @@ class QuickApp:
|
|||
callback = (
|
||||
lambda __=None: None
|
||||
) # FIXME: optional argument is here because pyjamas doesn't support callback
|
||||
# without arg with json proxy
|
||||
# without arg with json proxy
|
||||
if errback is None:
|
||||
errback = lambda failure: self.show_dialog(
|
||||
message=failure.message, title=failure.fullname, type="error"
|
||||
)
|
||||
|
||||
if not self.trigger.point("messageSendTrigger", to_jid, message, subject, mess_type, extra, callback, errback, profile_key=profile_key):
|
||||
if not self.trigger.point(
|
||||
"messageSendTrigger",
|
||||
to_jid,
|
||||
message,
|
||||
subject,
|
||||
mess_type,
|
||||
extra,
|
||||
callback,
|
||||
errback,
|
||||
profile_key=profile_key,
|
||||
):
|
||||
return
|
||||
|
||||
self.bridge.message_send(
|
||||
|
|
@ -906,7 +948,8 @@ class QuickApp:
|
|||
self.call_listeners("presence", entity, show, priority, statuses, profile=profile)
|
||||
|
||||
def muc_room_joined_handler(
|
||||
self, room_jid_s, occupants, user_nick, subject, statuses, profile):
|
||||
self, room_jid_s, occupants, user_nick, subject, statuses, profile
|
||||
):
|
||||
"""Called when a MUC room is joined"""
|
||||
log.debug(
|
||||
"Room [{room_jid}] joined by {profile}, users presents:{users}".format(
|
||||
|
|
@ -936,7 +979,8 @@ class QuickApp:
|
|||
chat_widget = self.widgets.get_widget(quick_chat.QuickChat, room_jid, profile)
|
||||
if chat_widget:
|
||||
self.widgets.delete_widget(
|
||||
chat_widget, all_instances=True, explicit_close=True)
|
||||
chat_widget, all_instances=True, explicit_close=True
|
||||
)
|
||||
self.contact_lists[profile].remove_contact(room_jid)
|
||||
|
||||
def muc_room_user_changed_nick_handler(self, room_jid_s, old_nick, new_nick, profile):
|
||||
|
|
@ -971,12 +1015,22 @@ class QuickApp:
|
|||
@param profile (unicode): current profile
|
||||
"""
|
||||
from_jid = jid.JID(from_jid_s)
|
||||
for widget in self.widgets.get_widgets(quick_chat.QuickChat, target=from_jid.bare,
|
||||
profiles=(profile,)):
|
||||
for widget in self.widgets.get_widgets(
|
||||
quick_chat.QuickChat, target=from_jid.bare, profiles=(profile,)
|
||||
):
|
||||
widget.on_chat_state(from_jid, state, profile)
|
||||
|
||||
def notify(self, type_, entity=None, message=None, subject=None, callback=None,
|
||||
cb_args=None, widget=None, profile=C.PROF_KEY_NONE):
|
||||
def notify(
|
||||
self,
|
||||
type_,
|
||||
entity=None,
|
||||
message=None,
|
||||
subject=None,
|
||||
callback=None,
|
||||
cb_args=None,
|
||||
widget=None,
|
||||
profile=C.PROF_KEY_NONE,
|
||||
):
|
||||
"""Trigger an event notification
|
||||
|
||||
@param type_(unicode): notifation kind,
|
||||
|
|
@ -1009,7 +1063,9 @@ class QuickApp:
|
|||
self._notif_id += 1
|
||||
self.call_listeners("notification", entity, notif_data, profile=profile)
|
||||
|
||||
def get_notifs(self, entity=None, type_=None, exact_jid=None, profile=C.PROF_KEY_NONE):
|
||||
def get_notifs(
|
||||
self, entity=None, type_=None, exact_jid=None, profile=C.PROF_KEY_NONE
|
||||
):
|
||||
"""return notifications for given entity
|
||||
|
||||
@param entity(jid.JID, None, C.ENTITY_ALL): jid of the entity to check
|
||||
|
|
@ -1203,11 +1259,11 @@ class QuickApp:
|
|||
def _debug_handler(self, action, parameters, profile):
|
||||
if action == "widgets_dump":
|
||||
from pprint import pformat
|
||||
|
||||
log.info("Widgets dump:\n{data}".format(data=pformat(self.widgets._widgets)))
|
||||
else:
|
||||
log.warning("Unknown debug action: {action}".format(action=action))
|
||||
|
||||
|
||||
def show_dialog(self, message, title, type="info", answer_cb=None, answer_data=None):
|
||||
"""Show a dialog to user
|
||||
|
||||
|
|
@ -1276,9 +1332,7 @@ class QuickApp:
|
|||
self.call_listeners("avatar", entity, value, profile=profile)
|
||||
|
||||
def register_action_handler(
|
||||
self,
|
||||
action_type: str,
|
||||
handler: Callable[[dict, str, int, str], None]
|
||||
self, action_type: str, handler: Callable[[dict, str, int, str], None]
|
||||
) -> None:
|
||||
"""Register a handler for action type.
|
||||
|
||||
|
|
@ -1307,13 +1361,13 @@ class QuickApp:
|
|||
def action_manager(
|
||||
self,
|
||||
action_data: dict,
|
||||
callback: Callable|None = None,
|
||||
ui_show_cb: Callable|None = None,
|
||||
callback: Callable | None = None,
|
||||
ui_show_cb: Callable | None = None,
|
||||
user_action: bool = True,
|
||||
action_id: str|None = None,
|
||||
progress_cb: Callable|None = None,
|
||||
progress_eb: Callable|None = None,
|
||||
profile: str = C.PROF_KEY_NONE
|
||||
action_id: str | None = None,
|
||||
progress_cb: Callable | None = None,
|
||||
progress_eb: Callable | None = None,
|
||||
profile: str = C.PROF_KEY_NONE,
|
||||
) -> None:
|
||||
"""Handle backend action
|
||||
|
||||
|
|
@ -1386,8 +1440,11 @@ class QuickApp:
|
|||
data_format.deserialise(data), callback, callback_id, profile
|
||||
)
|
||||
self.bridge.action_launch(
|
||||
callback_id, data_format.serialise(data), profile, callback=action_cb,
|
||||
errback=self.dialog_failure
|
||||
callback_id,
|
||||
data_format.serialise(data),
|
||||
profile,
|
||||
callback=action_cb,
|
||||
errback=self.dialog_failure,
|
||||
)
|
||||
|
||||
def launch_menu(
|
||||
|
|
|
|||
Loading…
Reference in a new issue