From 40aca0691949f41c27704c1f8c4d05fae655cf26 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 21 Aug 2022 11:20:37 +0200 Subject: Implement message sending --- README.txt | 5 ++--- gtk.c | 3 ++- net.c | 17 +++++++++++++++++ net.h | 3 ++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.txt b/README.txt index e056feb..7951483 100644 --- a/README.txt +++ b/README.txt @@ -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] diff --git a/gtk.c b/gtk.c index 1a13bfa..b519a28 100644 --- a/gtk.c +++ b/gtk.c @@ -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; diff --git a/net.c b/net.c index c37847d..dc0f5de 100644 --- a/net.c +++ b/net.c @@ -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); + +} diff --git a/net.h b/net.h index 3a53d9e..3bd184a 100644 --- a/net.h +++ b/net.h @@ -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 -- cgit v1.2.3-70-g09d2