Daniel Brötzmann pushed to branch newcontrol at gajim / gajim


Commits:
fd9718ba by wurstsalat at 2022-08-03T23:18:03+02:00
imprv: MessageInputTextView: Improve draft storage

- - - - -


4 changed files:

- gajim/gtk/chat_stack.py
- gajim/gtk/main.py
- gajim/gtk/message_actions_box.py
- gajim/gtk/message_input.py


Changes:

=====================================
gajim/gtk/chat_stack.py
=====================================
@@ -333,7 +333,7 @@ def _update_base_actions(self, contact: ChatContactT) -> 
None:
         client = app.get_client(contact.account)
         online = app.account_is_connected(contact.account)
 
-        has_text = self._message_action_box.msg_textview.has_text()
+        has_text = self._message_action_box.msg_textview.has_text
         app.window.get_action('send-message').set_enabled(
             online and has_text)
 


=====================================
gajim/gtk/main.py
=====================================
@@ -498,7 +498,7 @@ def _on_window_motion_notify(self,
             chat_stack = self._chat_page.get_chat_stack()
             msg_action_box = chat_stack.get_message_action_box()
             client.get_module('Chatstate').set_mouse_activity(
-                control.contact, msg_action_box.msg_textview.has_text())
+                control.contact, msg_action_box.msg_textview.has_text)
 
     def _on_window_delete(self,
                           _widget: Gtk.ApplicationWindow,


=====================================
gajim/gtk/message_actions_box.py
=====================================
@@ -282,7 +282,7 @@ def _update_message_input_state(self) -> None:
     def _set_chatstate(self, state: bool) -> None:
         assert self._client is not None
         if state:
-            if self.msg_textview.has_text():
+            if self.msg_textview.has_text:
                 self._client.get_module('Chatstate').set_chatstate(
                     self._contact, Chatstate.PAUSED)
             else:
@@ -513,7 +513,7 @@ def _update_send_file_button_tooltip(self):
         self._ui.sendfile_button.set_tooltip_text(tooltip_text)
 
     def _on_buffer_changed(self, textbuffer: Gtk.TextBuffer) -> None:
-        has_text = self.msg_textview.has_text()
+        has_text = self.msg_textview.has_text
         send_message_action = app.window.lookup_action('send-message')
         assert send_message_action is not None
         send_message_action.set_enabled(has_text)


=====================================
gajim/gtk/message_input.py
=====================================
@@ -77,7 +77,7 @@ def __init__(self) -> None:
         self.undo_pressed: bool = False
 
         self._contact: Optional[ChatContactT] = None
-        self._drafts: dict[JID, str] = {}
+        self._drafts: dict[tuple[str, JID], str] = {}
 
         self._chat_action_processor = ChatActionProcessor(self)
 
@@ -95,13 +95,15 @@ def __init__(self) -> None:
 
     def switch_contact(self, contact: ChatContactT) -> None:
         if self._contact is not None:
-            if self.has_text():
-                self._drafts[self._contact.jid] = self.get_text()
+            account = self._contact.account
+            jid = self._contact.jid
+            if self.has_text:
+                self._drafts[(account, jid)] = self.get_text()
             else:
-                self._drafts.pop(self._contact.jid, None)
+                self._drafts.pop((account, jid), None)
 
         self.clear()
-        draft = self._drafts.get(contact.jid)
+        draft = self._drafts.get((contact.account, contact.jid))
         if draft is not None:
             self.insert_text(draft)
 
@@ -138,7 +140,7 @@ def _on_focus_out(self,
         scrolled = self.get_parent()
         assert scrolled
         scrolled.get_style_context().remove_class('message-input-focus')
-        if not self.has_text():
+        if not self.has_text:
             self.toggle_speller(False)
         return False
 
@@ -188,6 +190,7 @@ def insert_newline(self) -> None:
         if buf.get_end_iter().equal(iter_):
             GLib.idle_add(scroll_to_end, self.get_parent())
 
+    @property
     def has_text(self) -> bool:
         buf = self.get_buffer()
         start, end = buf.get_bounds()
@@ -200,6 +203,9 @@ def get_text(self) -> str:
         text = self.get_buffer().get_text(start, end, True)
         return text
 
+    def get_draft(self, account: str, jid: JID) -> Optional[str]:
+        return self._drafts.get((account, jid))
+
     def toggle_speller(self, activate: bool) -> None:
         if app.is_installed('GSPELL') and app.settings.get('use_speller'):
             spell_view = Gspell.TextView.get_from_gtk_text_view(self)



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/fd9718baa7cf8b4bb8985f10a6c8af3fc133153e

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/fd9718baa7cf8b4bb8985f10a6c8af3fc133153e
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to