Private
Public Access
1
0

implements sending

This commit is contained in:
2025-05-02 15:09:12 -07:00
parent f80d1a609b
commit 410182eab8
10 changed files with 135 additions and 11 deletions

View File

@@ -4,7 +4,7 @@ using Gtk;
public class MainWindow : Adw.ApplicationWindow
{
private ConversationListView conversation_list_view;
private MessageListView message_list_view;
private TranscriptView transcript_view;
public MainWindow () {
Object (title: "Kordophone");
@@ -19,16 +19,33 @@ public class MainWindow : Adw.ApplicationWindow
var conversation_list_page = new NavigationPage (conversation_list_view, "Conversations");
split_view.sidebar = conversation_list_page;
message_list_view = new MessageListView (new MessageListModel ("123"));
var message_list_page = new NavigationPage (message_list_view, "Messages");
split_view.content = message_list_page;
transcript_view = new TranscriptView ();
transcript_view.on_send.connect (on_transcript_send);
var transcript_page = new NavigationPage (transcript_view, "Transcript");
split_view.content = transcript_page;
}
private void conversation_selected(string? conversation_guid) {
if (conversation_guid == null) {
message_list_view.model = null;
transcript_view.message_list.model = null;
} else {
message_list_view.model = new MessageListModel (conversation_guid);
transcript_view.message_list.model = new MessageListModel (conversation_guid);
}
}
private void on_transcript_send(string message) {
if (transcript_view.message_list.model == null) {
GLib.warning("No conversation selected");
return;
}
var selected_conversation = transcript_view.message_list.model.conversation_guid;
if (selected_conversation == null) {
GLib.warning("No conversation selected");
return;
}
Repository.get_instance().send_message(selected_conversation, message);
}
}

View File

