Private
Public Access
1
0

Mark conversation as read on movement

This commit is contained in:
2025-06-18 15:32:37 -07:00
parent a70adbb7f1
commit 3b6666cfc2
5 changed files with 113 additions and 37 deletions

View File

@@ -6,6 +6,9 @@ public class MainWindow : Adw.ApplicationWindow
private ConversationListView conversation_list_view;
private TranscriptContainerView transcript_container_view;
private EventControllerMotion _motion_controller = new EventControllerMotion();
private bool _motion_queued = false;
public MainWindow () {
Object (title: "Kordophone");
@@ -20,14 +23,59 @@ public class MainWindow : Adw.ApplicationWindow
split_view.sidebar = conversation_list_page;
transcript_container_view = new TranscriptContainerView ();
transcript_container_view.on_send.connect (on_transcript_send);
var transcript_page = new NavigationPage (transcript_container_view, "Transcript");
split_view.content = transcript_page;
var show_settings_action = new SimpleAction ("settings", null);
show_settings_action.activate.connect(show_settings);
add_action(show_settings_action);
_motion_controller.motion.connect((x, y) => {
queue_motion();
});
_motion_controller.set_propagation_phase(PropagationPhase.CAPTURE);
split_view.add_controller(_motion_controller);
}
private void queue_motion() {
if (_motion_queued) {
return;
}
if (!is_active) {
return;
}
_motion_queued = true;
GLib.Timeout.add(500, () => {
_motion_queued = false;
on_motion();
return false;
});
}
private void on_motion() {
var selected_conversation = transcript_container_view.transcript_view.model?.conversation;
if (selected_conversation == null) {
return;
}
var list_model = conversation_list_view.conversation_model;
var conversation_in_list = list_model.get_conversation(selected_conversation.guid);
if (conversation_in_list == null) {
return;
}
if (conversation_in_list.unread_count == 0) {
return;
}
try {
GLib.message("Marking conversation as read on motion: %s", selected_conversation.guid);
Repository.get_instance().mark_conversation_as_read(selected_conversation.guid);
} catch (Error e) {
GLib.warning("Failed to mark conversation as read: %s", e.message);
}
}
private void show_settings () {
@@ -40,8 +88,8 @@ public class MainWindow : Adw.ApplicationWindow
if (conversation == null) {
transcript_view.model = null;
} else {
if (transcript_view.model == null || transcript_view.model.conversation_guid != conversation.guid) {
transcript_view.model = new MessageListModel (conversation.guid);
if (transcript_view.model == null || transcript_view.model.conversation.guid != conversation.guid) {
transcript_view.model = new MessageListModel (conversation);
transcript_view.title = conversation.display_name;
try {
@@ -53,29 +101,4 @@ public class MainWindow : Adw.ApplicationWindow
}
}
}
private void on_transcript_send(TranscriptContainerView view) {
var body = view.message_body;
var attachment_guids = view.attachment_guids;
// Strip empty space at the beginning and end of the body
body = body.strip();
if (transcript_container_view.transcript_view.model == null) {
GLib.warning("No conversation selected");
return;
}
var selected_conversation = transcript_container_view.transcript_view.model.conversation_guid;
if (selected_conversation == null) {
GLib.warning("No conversation selected");
return;
}
try {
Repository.get_instance().send_message(selected_conversation, body, attachment_guids.to_array());
} catch (Error e) {
GLib.warning("Failed to send message: %s", e.message);
}
}
}