1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Use colouring for message receipts

This commit is contained in:
James Booth 2015-03-14 16:05:13 +00:00
parent bc6e32175d
commit 1014244408
5 changed files with 92 additions and 20 deletions

View File

@ -81,7 +81,7 @@ buffer_free(ProfBuff buffer)
void void
buffer_push(ProfBuff buffer, const char show_char, GDateTime *time, 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)); ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
e->show_char = show_char; e->show_char = show_char;
@ -90,6 +90,7 @@ buffer_push(ProfBuff buffer, const char show_char, GDateTime *time,
e->time = time; e->time = time;
e->from = strdup(from); e->from = strdup(from);
e->message = strdup(message); e->message = strdup(message);
e->receipt = receipt;
if (g_slist_length(buffer->entries) == BUFF_SIZE) { if (g_slist_length(buffer->entries) == BUFF_SIZE) {
_free_entry(buffer->entries->data); _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); 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* ProfBuffEntry*
buffer_yield_entry(ProfBuff buffer, int entry) buffer_yield_entry(ProfBuff buffer, int entry)
{ {
@ -113,4 +132,8 @@ _free_entry(ProfBuffEntry *entry)
free(entry->from); free(entry->from);
g_date_time_unref(entry->time); g_date_time_unref(entry->time);
free(entry); free(entry);
if (entry->receipt) {
free(entry->receipt->id);
free(entry->receipt);
}
} }

View File

@ -40,6 +40,11 @@
#include <glib.h> #include <glib.h>
typedef struct delivery_receipt_t {
char *id;
gboolean received;
} DeliveryReceipt;
typedef struct prof_buff_entry_t { typedef struct prof_buff_entry_t {
char show_char; char show_char;
GDateTime *time; GDateTime *time;
@ -47,13 +52,18 @@ typedef struct prof_buff_entry_t {
theme_item_t theme_item; theme_item_t theme_item;
char *from; char *from;
char *message; char *message;
DeliveryReceipt *receipt;
} ProfBuffEntry; } ProfBuffEntry;
typedef struct prof_buff_t *ProfBuff; typedef struct prof_buff_t *ProfBuff;
ProfBuff buffer_create(); ProfBuff buffer_create();
void buffer_free(ProfBuff buffer); 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); int buffer_size(ProfBuff buffer);
ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry); ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry);
gboolean buffer_mark_received(ProfBuff buffer, const char * const id);
#endif #endif

View File

@ -387,10 +387,7 @@ ui_message_receipt(const char * const barejid, const char * const id)
ProfChatWin *chatwin = wins_get_chat(barejid); ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin) { if (chatwin) {
ProfWin *win = (ProfWin*) chatwin; ProfWin *win = (ProfWin*) chatwin;
GString *message = g_string_new("Message received: "); win_mark_received(win, id);
g_string_append(message, id);
win_println(win, message->str);
g_string_free(message, TRUE);
} }
} }
@ -1459,13 +1456,8 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha
ProfChatWin *chatwin = (ProfChatWin*)window; ProfChatWin *chatwin = (ProfChatWin*)window;
chat_state_active(chatwin->state); chat_state_active(chatwin->state);
if (id) { if (prefs_get_boolean(PREF_RECEIPTS) && id) {
GString *message_with_id = g_string_new(id); win_print_with_receipt(window, '-', NULL, 0, THEME_TEXT_ME, "me", message, 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);
} else { } else {
win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message);
} }

View File

@ -59,7 +59,7 @@
#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X)) #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
static void _win_print(ProfWin *window, const char show_char, GDateTime *time, 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); static void _win_print_wrapped(WINDOW *win, const char * const message);
int int
@ -885,12 +885,44 @@ win_print(ProfWin *window, const char show_char, GTimeVal *tstamp,
time = g_date_time_new_from_timeval_utc(tstamp); time = g_date_time_new_from_timeval_utc(tstamp);
} }
buffer_push(window->layout->buffer, 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); _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 // TODO: cross-reference.. this should be replaced by a real event-based system
ui_input_nonblocking(TRUE); 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 void
win_println(ProfWin *window, const char * const message) win_println(ProfWin *window, const char * const message)
{ {
@ -905,7 +937,7 @@ win_newline(ProfWin *window)
static void static void
_win_print(ProfWin *window, const char show_char, GDateTime *time, _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 // flags : 1st bit = 0/1 - me/not me
// 2nd bit = 0/1 - date/no date // 2nd bit = 0/1 - date/no date
@ -947,6 +979,10 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
colour = 0; colour = 0;
} }
if (receipt && !receipt->received) {
colour = theme_attrs(THEME_BLACK_BOLD);
}
wattron(window->layout->win, colour); wattron(window->layout->win, colour);
if (strncmp(message, "/me ", 4) == 0) { if (strncmp(message, "/me ", 4) == 0) {
wprintw(window->layout->win, "*%s ", from); wprintw(window->layout->win, "*%s ", from);
@ -959,8 +995,12 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
} }
if (!me_message) { if (!me_message) {
if (receipt && !receipt->received) {
wattron(window->layout->win, theme_attrs(THEME_BLACK_BOLD));
} else {
wattron(window->layout->win, theme_attrs(theme_item)); wattron(window->layout->win, theme_attrs(theme_item));
} }
}
if (prefs_get_boolean(PREF_WRAP)) { if (prefs_get_boolean(PREF_WRAP)) {
_win_print_wrapped(window->layout->win, message+offset); _win_print_wrapped(window->layout->win, message+offset);
@ -974,10 +1014,14 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time,
if (me_message) { if (me_message) {
wattroff(window->layout->win, colour); wattroff(window->layout->win, colour);
} else {
if (receipt && !receipt->received) {
wattroff(window->layout->win, theme_attrs(THEME_BLACK_BOLD));
} else { } else {
wattroff(window->layout->win, theme_attrs(theme_item)); wattroff(window->layout->win, theme_attrs(theme_item));
} }
} }
}
static void static void
_win_indent(WINDOW *win, int size) _win_indent(WINDOW *win, int size)
@ -1074,7 +1118,7 @@ win_redraw(ProfWin *window)
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
ProfBuffEntry *e = buffer_yield_entry(window->layout->buffer, 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);
} }
} }

View File

@ -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_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_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(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_println(ProfWin *window, const char * const message);
void win_newline(ProfWin *window); void win_newline(ProfWin *window);
void win_redraw(ProfWin *window); void win_redraw(ProfWin *window);
@ -179,6 +181,7 @@ int win_roster_cols(void);
int win_occpuants_cols(void); int win_occpuants_cols(void);
void win_printline_nowrap(WINDOW *win, char *msg); void win_printline_nowrap(WINDOW *win, char *msg);
void win_mouse(ProfWin *current, const wint_t ch, const int result); 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); int win_unread(ProfWin *window);
gboolean win_has_active_subwin(ProfWin *window); gboolean win_has_active_subwin(ProfWin *window);