summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-08-19 12:13:32 +0200
committerxengineering <me@xengineering.eu>2022-08-19 12:15:39 +0200
commit8d707d0dd403b4fdef885956f31dad43dee0a91b (patch)
tree7720cfca40f0f22e3a02002b4a3345596a0184b6
parent43aa02ccbd484d8c7cecec7c38c446847b34e007 (diff)
downloadlimox-8d707d0dd403b4fdef885956f31dad43dee0a91b.tar
limox-8d707d0dd403b4fdef885956f31dad43dee0a91b.tar.zst
limox-8d707d0dd403b4fdef885956f31dad43dee0a91b.zip
Implement incoming messages
-rw-r--r--README.txt2
-rw-r--r--gtk.c43
2 files changed, 13 insertions, 32 deletions
diff --git a/README.txt b/README.txt
index a72c917..e056feb 100644
--- a/README.txt
+++ b/README.txt
@@ -17,7 +17,7 @@ Roadmap
- [x] dynamic GUI widgets (like text messages)
- [ ] connection, stream and presence management
- [x] roster request
- - [ ] receiving one-to-one text messages
+ - [x] receiving one-to-one text messages
- [ ] sending one-to-one text messages
- [ ] refactoring
- [ ] persistence with sqlite3
diff --git a/gtk.c b/gtk.c
index 9813531..0f03472 100644
--- a/gtk.c
+++ b/gtk.c
@@ -77,35 +77,6 @@ void send_message() {
//gtk_entry_set_buffer(GTK_ENTRY(chat->text_entry), empty_buffer);
}
-void add_incoming_text_message(char* sender_jid, char* content) {
-
- printf("Trying to add message '%s' to chat with '%s'.\n", content, sender_jid);
-
- // do not add message if list of chats is empty
- //if (chats == NULL) {
- // return;
- //}
-
- // find chat with corresponding JID
- //struct chat* chat = chats;
- //while (true) {
- // const char* jid = gtk_button_get_label(GTK_BUTTON(chat->roster_item));
- // if (strcmp(jid, sender_jid) == 0) {
- // break; // this seems to be the correct chat
- // } else if (chat->next == NULL) {
- // return; // no matching chat found - cannot add message
- // } else {
- // chat = chat->next; // go to next chat in linked list
- // }
- //}
-
-
- // add given message content to the chat
- //GtkWidget* message = gtk_label_new(content);
- //gtk_box_append(GTK_BOX(chat->chat_content_box), message);
-
-}
-
static void build_static_widgets(void) {
// main window with stack
@@ -223,8 +194,18 @@ void gui_add_chat_widget(chat_t* chat) {
void gui_add_message_widget(message_t* message, chat_t* chat) {
- // TODO
- printf("Received from %s:\n%s\n", message->sender_jid, message->content);
+ const char* connector = "\n";
+ char* label_content = malloc(sizeof(char)*(strlen(message->sender_jid)
+ + strlen(connector)
+ + strlen(message->content)));
+ sprintf(label_content, "%s%s%s", message->sender_jid, connector,
+ message->content);
+ GtkWidget* label = gtk_label_new(label_content);
+ gtk_label_set_wrap(GTK_LABEL(label), TRUE);
+ message->widget = (void*)label;
+ gtk_box_append(GTK_BOX(chat->widget), label);
+ free(label_content);
+
}
static void to_chat(chat_t* chat) {