Skip to content
Snippets Groups Projects
Commit 9a8664e4 authored by Daniel Brötzmann's avatar Daniel Brötzmann Committed by Philipp Hörist
Browse files

HistoryWindow: Use ConversationView

parent b6998e83
No related branches found
No related tags found
No related merge requests found
......@@ -25,10 +25,8 @@
from gajim.gui.dialogs import ShortcutsWindow
from gajim.gui.about import AboutDialog
from gajim.gui.history import HistoryWindow
from gajim.gui.discovery import ServiceDiscoveryWindow
from gajim.gui.util import open_window
from gajim.gui.util import get_app_window
# General Actions
......@@ -310,13 +308,7 @@ def on_browse_history(_action, param):
jid = dict_.get('jid')
account = dict_.get('account')
window = get_app_window(HistoryWindow)
if window is None:
HistoryWindow(jid, account)
else:
window.present()
if jid is not None and account is not None:
window.open_history(jid, account)
open_window('HistoryWindow', account=account, jid=jid)
def on_groupchat_join(_action, param):
......
......@@ -420,7 +420,7 @@ def get_last_conversation_line(self, account, jid):
return self._con.execute(sql, tuple(jids)).fetchone()
@timeit
def get_conversation_for_date(self, account, jid, date):
def get_messages_for_date(self, account, jid, date):
"""
Load the complete conversation with a given jid on a specific date
......@@ -435,21 +435,26 @@ def get_conversation_for_date(self, account, jid, date):
"""
jids = self._get_family_jids(account, jid)
account_id = self.get_account_id(account)
delta = datetime.timedelta(
hours=23, minutes=59, seconds=59, microseconds=999999)
date_ts = date.timestamp()
delta_ts = (date + delta).timestamp()
sql = '''
SELECT contact_name, time, kind, show, message, subject,
additional_data, log_line_id
FROM logs NATURAL JOIN jids WHERE jid IN ({jids})
AND account_id = {account_id}
AND time BETWEEN ? AND ?
ORDER BY time, log_line_id
'''.format(jids=', '.join('?' * len(jids)))
ORDER BY time DESC, log_line_id DESC
'''.format(jids=', '.join('?' * len(jids)),
account_id=account_id)
return self._con.execute(sql, tuple(jids) +
(date.timestamp(),
(date + delta).timestamp())).fetchall()
return self._con.execute(
sql,
tuple(jids) + (date_ts, delta_ts)).fetchall()
@timeit
def search_log(self, account, jid, query, date=None):
......
This diff is collapsed.
......@@ -59,6 +59,9 @@ .conversation-row grid textview text {
.conversation-mention-highlight {
background-color: rgb(255, 215, 194);
}
.conversation-search-highlight {
background-color: rgb(194, 215, 255);
}
.conversation-system-row {
padding: 18px;
}
......
......@@ -37,6 +37,7 @@ def __init__(self, account, widget='label', history_mode=False):
self.kind = None
self.name = None
self.message_id = None
self.log_line_id = None
self.text = ''
self.get_style_context().add_class('conversation-row')
......@@ -98,8 +99,9 @@ def create_name_widget(name: str, kind: str,
@wrap_with_event_box
class MoreMenuButton(Gtk.MenuButton):
def __init__(self, row):
def __init__(self, row, history_mode=False):
Gtk.MenuButton.__init__(self)
self._history_mode = history_mode
self.set_valign(Gtk.Align.START)
self.set_halign(Gtk.Align.END)
......@@ -116,17 +118,18 @@ def _create_popover(self, row):
menu_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
menu_box.get_style_context().add_class('padding-6')
quote_button = Gtk.ModelButton()
quote_button.set_halign(Gtk.Align.START)
quote_button.connect('clicked', row._on_quote_message)
quote_button.set_label(_('Quote…'))
quote_button.set_image(Gtk.Image.new_from_icon_name(
'mail-reply-sender-symbolic', Gtk.IconSize.MENU))
menu_box.add(quote_button)
if not self._history_mode:
quote_button = Gtk.ModelButton()
quote_button.set_halign(Gtk.Align.START)
quote_button.connect('clicked', row.on_quote_message)
quote_button.set_label(_('Quote…'))
quote_button.set_image(Gtk.Image.new_from_icon_name(
'mail-reply-sender-symbolic', Gtk.IconSize.MENU))
menu_box.add(quote_button)
copy_button = Gtk.ModelButton()
copy_button.set_halign(Gtk.Align.START)
copy_button.connect('clicked', row._on_copy_message)
copy_button.connect('clicked', row.on_copy_message)
copy_button.set_label(_('Copy'))
copy_button.set_image(Gtk.Image.new_from_icon_name(
'edit-copy-symbolic', Gtk.IconSize.MENU))
......
......@@ -45,7 +45,8 @@ def __init__(self,
marker=None,
error=None,
encryption_enabled=False,
history_mode=False):
history_mode=False,
log_line_id=None):
# other_tags_for_name contained 'marked', 'bold' and
# 'muc_nickname_color_', which are now derived from
......@@ -58,6 +59,7 @@ def __init__(self,
self.type = 'chat'
self.timestamp = timestamp
self.message_id = message_id
self.log_line_id = log_line_id
self.kind = kind
self.name = name or ''
self.text = text
......@@ -124,19 +126,19 @@ def __init__(self,
bottom_box = Gtk.Box(spacing=6)
bottom_box.add(self.textview)
bottom_box.add(MoreMenuButton(self))
bottom_box.add(MoreMenuButton(self, history_mode=history_mode))
self.grid.attach(avatar_placeholder, 0, 0, 1, 2)
self.grid.attach(self._meta_box, 1, 0, 1, 1)
self.grid.attach(bottom_box, 1, 1, 1, 1)
def _on_copy_message(self, _widget):
def on_copy_message(self, _widget):
timestamp = self.timestamp.strftime('%x, %X')
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip.set_text(
f'{timestamp} - {self.name}: {self.textview.get_text()}', -1)
def _on_quote_message(self, _widget):
def on_quote_message(self, _widget):
self.get_parent().on_quote(self.textview.get_text())
def _get_encryption_image(self, additional_data, encryption_enabled=None):
......
......@@ -22,24 +22,31 @@
class ScrollHintRow(BaseRow):
def __init__(self, account):
def __init__(self, account, history_mode=False):
BaseRow.__init__(self, account)
self.type = 'system'
self.timestamp = datetime.fromtimestamp(0)
self.get_style_context().add_class('conversation-system-row')
self._button = Gtk.Button.new_from_icon_name(
'go-up-symbolic', Gtk.IconSize.BUTTON)
self._button.set_tooltip_text(_('Load more messages'))
self._button.connect('clicked', self._on_load_history)
self.grid.attach(self._button, 0, 0, 1, 1)
self.get_style_context().add_class('conversation-system-row')
self.label.set_text(_('Scroll up to load more chat history…'))
self.label.set_halign(Gtk.Align.CENTER)
self.label.set_hexpand(True)
self.label.get_style_context().add_class(
'conversation-meta')
if history_mode:
self.label.set_text(_('Use the calendar to select a specific date'))
self.grid.attach(self.label, 0, 1, 1, 1)
return
self.label.set_text(_('Scroll up to load more chat history…'))
self.grid.attach(self.label, 0, 1, 1, 1)
self._button = Gtk.Button.new_from_icon_name(
'go-up-symbolic', Gtk.IconSize.BUTTON)
self._button.set_tooltip_text(_('Load more messages'))
self._button.connect('clicked', self._on_load_history)
self.grid.attach(self._button, 0, 0, 1, 1)
def _on_load_history(self, _button):
self.get_parent().emit('load-history', 30)
......@@ -95,7 +95,7 @@ def __init__(self, account, contact, history_mode=False):
self._last_incoming_timestamp = datetime.fromtimestamp(0)
# Insert the very first row, containing the scroll hint and load button
self.add(ScrollHintRow(self._account))
self.add(ScrollHintRow(self._account, history_mode=self._history_mode))
self._timestamps_inserted.append(datetime.fromtimestamp(0))
def clear(self):
......@@ -121,6 +121,7 @@ def add_message(self,
name,
timestamp,
other_text_tags=None,
log_line_id=None,
message_id=None,
correct_id=None,
display_marking=None,
......@@ -153,7 +154,8 @@ def add_message(self,
if other_text_tags is None:
other_text_tags = []
if kind in ('status', 'info') or subject:
if (kind in ('status', 'info') or
(subject and self._contact.is_groupchat)):
message = InfoMessageRow(
self._account,
time_,
......@@ -191,7 +193,8 @@ def add_message(self,
marker=marker,
error=error,
encryption_enabled=self.encryption_enabled,
history_mode=self._history_mode)
history_mode=self._history_mode,
log_line_id=log_line_id)
self._insert_message(message, time_, kind, history)
......@@ -382,12 +385,22 @@ def _reduce_message_count(self):
self.first_message_timestamp = None
self._row_count -= 1
def _get_row_by_id(self, id_):
def _get_row_by_message_id(self, id_):
for row in self.get_children():
if row.message_id == id_:
return row
return None
def get_row_by_log_line_id(self, log_line_id):
for row in self.get_children():
if row.log_line_id == log_line_id:
return row
return None
def iter_rows(self):
for row in self.get_children():
yield row
def _get_first_chat_row(self):
for row in self.get_children():
if row.type == 'chat':
......@@ -395,7 +408,7 @@ def _get_first_chat_row(self):
return None
def set_read_marker(self, id_):
message_row = self._get_row_by_id(id_)
message_row = self._get_row_by_message_id(id_)
if message_row is None:
return
......@@ -476,7 +489,7 @@ def scroll_to_end(self, force=False):
def correct_message(self, correct_id, message_id, text,
other_text_tags, kind, name, additional_data=None):
message_row = self._get_row_by_id(correct_id)
message_row = self._get_row_by_message_id(correct_id)
if message_row is not None:
message_row.set_correction(
message_id, text, other_text_tags, kind, name,
......@@ -484,12 +497,12 @@ def correct_message(self, correct_id, message_id, text,
message_row.set_merged(False)
def show_receipt(self, id_):
message_row = self._get_row_by_id(id_)
message_row = self._get_row_by_message_id(id_)
if message_row is not None:
message_row.set_receipt()
def show_error(self, id_, error):
message_row = self._get_row_by_id(id_)
message_row = self._get_row_by_message_id(id_)
if message_row is not None:
message_row.set_error(to_user_string(error))
message_row.set_merged(False)
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment