Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: 0a922532 by wurstsalat at 2023-05-21T20:46:26+02:00 fix: SearchView: Don't change search context when switching chats
- Simplify search context determination - Add fail-safe and improve GUI representation of context
Fixes #11533
- - - - -
2 changed files:
- gajim/data/gui/search_view.ui - gajim/gtk/search_view.py
Changes:
===================================== gajim/data/gui/search_view.ui ===================================== @@ -235,7 +235,7 @@ after:yyyy-mm-dd</property> <property name="can-focus">True</property> <property name="receives-default">False</property> <property name="halign">center</property> - <property name="active">True</property> + <property name="active">False</property> <property name="draw-indicator">True</property> </object> <packing>
===================================== gajim/gtk/search_view.py ===================================== @@ -60,7 +60,6 @@ def __init__(self) -> None: self._account: Optional[str] = None self._jid: Optional[JID] = None self._results_iterator: Optional[Iterator[SearchLogRow]] = None - self._scope: str = 'everywhere'
self._first_date: Optional[datetime] = None self._last_date: Optional[datetime] = None @@ -155,16 +154,17 @@ def _on_search(self, entry: Gtk.Entry) -> None:
everywhere = self._ui.search_checkbutton.get_active() context = self._account is not None and self._jid is not None + if not context: + # Started search without context -> show in UI + self._ui.search_checkbutton.set_active(True)
if not context or everywhere: - self._scope = 'everywhere' self._results_iterator = app.storage.archive.search_all_logs( text, from_users=from_filters, before=before_filters, after=after_filters) else: - self._scope = 'contact' self._results_iterator = app.storage.archive.search_log( self._account, self._jid, @@ -193,18 +193,13 @@ def _add_results(self) -> None: accounts = self._get_accounts() assert self._results_iterator is not None for msg in itertools.islice(self._results_iterator, 25): - if self._scope == 'everywhere': - archive_jid = app.storage.archive.get_jid_from_id(msg.jid_id) - if archive_jid is None: - continue - result_row = ResultRow( - msg, - accounts[msg.account_id], - JID.from_string(archive_jid.jid)) - else: - assert self._account is not None - assert self._jid is not None - result_row = ResultRow(msg, self._account, self._jid) + archive_jid = app.storage.archive.get_jid_from_id(msg.jid_id) + if archive_jid is None: + continue + result_row = ResultRow( + msg, + accounts[msg.account_id], + JID.from_string(archive_jid.jid))
self._ui.results_listbox.add(result_row)
@@ -217,24 +212,24 @@ def _on_edge_reached(self, self._add_results()
def _update_calendar(self) -> None: - if self._scope == 'everywhere': + if self._account is None and self._jid is None: self._ui.calendar_button.set_sensitive(False) - else: - self._ui.calendar_button.set_sensitive(True) + return
- first_log = app.storage.archive.get_first_history_timestamp( - self._account, self._jid) - if first_log is None: - return - self._first_date = self._get_date_from_timestamp(first_log) - last_log = app.storage.archive.get_last_history_timestamp( - self._account, self._jid) - if last_log is None: - return - self._last_date = self._get_date_from_timestamp(last_log) + self._ui.calendar_button.set_sensitive(True)
- month = gtk_month(self._last_date.month) - self._ui.calendar.select_month(month, self._last_date.year) + first_log = app.storage.archive.get_first_history_timestamp( + self._account, self._jid) + if first_log is None: + return + self._first_date = self._get_date_from_timestamp(first_log) + last_log = app.storage.archive.get_last_history_timestamp( + self._account, self._jid) + if last_log is None: + return + self._last_date = self._get_date_from_timestamp(last_log) + month = gtk_month(self._last_date.month) + self._ui.calendar.select_month(month, self._last_date.year)
def _on_month_changed(self, calendar: Gtk.Calendar) -> None: # Mark days with history in calendar @@ -361,13 +356,6 @@ def set_focus(self) -> None: def set_context(self, account: Optional[str], jid: Optional[JID]) -> None: self._account = account self._jid = jid - everywhere = bool(jid is None) - self._ui.search_checkbutton.set_active(everywhere) - context = account is not None and jid is not None - if not context or everywhere: - self._scope = 'everywhere' - else: - self._scope = 'contact' self._update_calendar()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/0a922532f6f762e60cbd640ad74587ab0...