2025-04-30 15:58:47 -07:00
|
|
|
using Adw;
|
|
|
|
|
using Gtk;
|
2025-04-30 19:12:00 -07:00
|
|
|
using Gee;
|
2025-04-30 15:58:47 -07:00
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
public class TranscriptView : Adw.Bin
|
2025-04-30 15:58:47 -07:00
|
|
|
{
|
2025-04-30 19:50:36 -07:00
|
|
|
public MessageListModel? model {
|
|
|
|
|
get {
|
|
|
|
|
return _model;
|
|
|
|
|
}
|
|
|
|
|
set {
|
2025-05-14 17:37:23 -07:00
|
|
|
if (_model != null) {
|
|
|
|
|
_model.disconnect(messages_changed_handler_id);
|
|
|
|
|
_model.unwatch_updates();
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 19:50:36 -07:00
|
|
|
_model = value;
|
|
|
|
|
|
2025-05-14 17:37:23 -07:00
|
|
|
if (value != null) {
|
2025-05-03 23:39:21 -07:00
|
|
|
// Reset scroll position
|
|
|
|
|
scrolled_window.vadjustment = new Gtk.Adjustment(0, 0, 0, 0, 0, 0);
|
|
|
|
|
|
2025-05-14 17:37:23 -07:00
|
|
|
weak TranscriptView self = this;
|
|
|
|
|
messages_changed_handler_id = value.messages_changed.connect(() => {
|
|
|
|
|
self.reload_messages();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
value.load_messages();
|
2025-04-30 19:50:36 -07:00
|
|
|
} else {
|
2025-05-14 17:37:23 -07:00
|
|
|
transcript_drawing_area.set_messages(new ArrayList<Message>());
|
2025-04-30 19:50:36 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-03 23:26:53 -07:00
|
|
|
public string title {
|
|
|
|
|
get { return title_label.label; }
|
|
|
|
|
set { title_label.label = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 19:50:36 -07:00
|
|
|
private MessageListModel? _model = null;
|
2025-04-30 15:58:47 -07:00
|
|
|
private Adw.ToolbarView container;
|
2025-05-03 23:26:53 -07:00
|
|
|
private Label title_label = new Label("Messages");
|
2025-04-30 15:58:47 -07:00
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
private TranscriptDrawingArea transcript_drawing_area = new TranscriptDrawingArea();
|
2025-04-30 15:58:47 -07:00
|
|
|
private ScrolledWindow scrolled_window = new ScrolledWindow();
|
2025-05-14 17:37:23 -07:00
|
|
|
private ulong messages_changed_handler_id = 0;
|
2025-06-06 20:03:02 -07:00
|
|
|
private bool needs_reload = false;
|
2025-04-30 15:58:47 -07:00
|
|
|
|
2025-05-14 17:37:23 -07:00
|
|
|
public TranscriptView() {
|
2025-04-30 15:58:47 -07:00
|
|
|
container = new Adw.ToolbarView();
|
|
|
|
|
set_child(container);
|
|
|
|
|
|
2025-05-03 22:47:56 -07:00
|
|
|
scrolled_window.set_child(transcript_drawing_area);
|
2025-04-30 15:58:47 -07:00
|
|
|
scrolled_window.add_css_class("message-list-scroller");
|
|
|
|
|
container.set_content(scrolled_window);
|
|
|
|
|
|
|
|
|
|
var header_bar = new Adw.HeaderBar();
|
2025-05-03 23:26:53 -07:00
|
|
|
header_bar.set_title_widget(title_label);
|
2025-04-30 15:58:47 -07:00
|
|
|
container.add_top_bar(header_bar);
|
2025-06-06 20:03:02 -07:00
|
|
|
|
|
|
|
|
Repository.get_instance().attachment_downloaded.connect((attachment_guid) => {
|
|
|
|
|
debug("Attachment downloaded: %s", attachment_guid);
|
|
|
|
|
|
|
|
|
|
// See if this attachment is part of this transcript.
|
|
|
|
|
bool contains_attachment = false;
|
|
|
|
|
foreach (var message in _model.messages) {
|
|
|
|
|
foreach (var attachment in message.attachments) {
|
|
|
|
|
if (attachment.guid == attachment_guid) {
|
|
|
|
|
contains_attachment = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (contains_attachment && !needs_reload) {
|
|
|
|
|
debug("Queueing reload of messages for attachment download");
|
|
|
|
|
|
|
|
|
|
needs_reload = true;
|
|
|
|
|
GLib.Idle.add(() => {
|
|
|
|
|
if (needs_reload) {
|
|
|
|
|
debug("Reloading messages for attachment download");
|
|
|
|
|
model.load_messages();
|
|
|
|
|
needs_reload = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}, GLib.Priority.HIGH);
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-04-30 19:50:36 -07:00
|
|
|
}
|
2025-04-30 15:58:47 -07:00
|
|
|
|
2025-04-30 19:50:36 -07:00
|
|
|
private void reload_messages() {
|
2025-05-03 23:19:15 -07:00
|
|
|
transcript_drawing_area.show_sender = _model.is_group_chat;
|
2025-05-03 22:47:56 -07:00
|
|
|
transcript_drawing_area.set_messages(_model.messages);
|
2025-04-30 15:58:47 -07:00
|
|
|
}
|
|
|
|
|
}
|