diff options
-rw-r--r-- | README.txt | 5 | ||||
-rw-r--r-- | gtk.c | 3 | ||||
-rw-r--r-- | net.c | 17 | ||||
-rw-r--r-- | net.h | 3 |
4 files changed, 23 insertions, 5 deletions
@@ -12,13 +12,12 @@ Roadmap ------- - [x] build a GTK 4 GUI -- [ ] finish minimal viable product (MVP) to send and receive text messages +- [x] finish minimal viable product (MVP) to send and receive text messages - [x] static GUI widgets - [x] dynamic GUI widgets (like text messages) - - [ ] connection, stream and presence management - [x] roster request - [x] receiving one-to-one text messages - - [ ] sending one-to-one text messages + - [x] sending one-to-one text messages - [ ] refactoring - [ ] persistence with sqlite3 - [ ] XMPP core compliance suite 2022 / client [1] @@ -75,8 +75,9 @@ void send_message(chat_t* chat) { const char* text = gtk_editable_get_text(GTK_EDITABLE(chat_widget->entry)); const char* self = gtk_editable_get_text(GTK_EDITABLE(connector_jid_entry)); - // add message to datastructure + // add message to datastructure and send it data_add_outgoing_message(self, text, chat); + net_send_message(self, text, chat->jid); // clear text input GtkEntryBuffer* buffer; @@ -215,3 +215,20 @@ void net_disconnect(void) { state = DISCONNECTED; } + +void net_send_message(const char* sender, const char* content, + const char* recipient) { + + // TODO what happens if client is disconnected and this function is called? + + char* uuid = xmpp_uuid_gen(ctx); + + xmpp_stanza_t* msg = xmpp_message_new(ctx, "chat", recipient, uuid); + xmpp_stanza_set_from(msg, sender); + xmpp_message_set_body(msg, content); + xmpp_send(conn, msg); + + xmpp_free(ctx, msg); + xmpp_free(ctx, uuid); + +} @@ -9,5 +9,6 @@ void net_quit(void); // disconnect and clean up // interface for the GUI implementation void net_connect(const char* jid, const char* password); void net_disconnect(void); - +void net_send_message(const char* sender, const char* content, + const char* recipient); #endif |