diff options
author | James Booth <boothj5@gmail.com> | 2015-03-14 16:05:13 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-03-14 16:05:13 +0000 |
commit | 1014244408caa2d74278603dcbece7857e7f7d4b (patch) | |
tree | ab48b145d05f01416c760f58856e0818d88ae845 | |
parent | bc6e32175d703e5cf7b4ed7638ee7b60c521c298 (diff) | |
download | profani-tty-1014244408caa2d74278603dcbece7857e7f7d4b.tar.gz |
Use colouring for message receipts
-rw-r--r-- | src/ui/buffer.c | 25 | ||||
-rw-r--r-- | src/ui/buffer.h | 12 | ||||
-rw-r--r-- | src/ui/core.c | 14 | ||||
-rw-r--r-- | src/ui/window.c | 58 | ||||
-rw-r--r-- | src/ui/window.h | 3 |
5 files changed, 92 insertions, 20 deletions
diff --git a/src/ui/buffer.c b/src/ui/buffer.c index da505867..d16eec76 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -81,7 +81,7 @@ buffer_free(ProfBuff buffer) void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, - int flags, theme_item_t theme_item, const char * const from, const char * const message) + int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt) { ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t)); e->show_char = show_char; @@ -90,6 +90,7 @@ buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, e->time = time; e->from = strdup(from); e->message = strdup(message); + e->receipt = receipt; if (g_slist_length(buffer->entries) == BUFF_SIZE) { _free_entry(buffer->entries->data); @@ -99,6 +100,24 @@ buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, buffer->entries = g_slist_append(buffer->entries, e); } +gboolean +buffer_mark_received(ProfBuff buffer, const char * const id) +{ + GSList *entries = buffer->entries; + while (entries) { + ProfBuffEntry *entry = entries->data; + if (entry->receipt) { + if (!entry->receipt->received) { + entry->receipt->received = TRUE; + return TRUE; + } + } + entries = g_slist_next(entries); + } + + return FALSE; +} + ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry) { @@ -113,4 +132,8 @@ _free_entry(ProfBuffEntry *entry) free(entry->from); g_date_time_unref(entry->time); free(entry); + if (entry->receipt) { + free(entry->receipt->id); + free(entry->receipt); + } } \ No newline at end of file diff --git a/src/ui/buffer.h b/src/ui/buffer.h index 5258b8c1..cad7eee0 100644 --- a/src/ui/buffer.h +++ b/src/ui/buffer.h @@ -40,6 +40,11 @@ #include <glib.h> +typedef struct delivery_receipt_t { + char *id; + gboolean received; +} DeliveryReceipt; + typedef struct prof_buff_entry_t { char show_char; GDateTime *time; @@ -47,13 +52,18 @@ typedef struct prof_buff_entry_t { theme_item_t theme_item; char *from; char *message; + DeliveryReceipt *receipt; } ProfBuffEntry; typedef struct prof_buff_t *ProfBuff; ProfBuff buffer_create(); void buffer_free(ProfBuff buffer); -void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, const char * const from, const char * const message); +void buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, int flags, theme_item_t theme_item, + const char * const from, const char * const message, DeliveryReceipt *receipt); int buffer_size(ProfBuff buffer); ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry); +gboolean buffer_mark_received(ProfBuff buffer, const char * const id); + + #endif diff --git a/src/ui/core.c b/src/ui/core.c index be49ed29..aa77e32e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -387,10 +387,7 @@ ui_message_receipt(const char * const barejid, const char * const id) ProfChatWin *chatwin = wins_get_chat(barejid); if (chatwin) { ProfWin *win = (ProfWin*) chatwin; - GString *message = g_string_new("Message received: "); - g_string_append(message, id); - win_println(win, message->str); - g_string_free(message, TRUE); + win_mark_received(win, id); } } @@ -1459,13 +1456,8 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha ProfChatWin *chatwin = (ProfChatWin*)window; chat_state_active(chatwin->state); - if (id) { - GString *message_with_id = g_string_new(id); - g_string_append(message_with_id, ": "); - g_string_append(message_with_id, message); - win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message_with_id->str); - g_string_free(message_with_id, TRUE); - free(id); + if (prefs_get_boolean(PREF_RECEIPTS) && id) { + win_print_with_receipt(window, '-', NULL, 0, THEME_TEXT_ME, "me", message, id); } else { win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); } diff --git a/src/ui/window.c b/src/ui/window.c index d5b30228..81408403 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -59,7 +59,7 @@ #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X)) static void _win_print(ProfWin *window, const char show_char, GDateTime *time, - int flags, theme_item_t theme_item, const char * const from, const char * const message); + int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt); static void _win_print_wrapped(WINDOW *win, const char * const message); int @@ -885,13 +885,45 @@ win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, time = g_date_time_new_from_timeval_utc(tstamp); } - buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message); - _win_print(window, show_char, time, flags, theme_item, from, message); + buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, NULL); + _win_print(window, show_char, time, flags, theme_item, from, message, NULL); // TODO: cross-reference.. this should be replaced by a real event-based system ui_input_nonblocking(TRUE); } void +win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, + int flags, theme_item_t theme_item, const char * const from, const char * const message, char *id) +{ + GDateTime *time; + + if (tstamp == NULL) { + time = g_date_time_new_now_local(); + } else { + time = g_date_time_new_from_timeval_utc(tstamp); + } + + DeliveryReceipt *receipt = malloc(sizeof(struct delivery_receipt_t)); + receipt->id = strdup(id); + receipt->received = FALSE; + free(id); + + buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message, receipt); + _win_print(window, show_char, time, flags, theme_item, from, message, receipt); + // TODO: cross-reference.. this should be replaced by a real event-based system + ui_input_nonblocking(TRUE); +} + +void +win_mark_received(ProfWin *window, const char * const id) +{ + gboolean received = buffer_mark_received(window->layout->buffer, id); + if (received) { + win_redraw(window); + } +} + +void win_println(ProfWin *window, const char * const message) { win_print(window, '-', NULL, 0, 0, "", message); @@ -905,7 +937,7 @@ win_newline(ProfWin *window) static void _win_print(ProfWin *window, const char show_char, GDateTime *time, - int flags, theme_item_t theme_item, const char * const from, const char * const message) + int flags, theme_item_t theme_item, const char * const from, const char * const message, DeliveryReceipt *receipt) { // flags : 1st bit = 0/1 - me/not me // 2nd bit = 0/1 - date/no date @@ -947,6 +979,10 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, colour = 0; } + if (receipt && !receipt->received) { + colour = theme_attrs(THEME_BLACK_BOLD); + } + wattron(window->layout->win, colour); if (strncmp(message, "/me ", 4) == 0) { wprintw(window->layout->win, "*%s ", from); @@ -959,7 +995,11 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, } if (!me_message) { - wattron(window->layout->win, theme_attrs(theme_item)); + if (receipt && !receipt->received) { + wattron(window->layout->win, theme_attrs(THEME_BLACK_BOLD)); + } else { + wattron(window->layout->win, theme_attrs(theme_item)); + } } if (prefs_get_boolean(PREF_WRAP)) { @@ -975,7 +1015,11 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, if (me_message) { wattroff(window->layout->win, colour); } else { - wattroff(window->layout->win, theme_attrs(theme_item)); + if (receipt && !receipt->received) { + wattroff(window->layout->win, theme_attrs(THEME_BLACK_BOLD)); + } else { + wattroff(window->layout->win, theme_attrs(theme_item)); + } } } @@ -1074,7 +1118,7 @@ win_redraw(ProfWin *window) for (i = 0; i < size; i++) { ProfBuffEntry *e = buffer_yield_entry(window->layout->buffer, i); - _win_print(window, e->show_char, e->time, e->flags, e->theme_item, e->from, e->message); + _win_print(window, e->show_char, e->time, e->flags, e->theme_item, e->from, e->message, e->receipt); } } diff --git a/src/ui/window.h b/src/ui/window.h index b16d2609..f525e5fa 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -170,6 +170,8 @@ void win_show_info(ProfWin *window, PContact contact); void win_show_occupant_info(ProfWin *window, const char * const room, Occupant *occupant); void win_vprint(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...); void win_print(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, theme_item_t theme_item, const char * const from, const char * const message); +void win_print_with_receipt(ProfWin *window, const char show_char, GTimeVal *tstamp, int flags, + theme_item_t theme_item, const char * const from, const char * const message, char *id); void win_println(ProfWin *window, const char * const message); void win_newline(ProfWin *window); void win_redraw(ProfWin *window); @@ -179,6 +181,7 @@ int win_roster_cols(void); int win_occpuants_cols(void); void win_printline_nowrap(WINDOW *win, char *msg); void win_mouse(ProfWin *current, const wint_t ch, const int result); +void win_mark_received(ProfWin *window, const char * const id); int win_unread(ProfWin *window); gboolean win_has_active_subwin(ProfWin *window); |