@@ -16,6 +16,7 @@ public class ConversationListModel : Object, ListModel
});
Repository.get_instance().conversations_updated.connect(load_conversations);
Repository.get_instance().messages_updated.connect(load_conversations);
}
public void load_conversations() {

View File

@@ -31,6 +31,8 @@ sources = [
'models/conversation.vala',
'models/message.vala',
'transcript-view/transcript-view.vala',
]
executable('kordophone',

View File

@@ -14,7 +14,7 @@ private struct MessageLayoutConstants {
tail_curve_offset = 2.5f / scale_factor;
tail_side_offset = 0.0f / scale_factor;
tail_bottom_padding = 4.0f / scale_factor;
corner_radius = 32.0f / scale_factor;
corner_radius = 24.0f / scale_factor;
text_padding = 18.0f / scale_factor;
}
}

View File

@@ -9,7 +9,7 @@ public class MessageListModel : Object, ListModel
owned get { return _messages.read_only_view; }
}
private string _conversation_guid;
public string conversation_guid { get; private set; }
private SortedSet<Message> _messages;
public MessageListModel(string conversation_guid) {
@@ -19,12 +19,12 @@ public class MessageListModel : Object, ListModel
});
Repository.get_instance().messages_updated.connect(got_messages_updated);
_conversation_guid = conversation_guid;
this.conversation_guid = conversation_guid;
}
public void load_messages() {
try {
Message[] messages = Repository.get_instance().get_messages(_conversation_guid);
Message[] messages = Repository.get_instance().get_messages(conversation_guid);
// Clear existing set
uint old_count = _messages.size;
@@ -56,7 +56,7 @@ public class MessageListModel : Object, ListModel
}
private void got_messages_updated(string conversation_guid) {
if (conversation_guid == _conversation_guid) {
if (conversation_guid == this.conversation_guid) {
load_messages();
}
}

View File

@@ -18,3 +18,14 @@
.message-drawing-area {
color: darker(@accent_bg_color);
}
.message-input-box {
margin-bottom: 14px;
margin-top: 14px;
margin-left: 14px;
margin-right: 14px;
}
.message-input-entry {
font-size: 1.1rem;
}

View File

@@ -32,6 +32,9 @@ namespace DBusService {
[DBus (name = "GetConversations")]
public abstract GLib.HashTable<string, GLib.Variant>[] get_conversations() throws DBusError, IOError;
[DBus (name = "SyncConversationList")]
public abstract void sync_conversation_list() throws DBusError, IOError;
[DBus (name = "SyncAllConversations")]
public abstract void sync_all_conversations() throws DBusError, IOError;
@@ -41,9 +44,15 @@ namespace DBusService {
[DBus (name = "ConversationsUpdated")]
public signal void conversations_updated();
[DBus (name = "DeleteAllConversations")]
public abstract void delete_all_conversations() throws DBusError, IOError;
[DBus (name = "GetMessages")]
public abstract GLib.HashTable<string, GLib.Variant>[] get_messages(string conversation_id, string last_message_id) throws DBusError, IOError;
[DBus (name = "SendMessage")]
public abstract string send_message(string conversation_id, string text) throws DBusError, IOError;
[DBus (name = "MessagesUpdated")]
public signal void messages_updated(string conversation_id);
}

View File

@@ -24,6 +24,11 @@
</arg>
</method>
<method name="SyncConversationList">
<annotation name="org.freedesktop.DBus.DocString"
value="Initiates a background sync of the conversation list with the server."/>
</method>
<method name="SyncAllConversations">
<annotation name="org.freedesktop.DBus.DocString"
value="Initiates a background sync of all conversations with the server."/>
@@ -40,6 +45,11 @@
value="Emitted when the list of conversations is updated."/>
</signal>
<method name="DeleteAllConversations">
<annotation name="org.freedesktop.DBus.DocString"
value="Deletes all conversations from the database."/>
</method>
<!-- Messages -->
<method name="GetMessages">
@@ -48,6 +58,15 @@
<arg type="aa{sv}" direction="out" name="messages"/>
</method>
<method name="SendMessage">
<arg type="s" name="conversation_id" direction="in"/>
<arg type="s" name="text" direction="in"/>
<arg type="s" name="outgoing_message_id" direction="out"/>
<annotation name="org.freedesktop.DBus.DocString"
value="Sends a message to the server. Returns the outgoing message ID."/>
</method>
<signal name="MessagesUpdated">
<arg type="s" name="conversation_id" direction="in"/>
<annotation name="org.freedesktop.DBus.DocString"

View File

@@ -60,6 +60,14 @@ public class Repository : Object
return returned_messages;
}
public string send_message(string conversation_guid, string message) throws Error {
if (dbus_repository == null) {
throw new Error(1337, 1, "Repository not connected");
}
return dbus_repository.send_message(conversation_guid, message);
}
private async void connect_to_dbus() {
bool connected = false;
const string path = "/net/buzzert/kordophonecd/daemon";

View File

@@ -0,0 +1,57 @@
using Gtk;
using Adw;
class TranscriptView : Adw.Bin {
public MessageListView message_list;
public Entry message_entry;
public signal void on_send(string message);
private Box container;
private Button send_button;
public TranscriptView () {
container = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
set_child (container);
// Create message list view
message_list = new MessageListView();
message_list.set_vexpand(true);
container.append(message_list);
// Create bottom box for input
var input_box = new Box(Orientation.HORIZONTAL, 6);
input_box.add_css_class("message-input-box");
input_box.set_valign(Align.END);
input_box.set_spacing(6);
container.append(input_box);
// Create message entry
message_entry = new Entry();
message_entry.add_css_class("message-input-entry");
message_entry.set_placeholder_text("Type a message...");
message_entry.set_hexpand(true);
message_entry.changed.connect(on_text_changed);
message_entry.activate.connect(on_request_send);
input_box.append(message_entry);
// Create send button
send_button = new Button();
send_button.set_label("Send");
send_button.set_sensitive(false);
send_button.add_css_class("suggested-action");
send_button.clicked.connect(on_request_send);
input_box.append(send_button);
}
private void on_text_changed() {
send_button.set_sensitive(message_entry.text.length > 0);
}
private void on_request_send() {
if (message_entry.text.length > 0) {
on_send(message_entry.text);
message_entry.text = "";
}
}
}