1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-18 15:07:47 +02:00

alert user when name is mentioned in groupchat

This commit is contained in:
Jfreegman 2013-12-06 19:41:53 -05:00
parent ce45580c83
commit f942982f4e
5 changed files with 45 additions and 13 deletions

View File

@ -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 */

View File

@ -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");

View File

@ -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();

View File

@ -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;

View File

@ -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;