Mercurial > libervia-desktop-kivy
diff cagou/plugins/plugin_wid_chat.py @ 491:203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:32 +0200 |
parents | 962d17c4078c |
children |
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.py Sat Apr 08 13:34:55 2023 +0200 +++ b/cagou/plugins/plugin_wid_chat.py Sat Apr 08 13:44:32 2023 +0200 @@ -100,9 +100,9 @@ show_resize = properties.BooleanProperty(False) def on_kv_post(self, __): - self.attachments.bind(children=self.onAttachment) + self.attachments.bind(children=self.on_attachment) - def onAttachment(self, __, attachments): + def on_attachment(self, __, attachments): if len(attachments) == 0: self.show_resize = False @@ -140,7 +140,7 @@ def on_press(self): full_size_source = self.data.get('path', self.data.get('url')) gallery = ImagesGallery(sources=[full_size_source]) - G.host.showExtraUI(gallery) + G.host.show_extra_ui(gallery) def on_kv_post(self, __): self.on_data(None, self.data) @@ -158,21 +158,21 @@ chat = properties.ObjectProperty() mess_data = properties.ObjectProperty() - def _setPreview(self, attachment, wid, preview_path): + def _set_preview(self, attachment, wid, preview_path): attachment['preview'] = preview_path wid.source = preview_path - def _setPath(self, attachment, wid, path): + def _set_path(self, attachment, wid, path): attachment['path'] = path if wid is not None: # we also need a preview for the widget if 'preview' in attachment: wid.source = attachment['preview'] else: - G.host.bridge.imageGeneratePreview( + G.host.bridge.image_generate_preview( path, self.chat.profile, - callback=partial(self._setPreview, attachment, wid), + callback=partial(self._set_preview, attachment, wid), ) def on_kv_post(self, __): @@ -194,15 +194,15 @@ if idx < 3 or len(attachments) <= 4: if ((self.mess_data.own_mess - or self.chat.contact_list.isInRoster(self.mess_data.from_jid))): + or self.chat.contact_list.is_in_roster(self.mess_data.from_jid))): wid = AsyncImage(size_hint=(1, 1), source="data/images/image-loading.gif") if 'preview' in attachment: wid.source = attachment["preview"] elif 'path' in attachment: - G.host.bridge.imageGeneratePreview( + G.host.bridge.image_generate_preview( attachment['path'], self.chat.profile, - callback=partial(self._setPreview, attachment, wid), + callback=partial(self._set_preview, attachment, wid), ) elif url is None: log.warning(f"Can't find any source for {attachment}") @@ -220,9 +220,9 @@ if to_download: # the file needs to be downloaded, the widget source, # attachment path, and preview will then be completed - G.host.downloadURL( + G.host.download_url( url, - callback=partial(self._setPath, attachment, wid), + callback=partial(self._set_path, attachment, wid), dest=C.FILE_DEST_CACHE, profile=self.chat.profile, ) @@ -243,7 +243,7 @@ else: sources.append(source) gallery = ImagesGallery(sources=sources) - G.host.showExtraUI(gallery) + G.host.show_extra_ui(gallery) class AttachmentToSendItem(AttachmentItem): @@ -322,7 +322,7 @@ if 'avatar' in update_dict: avatar_data = update_dict['avatar'] if avatar_data is None: - source = G.host.getDefaultAvatar() + source = G.host.get_default_avatar() else: source = avatar_data['path'] self.avatar.source = source @@ -330,7 +330,7 @@ status = update_dict['status'] self.delivery.text = '\u2714' if status == 'delivered' else '' - def _setPath(self, data, path): + def _set_path(self, data, path): """Set path of decrypted file to an item""" data['path'] = path @@ -372,7 +372,7 @@ # to avoid leaking IP address, we only display image if the contact is in # roster if ((self.mess_data.own_mess - or self.chat.contact_list.isInRoster(self.mess_data.from_jid))): + or self.chat.contact_list.is_in_roster(self.mess_data.from_jid))): try: url = urlparse(attachment['url']) except KeyError: @@ -383,9 +383,9 @@ # the local decrypted version del attachment['url'] item = AttachmentImageItem(data=attachment) - G.host.downloadURL( + G.host.download_url( url.geturl(), - callback=partial(self._setPath, item.data), + callback=partial(self._set_path, item.data), dest=C.FILE_DEST_CACHE, profile=self.chat.profile, ) @@ -432,7 +432,7 @@ def on_release(self, *args): menu.TransferMenu( encrypted=self.chat.encrypted, - callback=self.chat.transferFile, + callback=self.chat.transfer_file, ).show(self) @@ -441,19 +441,19 @@ def on_select(self, menu): if menu == 'bookmark': - G.host.bridge.menuLaunch(C.MENU_GLOBAL, ("groups", "bookmarks"), + G.host.bridge.menu_launch(C.MENU_GLOBAL, ("groups", "bookmarks"), {}, C.NO_SECURITY_LIMIT, self.chat.profile, callback=partial( - G.host.actionManager, profile=self.chat.profile), + G.host.action_manager, profile=self.chat.profile), errback=G.host.errback) elif menu == 'close': if self.chat.type == C.CHAT_GROUP: # for MUC, we have to indicate the backend that we've left - G.host.bridge.mucLeave(self.chat.target, self.chat.profile) + G.host.bridge.muc_leave(self.chat.target, self.chat.profile) else: # for one2one, backend doesn't keep any state, so we just delete the # widget here in the frontend - G.host.widgets.deleteWidget( + G.host.widgets.delete_widget( self.chat, all_instances=True, explicit_close=True) else: raise exceptions.InternalError("Unknown menu: {}".format(menu)) @@ -474,7 +474,7 @@ super(EncryptionMainButton, self).__init__(**kwargs) self.bind(on_release=self.encryption_menu.open) - def selectAlgo(self, name): + def select_algo(self, name): """Mark an encryption algorithm as selected. This will also deselect all other button @@ -486,7 +486,7 @@ for button in buttons[:-1]: button.selected = button.text == name - def getColor(self): + def get_color(self): if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: return (0.4, 0.4, 0.4, 1) elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: @@ -494,7 +494,7 @@ else: return (0.4, 0.4, 0.4, 1) - def getSymbol(self): + def get_symbol(self): if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: return 'lock-open' elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: @@ -557,83 +557,83 @@ trust_button=True, ) btn.bind( - on_release=partial(self.startEncryption, plugin=plugin), - on_trust_release=partial(self.getTrustUI, plugin=plugin), + on_release=partial(self.start_encryption, plugin=plugin), + on_trust_release=partial(self.get_trust_ui, plugin=plugin), ) self.add_widget(btn) log.info("added encryption: {}".format(plugin['name'])) - def messageEncryptionStopCb(self): + def message_encryption_stop_cb(self): log.info(_("Session with {destinee} is now in plain text").format( destinee = self.chat.target)) - def messageEncryptionStopEb(self, failure_): + def message_encryption_stop_eb(self, failure_): msg = _("Error while stopping encryption with {destinee}: {reason}").format( destinee = self.chat.target, reason = failure_) log.warning(msg) - G.host.addNote(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) + G.host.add_note(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) def unencrypted(self, button): self.dismiss() - G.host.bridge.messageEncryptionStop( + G.host.bridge.message_encryption_stop( str(self.chat.target), self.chat.profile, - callback=self.messageEncryptionStopCb, - errback=self.messageEncryptionStopEb) + callback=self.message_encryption_stop_cb, + errback=self.message_encryption_stop_eb) - def messageEncryptionStartCb(self, plugin): + def message_encryption_start_cb(self, plugin): log.info(_("Session with {destinee} is now encrypted with {encr_name}").format( destinee = self.chat.target, encr_name = plugin['name'])) - def messageEncryptionStartEb(self, failure_): + def message_encryption_start_eb(self, failure_): msg = _("Session can't be encrypted with {destinee}: {reason}").format( destinee = self.chat.target, reason = failure_) log.warning(msg) - G.host.addNote(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) + G.host.add_note(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) - def startEncryption(self, button, plugin): + def start_encryption(self, button, plugin): """Request encryption with given plugin for this session @param button(EncryptionButton): button which has been pressed @param plugin(dict): plugin data """ self.dismiss() - G.host.bridge.messageEncryptionStart( + G.host.bridge.message_encryption_start( str(self.chat.target), plugin['namespace'], True, self.chat.profile, - callback=partial(self.messageEncryptionStartCb, plugin=plugin), - errback=self.messageEncryptionStartEb) + callback=partial(self.message_encryption_start_cb, plugin=plugin), + errback=self.message_encryption_start_eb) - def encryptionTrustUIGetCb(self, xmlui_raw): + def encryption_trust_ui_get_cb(self, xmlui_raw): xml_ui = xmlui.create( G.host, xmlui_raw, profile=self.chat.profile) xml_ui.show() - def encryptionTrustUIGetEb(self, failure_): + def encryption_trust_ui_get_eb(self, failure_): msg = _("Trust manager interface can't be retrieved: {reason}").format( reason = failure_) log.warning(msg) - G.host.addNote(_("encryption trust management problem"), msg, + G.host.add_note(_("encryption trust management problem"), msg, C.XMLUI_DATA_LVL_ERROR) - def getTrustUI(self, button, plugin): + def get_trust_ui(self, button, plugin): """Request and display trust management UI @param button(EncryptionButton): button which has been pressed @param plugin(dict): plugin data """ self.dismiss() - G.host.bridge.encryptionTrustUIGet( + G.host.bridge.encryption_trust_ui_get( str(self.chat.target), plugin['namespace'], self.chat.profile, - callback=self.encryptionTrustUIGetCb, - errback=self.encryptionTrustUIGetEb) + callback=self.encryption_trust_ui_get_cb, + errback=self.encryption_trust_ui_get_eb) class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): @@ -663,21 +663,21 @@ self._hi_comp_allowed = True cagou_widget.CagouWidget.__init__(self) transfer_btn = TransferButton(chat=self) - self.headerInputAddExtra(transfer_btn) + self.header_input_add_extra(transfer_btn) if (type_ == C.CHAT_ONE2ONE or "REALJID_PUBLIC" in statuses): self.encryption_btn = EncryptionMainButton(self) - self.headerInputAddExtra(self.encryption_btn) + self.header_input_add_extra(self.encryption_btn) self.extra_menu = ExtraMenu(chat=self) extra_btn = ExtraButton(chat=self) - self.headerInputAddExtra(extra_btn) + self.header_input_add_extra(extra_btn) self.header_input.hint_text = target self._history_prepend_lock = False self.history_count = 0 def on_kv_post(self, __): - self.postInit() + self.post_init() - def screenManagerInit(self, screen_manager): + def screen_manager_init(self, screen_manager): screen_manager.transition = screenmanager.SlideTransition(direction='down') sel_screen = Screen(name='chat_selector') chat_selector = ChatSelector(profile=self.profile) @@ -705,8 +705,8 @@ target = G.host.profiles[profiles[0]].whoami else: show_chat_selector = False - wid = G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, - on_existing_widget=G.host.getOrClone, + wid = G.host.widgets.get_or_create_widget(cls, target, on_new_widget=None, + on_existing_widget=G.host.get_or_clone, profiles=profiles) wid.show_chat_selector = show_chat_selector return wid @@ -727,21 +727,21 @@ ## drop ## def on_drop_file(self, path): - self.addAttachment(path) + self.add_attachment(path) ## header ## - def changeWidget(self, jid_): + def change_widget(self, jid_): """change current widget for a new one with given jid @param jid_(jid.JID): jid of the widget to create """ - plugin_info = G.host.getPluginInfo(main=Chat) + plugin_info = G.host.get_plugin_info(main=Chat) factory = plugin_info['factory'] - G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile])) + G.host.switch_widget(self, factory(plugin_info, jid_, profiles=[self.profile])) self.header_input.text = '' - def onHeaderInput(self): + def on_header_wid_input(self): text = self.header_input.text.strip() try: if text.count('@') != 1 or text.count(' '): @@ -751,31 +751,31 @@ log.info("entered text is not a jid") return - def discoCb(disco): + def disco_cb(disco): # TODO: check if plugin XEP-0045 is activated if "conference" in [i[0] for i in disco[1]]: - G.host.bridge.mucJoin(str(jid_), "", "", self.profile, - callback=self._mucJoinCb, errback=self._mucJoinEb) + G.host.bridge.muc_join(str(jid_), "", "", self.profile, + callback=self._muc_join_cb, errback=self._muc_join_eb) else: - self.changeWidget(jid_) + self.change_widget(jid_) - def discoEb(failure): + def disco_eb(failure): log.warning("Disco failure, ignore this text: {}".format(failure)) - G.host.bridge.discoInfos( + G.host.bridge.disco_infos( jid_.domain, profile_key=self.profile, - callback=discoCb, - errback=discoEb) + callback=disco_cb, + errback=disco_eb) - def onHeaderInputCompleted(self, input_wid, completed_text): + def on_header_wid_input_completed(self, input_wid, completed_text): self._hi_comp_allowed = False input_wid.text = completed_text self._hi_comp_allowed = True self._hi_comp_dropdown.dismiss() - self.onHeaderInput() + self.on_header_wid_input() - def onHeaderInputComplete(self, wid, text): + def on_header_wid_input_complete(self, wid, text): if not self._hi_comp_allowed: return text = text.lstrip() @@ -813,7 +813,7 @@ profile = profile, size_hint = (0.5, None), nick = nick, - on_release=lambda __, txt=jid_.bare: self.onHeaderInputCompleted(wid, txt) + on_release=lambda __, txt=jid_.bare: self.on_header_wid_input_completed(wid, txt) ) dropdown.add_widget(btn) else: @@ -828,17 +828,17 @@ dropdown.open(wid) self._hi_comp_last = text - def messageDataConverter(self, idx, mess_id): + def message_data_converter(self, idx, mess_id): return {"mess_data": self.messages[mess_id]} - def _onHistoryPrinted(self): + def _on_history_printed(self): """Refresh or scroll down the focus after the history is printed""" # self.adapter.data = self.messages for mess_data in self.messages.values(): self.appendMessage(mess_data) - super(Chat, self)._onHistoryPrinted() + super(Chat, self)._on_history_printed() - def createMessage(self, message): + def create_message(self, message): self.appendMessage(message) # we need to render immediatly next 2 layouts to avoid an unpleasant flickering # when sending or receiving a message @@ -849,12 +849,12 @@ @param mess_data(quick_chat.Message): message data """ - if self.handleUserMoved(mess_data): + if self.handle_user_moved(mess_data): return self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) self.notify(mess_data) - def prependMessage(self, mess_data): + def prepend_message(self, mess_data): """Prepend a message Widget to the history @param mess_data(quick_chat.Message): message data @@ -877,7 +877,7 @@ For group chat, note will be added on mention, with a desktop notification if window has not focus or is not visible. """ - visible_clones = [w for w in G.host.getVisibleList(self.__class__) + visible_clones = [w for w in G.host.get_visible_list(self.__class__) if w.target == self.target] if len(visible_clones) > 1 and visible_clones.index(self) > 0: # to avoid multiple notifications in case of multiple cloned widgets @@ -896,7 +896,7 @@ profile=self.profile ) if not is_visible: - G.host.addNote( + G.host.add_note( _("private message"), notif_msg, symbol = "chat", @@ -908,7 +908,7 @@ else: if mess_data.mention: notif_msg = self._get_notif_msg(mess_data) - G.host.addNote( + G.host.add_note( _("mention"), notif_msg, symbol = "chat", @@ -930,19 +930,19 @@ # message input - def _attachmentProgressCb(self, item, metadata, profile): + def _attachment_progress_cb(self, item, metadata, profile): item.parent.remove_widget(item) log.info(f"item {item.data.get('path')} uploaded successfully") - def _attachmentProgressEb(self, item, err_msg, profile): + def _attachment_progress_eb(self, item, err_msg, profile): item.parent.remove_widget(item) path = item.data.get('path') msg = _("item {path} could not be uploaded: {err_msg}").format( path=path, err_msg=err_msg) - G.host.addNote(_("can't upload file"), msg, C.XMLUI_DATA_LVL_WARNING) + G.host.add_note(_("can't upload file"), msg, C.XMLUI_DATA_LVL_WARNING) log.warning(msg) - def _progressGetCb(self, item, metadata): + def _progress_get_cb(self, item, metadata): try: position = int(metadata["position"]) size = int(metadata["size"]) @@ -960,23 +960,23 @@ if item.parent is not None: # the item is not yet fully received, we reschedule an update Clock.schedule_once( - partial(self._attachmentProgressUpdate, item), + partial(self._attachment_progress_update, item), PROGRESS_UPDATE) - def _attachmentProgressUpdate(self, item, __): - G.host.bridge.progressGet( + def _attachment_progress_update(self, item, __): + G.host.bridge.progress_get( item.data["progress_id"], self.profile, - callback=partial(self._progressGetCb, item), + callback=partial(self._progress_get_cb, item), errback=G.host.errback, ) - def addNick(self, nick): + def add_nick(self, nick): """Add a nickname to message_input if suitable""" if (self.type == C.CHAT_GROUP and not self.message_input.text.startswith(nick)): self.message_input.text = f'{nick}: {self.message_input.text}' - def onSend(self, input_widget): + def on_send(self, input_widget): extra = {} for item in self.attachments_to_send.attachments.children: if item.sending: @@ -999,17 +999,17 @@ attachments.append(attachment) Clock.schedule_once( - partial(self._attachmentProgressUpdate, item), + partial(self._attachment_progress_update, item), PROGRESS_UPDATE) - G.host.registerProgressCbs( + G.host.register_progress_cbs( progress_id, - callback=partial(self._attachmentProgressCb, item), - errback=partial(self._attachmentProgressEb, item) + callback=partial(self._attachment_progress_cb, item), + errback=partial(self._attachment_progress_eb, item) ) - G.host.messageSend( + G.host.message_send( self.target, # TODO: handle language {'': input_widget.text}, @@ -1021,13 +1021,13 @@ ) input_widget.text = '' - def _imageCheckCb(self, report_raw): + def _image_check_cb(self, report_raw): report = data_format.deserialise(report_raw) if report['too_large']: self.attachments_to_send.show_resize=True self.attachments_to_send.reduce_checkbox.active=True - def addAttachment(self, file_path, media_type=None): + def add_attachment(self, file_path, media_type=None): file_path = Path(file_path) if media_type is None: media_type = mimetypes.guess_type(str(file_path), strict=False)[0] @@ -1037,9 +1037,9 @@ # default. main_type = media_type.split('/')[0] if main_type == "image": - G.host.bridge.imageCheck( + G.host.bridge.image_check( str(file_path), - callback=self._imageCheckCb, + callback=self._image_check_cb, errback=partial( G.host.errback, title=_("Can't check image size"), @@ -1060,10 +1060,10 @@ AttachmentToSendItem(data=data) ) - def transferFile(self, file_path, transfer_type=C.TRANSFER_UPLOAD, cleaning_cb=None): + def transfer_file(self, file_path, transfer_type=C.TRANSFER_UPLOAD, cleaning_cb=None): # FIXME: cleaning_cb is not managed if transfer_type == C.TRANSFER_UPLOAD: - self.addAttachment(file_path) + self.add_attachment(file_path) elif transfer_type == C.TRANSFER_SEND: if self.type == C.CHAT_GROUP: log.warning("P2P transfer is not possible for group chat") @@ -1072,35 +1072,35 @@ else: jid_ = self.target if not jid_.resource: - jid_ = G.host.contact_lists[self.profile].getFullJid(jid_) - G.host.bridge.fileSend(str(jid_), str(file_path), "", "", "", + jid_ = G.host.contact_lists[self.profile].get_full_jid(jid_) + G.host.bridge.file_send(str(jid_), str(file_path), "", "", "", profile=self.profile) # TODO: notification of sending/failing else: raise log.error("transfer of type {} are not handled".format(transfer_type)) - def messageEncryptionStarted(self, plugin_data): - quick_chat.QuickChat.messageEncryptionStarted(self, plugin_data) + def message_encryption_started(self, plugin_data): + quick_chat.QuickChat.message_encryption_started(self, plugin_data) self.encryption_btn.symbol = SYMBOL_ENCRYPTED self.encryption_btn.color = COLOR_ENCRYPTED - self.encryption_btn.selectAlgo(plugin_data['name']) + self.encryption_btn.select_algo(plugin_data['name']) - def messageEncryptionStopped(self, plugin_data): - quick_chat.QuickChat.messageEncryptionStopped(self, plugin_data) + def message_encryption_stopped(self, plugin_data): + quick_chat.QuickChat.message_encryption_stopped(self, plugin_data) self.encryption_btn.symbol = SYMBOL_UNENCRYPTED self.encryption_btn.color = COLOR_UNENCRYPTED - self.encryption_btn.selectAlgo(None) + self.encryption_btn.select_algo(None) - def _mucJoinCb(self, joined_data): + def _muc_join_cb(self, joined_data): joined, room_jid_s, occupants, user_nick, subject, statuses, profile = joined_data - self.host.mucRoomJoinedHandler(*joined_data[1:]) + self.host.muc_room_joined_handler(*joined_data[1:]) jid_ = jid.JID(room_jid_s) - self.changeWidget(jid_) + self.change_widget(jid_) - def _mucJoinEb(self, failure): + def _muc_join_eb(self, failure): log.warning("Can't join room: {}".format(failure)) - def onOTRState(self, state, dest_jid, profile): + def on_otr_state(self, state, dest_jid, profile): assert profile in self.profiles if state in OTR_STATE_ENCRYPTION: self.otr_state_encryption = state @@ -1109,17 +1109,17 @@ else: log.error(_("Unknown OTR state received: {}".format(state))) return - self.encryption_btn.symbol = self.encryption_btn.getSymbol() - self.encryption_btn.color = self.encryption_btn.getColor() + self.encryption_btn.symbol = self.encryption_btn.get_symbol() + self.encryption_btn.color = self.encryption_btn.get_color() - def onVisible(self): + def on_visible(self): if not self.sync: self.resync() - def onSelected(self): - G.host.clearNotifs(self.target, profile=self.profile) + def on_selected(self): + G.host.clear_notifs(self.target, profile=self.profile) - def onDelete(self, **kwargs): + def on_delete(self, **kwargs): if kwargs.get('explicit_close', False): wrapper = self.whwrapper if wrapper is not None: @@ -1132,7 +1132,7 @@ return True # we always keep one widget, so it's available when swiping # TODO: delete all widgets when chat is closed - nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self)) + nb_instances = sum(1 for _ in self.host.widgets.get_widget_instances(self)) # we want to keep at least one instance of Chat by WHWrapper nb_to_keep = len(G.host.widgets_handler.children) if nb_instances <= nb_to_keep: @@ -1141,8 +1141,8 @@ def _history_unlock(self, __): self._history_prepend_lock = False log.debug("history prepend unlocked") - # we call manually onScroll, to check if we are still in the scrolling zone - self.onScroll(self.history_scroll, self.history_scroll.scroll_y) + # we call manually on_scroll, to check if we are still in the scrolling zone + self.on_scroll(self.history_scroll, self.history_scroll.scroll_y) def _history_scroll_adjust(self, __, scroll_start_height): # history scroll position must correspond to where it was before new messages @@ -1155,7 +1155,7 @@ # again Clock.schedule_once(self._history_unlock, 1.5) - def _backHistoryGetCb_post(self, __, history, scroll_start_height): + def _back_history_get_cb_post(self, __, history, scroll_start_height): if len(history) == 0: # we don't unlock self._history_prepend_lock if there is no history, as there # is no sense to try to retrieve more in this case. @@ -1170,8 +1170,8 @@ log.debug( f"{len(history)} messages prepended to history (last: {history[0][0]})") - def _backHistoryGetCb(self, history): - # TODO: factorise with QuickChat._historyGetCb + def _back_history_get_cb(self, history): + # TODO: factorise with QuickChat._history_get_cb scroll_start_height = self.messages_widget.height * self.history_scroll.scroll_y for data in reversed(history): uid, timestamp, from_jid, to_jid, message, subject, type_, extra_s = data @@ -1192,14 +1192,14 @@ self.profile, ) self.messages.move_to_end(uid, last=False) - self.prependMessage(message) + self.prepend_message(message) Clock.schedule_once(partial( - self._backHistoryGetCb_post, + self._back_history_get_cb_post, history=history, scroll_start_height=scroll_start_height)) - def _backHistoryGetEb(self, failure_): - G.host.addNote( + def _back_history_get_eb(self, failure_): + G.host.add_note( _("Problem while getting back history"), _("Can't back history for {target}: {problem}").format( target=self.target, problem=failure_), @@ -1207,7 +1207,7 @@ # we don't unlock self._history_prepend_lock on purpose, no need # to try to get more history if something is wrong - def onScroll(self, scroll_view, scroll_y): + def on_scroll(self, scroll_view, scroll_y): if self._history_prepend_lock: return if (1-scroll_y) * self.messages_widget.height < INFINITE_SCROLL_LIMIT: @@ -1217,15 +1217,15 @@ first_uid = next(iter(self.messages.keys())) filters = self.history_filters.copy() filters['before_uid'] = first_uid - self.host.bridge.historyGet( + self.host.bridge.history_get( str(self.host.profiles[self.profile].whoami.bare), str(self.target), 30, True, {k: str(v) for k,v in filters.items()}, self.profile, - callback=self._backHistoryGetCb, - errback=self._backHistoryGetEb, + callback=self._back_history_get_cb, + errback=self._back_history_get_eb, ) @@ -1237,7 +1237,7 @@ def on_select(self, contact_button): contact_jid = jid.JID(contact_button.jid) - plugin_info = G.host.getPluginInfo(main=Chat) + plugin_info = G.host.get_plugin_info(main=Chat) factory = plugin_info['factory'] self.screen_manager.transition.direction = 'up' carousel = self.whwrapper.carousel @@ -1248,11 +1248,11 @@ carousel.index = idx self.screen_manager.current = '' else: - G.host.switchWidget( + G.host.switch_widget( self, factory(plugin_info, contact_jid, profiles=[self.profile])) - def onHeaderInput(self): + def on_header_wid_input(self): text = self.header_input.text.strip() try: if text.count('@') != 1 or text.count(' '): @@ -1261,9 +1261,9 @@ except ValueError: log.info("entered text is not a jid") return - G.host.doAction("chat", jid_, [self.profile]) + G.host.do_action("chat", jid_, [self.profile]) - def onHeaderInputComplete(self, wid, text, **kwargs): + def on_header_wid_input_complete(self, wid, text, **kwargs): """we filter items when text is entered in input box""" for layout in self.jid_selector.items_layouts: self.do_filter(