Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
b4c09866
by wurstsalat at 2021-12-14T23:10:45+01:00
5 changed files:
- gajim/gtk/chat_page.py
- gajim/gtk/chat_stack.py
- gajim/gtk/controls/base.py
- gajim/gtk/conversation/scrolled.py
- gajim/gtk/main.py
Changes:
| ... | ... | @@ -325,9 +325,8 @@ def get_active_control(self) -> Optional[ControlType]: |
| 325 | 325 |
return None
|
| 326 | 326 |
return self.get_control(chat.account, chat.jid)
|
| 327 | 327 |
|
| 328 |
- def is_chat_idle(self, account: str, jid: JID) -> bool:
|
|
| 329 |
- entry = self._chat_idle_time.get((account, jid))
|
|
| 330 |
- return entry is not None
|
|
| 328 |
+ def is_chat_loaded(self, account: str, jid: JID) -> bool:
|
|
| 329 |
+ return self._chat_stack.is_chat_loaded(account, jid)
|
|
| 331 | 330 |
|
| 332 | 331 |
def get_controls(self, account: Optional[str]
|
| 333 | 332 |
) -> Generator[ControlType, None, None]:
|
| ... | ... | @@ -112,6 +112,12 @@ def show_chat(self, account: str, jid: JID) -> None: |
| 112 | 112 |
|
| 113 | 113 |
GLib.idle_add(control.focus)
|
| 114 | 114 |
|
| 115 |
+ def is_chat_loaded(self, account, jid) -> bool:
|
|
| 116 |
+ control = self.get_control(account, jid)
|
|
| 117 |
+ if control is None:
|
|
| 118 |
+ return False
|
|
| 119 |
+ return control.is_chat_loaded
|
|
| 120 |
+ |
|
| 115 | 121 |
def unload_chat(self, account: str, jid: JID) -> None:
|
| 116 | 122 |
control = self.get_control(account, jid)
|
| 117 | 123 |
if control is None:
|
| ... | ... | @@ -225,8 +225,8 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None: |
| 225 | 225 |
|
| 226 | 226 |
self.xml.hbox.pack_start(self.msg_scrolledwindow, True, True, 0)
|
| 227 | 227 |
|
| 228 |
- # Used for initial message row fetching in ConversationView
|
|
| 229 |
- self._initial_fetch_finished: bool = False
|
|
| 228 |
+ # Keeps track of whether the ConversationView is populated
|
|
| 229 |
+ self._chat_loaded: bool = False
|
|
| 230 | 230 |
|
| 231 | 231 |
# the following vars are used to keep history of user's messages
|
| 232 | 232 |
self.sent_history: List[str] = []
|
| ... | ... | @@ -511,8 +511,7 @@ def _sec_labels_received(self, event): |
| 511 | 511 |
|
| 512 | 512 |
def delegate_action(self, action: str) -> int:
|
| 513 | 513 |
if action == 'clear-chat':
|
| 514 |
- self.conversation_view.clear()
|
|
| 515 |
- self._scrolled_view.reset()
|
|
| 514 |
+ self.reset_view()
|
|
| 516 | 515 |
return Gdk.EVENT_STOP
|
| 517 | 516 |
|
| 518 | 517 |
if action == 'delete-line':
|
| ... | ... | @@ -1123,10 +1122,10 @@ def save_message(self, message: str, msg_type: str) -> None: |
| 1123 | 1122 |
self.received_history_pos = pos
|
| 1124 | 1123 |
|
| 1125 | 1124 |
def _allow_add_message(self) -> bool:
|
| 1125 |
+ # Only add messages if the view is already populated
|
|
| 1126 |
+ chat_loaded = app.window.is_chat_loaded(self.account, self.contact.jid)
|
|
| 1126 | 1127 |
lower_complete = self._scrolled_view.get_lower_complete()
|
| 1127 |
- chat_idle = app.window.is_chat_idle(self.account, self.contact.jid)
|
|
| 1128 |
- chat_selected = bool(app.window.get_active_control() is not None)
|
|
| 1129 |
- return lower_complete and (chat_idle or chat_selected)
|
|
| 1128 |
+ return chat_loaded and lower_complete
|
|
| 1130 | 1129 |
|
| 1131 | 1130 |
def add_info_message(self, text: str) -> None:
|
| 1132 | 1131 |
self.conversation_view.add_info_message(text)
|
| ... | ... | @@ -1315,9 +1314,9 @@ def update_text_tags(self): |
| 1315 | 1314 |
self.conversation_view.update_text_tags()
|
| 1316 | 1315 |
|
| 1317 | 1316 |
def set_control_active(self, state: bool) -> None:
|
| 1318 |
- if not self._initial_fetch_finished:
|
|
| 1317 |
+ if not self._chat_loaded:
|
|
| 1319 | 1318 |
self.fetch_n_lines_history(self._scrolled_view, True, 20)
|
| 1320 |
- self._initial_fetch_finished = True
|
|
| 1319 |
+ self._chat_loaded = True
|
|
| 1321 | 1320 |
|
| 1322 | 1321 |
if state:
|
| 1323 | 1322 |
self.set_emoticon_popover()
|
| ... | ... | @@ -1332,17 +1331,21 @@ def set_control_active(self, state: bool) -> None: |
| 1332 | 1331 |
self._client.get_module('Chatstate').set_chatstate(
|
| 1333 | 1332 |
self.contact, Chatstate.INACTIVE)
|
| 1334 | 1333 |
|
| 1334 |
+ @property
|
|
| 1335 |
+ def is_chat_loaded(self) -> bool:
|
|
| 1336 |
+ return self._chat_loaded
|
|
| 1337 |
+ |
|
| 1335 | 1338 |
def reset_view(self) -> None:
|
| 1336 |
- self._initial_fetch_finished = False
|
|
| 1339 |
+ self._chat_loaded = False
|
|
| 1337 | 1340 |
self.conversation_view.clear()
|
| 1341 |
+ self._scrolled_view.reset()
|
|
| 1338 | 1342 |
|
| 1339 | 1343 |
def get_autoscroll(self) -> bool:
|
| 1340 | 1344 |
return self._scrolled_view.get_autoscroll()
|
| 1341 | 1345 |
|
| 1342 | 1346 |
def scroll_to_end(self, force: bool = False) -> None:
|
| 1343 | 1347 |
# Clear view and reload conversation
|
| 1344 |
- self.conversation_view.clear()
|
|
| 1345 |
- self._scrolled_view.reset()
|
|
| 1348 |
+ self.reset_view()
|
|
| 1346 | 1349 |
self.conversation_view.scroll_to_end(force)
|
| 1347 | 1350 |
|
| 1348 | 1351 |
def scroll_to_message(self, log_line_id: str, timestamp: float) -> None:
|
| ... | ... | @@ -1350,8 +1353,7 @@ def scroll_to_message(self, log_line_id: str, timestamp: float) -> None: |
| 1350 | 1353 |
if row is None:
|
| 1351 | 1354 |
# Clear view and reload conversation around timestamp
|
| 1352 | 1355 |
self.conversation_view.lock()
|
| 1353 |
- self.conversation_view.clear()
|
|
| 1354 |
- self._scrolled_view.reset()
|
|
| 1356 |
+ self.reset_view()
|
|
| 1355 | 1357 |
before, at_after = app.storage.archive.get_conversation_around(
|
| 1356 | 1358 |
self.account, self.contact.jid, timestamp)
|
| 1357 | 1359 |
self.add_messages(before)
|
| ... | ... | @@ -111,9 +111,12 @@ def _on_adj_upper_changed(self, |
| 111 | 111 |
if self._requesting == 'before':
|
| 112 | 112 |
adj.set_value(adj.get_value() + diff)
|
| 113 | 113 |
|
| 114 |
- self._lower_complete = True
|
|
| 115 |
- self._autoscroll = True
|
|
| 116 |
- self.emit('autoscroll-changed', self._autoscroll)
|
|
| 114 |
+ if upper == adj.get_page_size():
|
|
| 115 |
+ # There is no scrollbar
|
|
| 116 |
+ self.emit('request-history', True)
|
|
| 117 |
+ self._lower_complete = True
|
|
| 118 |
+ self._autoscroll = True
|
|
| 119 |
+ self.emit('autoscroll-changed', self._autoscroll)
|
|
| 117 | 120 |
|
| 118 | 121 |
self._requesting = None
|
| 119 | 122 |
|
| ... | ... | @@ -517,8 +517,8 @@ def get_controls(self, account: Optional[str] = None |
| 517 | 517 |
def get_active_control(self) -> Optional[ControlType]:
|
| 518 | 518 |
return self._chat_page.get_active_control()
|
| 519 | 519 |
|
| 520 |
- def is_chat_idle(self, account: str, jid: JID) -> bool:
|
|
| 521 |
- return self._chat_page.is_chat_idle(account, jid)
|
|
| 520 |
+ def is_chat_loaded(self, account: str, jid: JID) -> bool:
|
|
| 521 |
+ return self._chat_page.is_chat_loaded(account, jid)
|
|
| 522 | 522 |
|
| 523 | 523 |
def chat_exists(self, account: str, jid: JID) -> bool:
|
| 524 | 524 |
return self._chat_page.chat_exists(account, jid)
|