From f942982f4e74028031f22a242798744acee97544 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 6 Dec 2013 19:41:53 -0500 Subject: [PATCH] alert user when name is mentioned in groupchat --- src/groupchat.c | 27 +++++++++++++++++++++++---- src/main.c | 2 -- src/misc_tools.c | 11 +++++++++-- src/toxic_windows.h | 3 +++ src/windows.c | 15 ++++++++++----- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/groupchat.c b/src/groupchat.c index 5105261..e624569 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -97,6 +97,24 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int ChatContext *ctx = self->chatwin; + /* check if message contains own name and alert appropriately */ + int alert_type = WINDOW_ALERT_1; + bool beep = false; + int msg_clr = WHITE; + + uint8_t selfnick[TOX_MAX_NAME_LENGTH] = {'\0'}; + tox_get_self_name(m, selfnick, TOX_MAX_NAME_LENGTH); + + bool nick_match = strcasestr(msg, selfnick);; + + if (nick_match) { + alert_type = WINDOW_ALERT_0; + beep = true; + msg_clr = RED; + } + + alert_window(self, alert_type, beep); + uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'}; tox_group_peername(m, groupnum, peernum, nick); nick[TOXIC_MAX_NAME_LENGTH] = '\0'; /* enforce client max name length */ @@ -106,14 +124,15 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(CYAN)); - if (msg[0] == '>') { + if (msg[0] == '>' && !nick_match) { wattron(ctx->history, COLOR_PAIR(GREEN)); wprintw(ctx->history, "%s\n", msg); wattroff(ctx->history, COLOR_PAIR(GREEN)); - } else + } else { + wattron(ctx->history, COLOR_PAIR(msg_clr)); wprintw(ctx->history, "%s\n", msg); - - alert_window(self, WINDOW_ALERT_1, false); + wattroff(ctx->history, COLOR_PAIR(msg_clr)); + } } /* Puts two copies of peerlist in chat instance */ diff --git a/src/main.c b/src/main.c index 0dbeac1..ebd510d 100644 --- a/src/main.c +++ b/src/main.c @@ -527,7 +527,6 @@ int main(int argc, char *argv[]) load_data(m, DATA_FILE); if (f_flag == -1) { - prep_prompt_win(); attron(COLOR_PAIR(RED) | A_BOLD); wprintw(prompt->window, "You passed '-f' without giving an argument.\n" "defaulting to 'data' for a keyfile...\n"); @@ -535,7 +534,6 @@ int main(int argc, char *argv[]) } if (config_err) { - prep_prompt_win(); attron(COLOR_PAIR(RED) | A_BOLD); wprintw(prompt->window, "Unable to determine configuration directory.\n" "defaulting to 'data' for a keyfile...\n"); diff --git a/src/misc_tools.c b/src/misc_tools.c index 2325cb9..22ab0bf 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -111,10 +111,17 @@ bool timed_out(uint64_t timestamp, uint64_t curtime, uint64_t timeout) /* Colours the window tab according to type. Beeps if is_beep is true */ void alert_window(ToxWindow *self, int type, bool is_beep) { - if (type == WINDOW_ALERT_1) + switch (type) { + case WINDOW_ALERT_0: + self->alert0 = true; + break; + case WINDOW_ALERT_1: self->alert1 = true; - else if(type == WINDOW_ALERT_2) + break; + case WINDOW_ALERT_2: self->alert2 = true; + break; + } if (is_beep) beep(); diff --git a/src/toxic_windows.h b/src/toxic_windows.h index ad66cc7..8d8afbc 100644 --- a/src/toxic_windows.h +++ b/src/toxic_windows.h @@ -44,7 +44,9 @@ enum { BLACK, }; +/* tab alert types: lower types take priority */ enum { + WINDOW_ALERT_0, WINDOW_ALERT_1, WINDOW_ALERT_2, }; @@ -79,6 +81,7 @@ struct ToxWindow { char name[TOX_MAX_NAME_LENGTH]; bool active; + bool alert0; bool alert1; bool alert2; int num; diff --git a/src/windows.c b/src/windows.c index a5f6c7d..01cae48 100644 --- a/src/windows.c +++ b/src/windows.c @@ -264,19 +264,23 @@ ToxWindow *init_windows(Tox *m) static void draw_window_tab(ToxWindow toxwin) { - /* alert1 takes priority */ - if (toxwin.alert1) + /* alert0 takes priority */ + if (toxwin.alert0) + attron(COLOR_PAIR(GREEN)); + else if (toxwin.alert1) attron(COLOR_PAIR(RED)); else if (toxwin.alert2) - attron(COLOR_PAIR(BLUE)); + attron(COLOR_PAIR(MAGENTA)); clrtoeol(); printw(" [%s]", toxwin.name); - if (toxwin.alert1) + if (toxwin.alert0) + attroff(COLOR_PAIR(GREEN)); + else if (toxwin.alert1) attroff(COLOR_PAIR(RED)); else if (toxwin.alert2) - attroff(COLOR_PAIR(BLUE)); + attroff(COLOR_PAIR(MAGENTA)); } static void draw_bar(void) @@ -321,6 +325,7 @@ static void draw_bar(void) void draw_active_window(Tox *m) { ToxWindow *a = active_window; + a->alert0 = false; a->alert1 = false; a->alert2 = false;