about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-11-01 17:53:59 +0100
committerMichael Vetter <jubalh@iodoru.org>2019-11-01 17:53:59 +0100
commitbc282ef569ecd068cc8d523601264d9f4beefafe (patch)
treeab8f0e1cbe656b20a7f25c377cecdb3375db88c5 /src/ui
parentd5212d859389f14409af99b2708c4d002662fb92 (diff)
downloadprofani-tty-bc282ef569ecd068cc8d523601264d9f4beefafe.tar.gz
Move id from DeliveryReceipt to ProfBuffEntry struct
XEP-0184: Message Delivery Receipts, *requires* the id attribute.
Generally this is not the case.
For this reason the id was only present in the DeliveryReceipt struct
since it was only used for XEP-0184.

For https://github.com/profanity-im/profanity/issues/660 XEP-0313 MAM
and https://github.com/profanity-im/profanity/issues/805 XEP-0308 Last Message Correction
we will also need the id.

So in preparation for further work let's move the id to the general
ProfBuffEntry.

We will need to adapt code so that we actually always write the ID if we
receive one.
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/buffer.c13
-rw-r--r--src/ui/buffer.h7
-rw-r--r--src/ui/window.c30
3 files changed, 24 insertions, 26 deletions
diff --git a/src/ui/buffer.c b/src/ui/buffer.c
index b933ac8c..b36f19e7 100644
--- a/src/ui/buffer.c
+++ b/src/ui/buffer.c
@@ -80,7 +80,7 @@ buffer_free(ProfBuff buffer)
 
 void
 buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time,
-    int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt)
+    int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt, const char *const id)
 {
     ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
     e->show_char = show_char;
@@ -91,6 +91,7 @@ buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *
     e->from = from ? strdup(from) : NULL;
     e->message = strdup(message);
     e->receipt = receipt;
+    e->id = strdup(id);
 
     if (g_slist_length(buffer->entries) == BUFF_SIZE) {
         _free_entry(buffer->entries->data);
@@ -106,7 +107,7 @@ buffer_mark_received(ProfBuff buffer, const char *const id)
     GSList *entries = buffer->entries;
     while (entries) {
         ProfBuffEntry *entry = entries->data;
-        if (entry->receipt && g_strcmp0(entry->receipt->id, id) == 0) {
+        if (entry->receipt && g_strcmp0(entry->id, id) == 0) {
             if (!entry->receipt->received) {
                 entry->receipt->received = TRUE;
                 return TRUE;
@@ -131,7 +132,7 @@ buffer_get_entry_by_id(ProfBuff buffer, const char *const id)
     GSList *entries = buffer->entries;
     while (entries) {
         ProfBuffEntry *entry = entries->data;
-        if (entry->receipt && g_strcmp0(entry->receipt->id, id) == 0) {
+        if (g_strcmp0(entry->id, id) == 0) {
             return entry;
         }
         entries = g_slist_next(entries);
@@ -145,10 +146,8 @@ _free_entry(ProfBuffEntry *entry)
 {
     free(entry->message);
     free(entry->from);
+    free(entry->id);
+    free(entry->receipt);
     g_date_time_unref(entry->time);
-    if (entry->receipt) {
-        free(entry->receipt->id);
-        free(entry->receipt);
-    }
     free(entry);
 }
diff --git a/src/ui/buffer.h b/src/ui/buffer.h
index 243b003a..b11a5381 100644
--- a/src/ui/buffer.h
+++ b/src/ui/buffer.h
@@ -41,7 +41,6 @@
 #include "config/theme.h"
 
 typedef struct delivery_receipt_t {
-    char *id;
     gboolean received;
 } DeliveryReceipt;
 
@@ -54,14 +53,16 @@ typedef struct prof_buff_entry_t {
     char *from;
     char *message;
     DeliveryReceipt *receipt;
+    // message id, in case we have it
+    char *id;
 } ProfBuffEntry;
 
 typedef struct prof_buff_t *ProfBuff;
 
 ProfBuff buffer_create();
 void buffer_free(ProfBuff buffer);
-void buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item,
-    const char *const from, const char *const message, DeliveryReceipt *receipt);
+void buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time,
+    int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt, const char *const id);
 int buffer_size(ProfBuff buffer);
 ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
 ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id);
diff --git a/src/ui/window.c b/src/ui/window.c
index 631b4468..bb68f035 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1102,7 +1102,7 @@ win_println_them_message(ProfWin *window, char ch, int flags, const char *const
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, ch, 0, timestamp, flags | NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, ch, 0, timestamp, flags | NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL, NULL);
 
     _win_print(window, ch, 0, timestamp, flags | NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1122,7 +1122,7 @@ win_println_me_message(ProfWin *window, char ch, const char *const me, const cha
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL, NULL);
 
     _win_print(window, ch, 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1142,7 +1142,7 @@ win_print_outgoing(ProfWin *window, const char ch, const char *const message, ..
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL, NULL);
 
     _win_print(window, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1162,7 +1162,7 @@ win_print_history(ProfWin *window, GDateTime *timestamp, const char *const messa
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, '-', 0, timestamp, 0, THEME_TEXT_HISTORY, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, '-', 0, timestamp, 0, THEME_TEXT_HISTORY, "", fmt_msg->str, NULL, NULL);
     _win_print(window, '-', 0, timestamp, 0, THEME_TEXT_HISTORY, "", fmt_msg->str, NULL);
 
     inp_nonblocking(TRUE);
@@ -1182,7 +1182,7 @@ win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *c
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, ch, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, ch, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL, NULL);
 
     _win_print(window, ch, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1202,7 +1202,7 @@ win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, ch, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, ch, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL, NULL);
 
     _win_print(window, ch, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1222,7 +1222,7 @@ win_println_indent(ProfWin *window, int pad, const char *const message, ...)
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, '-', pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, '-', pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL, NULL);
 
     _win_print(window, '-', pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1242,7 +1242,7 @@ win_append(ProfWin *window, theme_item_t theme_item, const char *const message,
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL, NULL);
 
     _win_print(window, '-', 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1262,7 +1262,7 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL, NULL);
 
     _win_print(window, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1282,7 +1282,7 @@ win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL, NULL);
 
     _win_print(window, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1302,7 +1302,7 @@ win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *con
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL, NULL);
 
     _win_print(window, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL);
     inp_nonblocking(TRUE);
@@ -1319,16 +1319,14 @@ win_print_http_upload(ProfWin *window, const char *const message, char *url)
 }
 
 void
-win_print_with_receipt(ProfWin *window, const char show_char, const char *const from, const char *const message,
-    char *id)
+win_print_with_receipt(ProfWin *window, const char show_char, const char *const from, const char *const message, char *id)
 {
     GDateTime *time = g_date_time_new_now_local();
 
     DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t));
-    receipt->id = strdup(id);
     receipt->received = FALSE;
 
-    buffer_append(window->layout->buffer, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt);
+    buffer_append(window->layout->buffer, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt, id);
     _win_print(window, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt);
     // TODO: cross-reference.. this should be replaced by a real event-based system
     inp_nonblocking(TRUE);
@@ -1376,7 +1374,7 @@ _win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *ti
     GString *fmt_msg = g_string_new(NULL);
     g_string_vprintf(fmt_msg, message, arg);
 
-    buffer_append(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
+    buffer_append(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL, NULL);
 
     _win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL);
     inp_nonblocking(TRUE);