diff --git a/src/chat.c b/src/chat.c index 03bc2e3..0e00b60 100644 --- a/src/chat.c +++ b/src/chat.c @@ -30,14 +30,6 @@ typedef struct { WINDOW *linewin; } ChatContext; -typedef struct { - WINDOW *topline; - uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; - TOX_USERSTATUS status; - bool is_online; - int max_len; /* set equal to the window's max x coordinate */ -} StatusBar; - void print_help(ChatContext *self); void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd); diff --git a/src/friendlist.c b/src/friendlist.c index 501081a..755536e 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -76,8 +76,9 @@ void friendlist_onStatusMessageChange(ToxWindow *self, int num, uint8_t *str, ui if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num < 0 || num >= num_friends) return; - memcpy((char *) &friends[num].statusmsg, (char *) str, len); - friends[num].statusmsg[len] = 0; + /* Ignore default "Online" status message */ + if (strncmp(str, "Online", strlen(str))) + memcpy((char *) &friends[num].statusmsg, (char *) str, len); } int friendlist_onFriendAdded(Tox *m, int num) diff --git a/src/prompt.c b/src/prompt.c index aff1b68..4a06aa4 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -57,6 +57,24 @@ static struct { { "note", cmd_note }, }; +void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16_t length) +{ + int n = add_req(key); + wprintw(self->window, "\nFriend request from:\n"); + + int i; + + for (i = 0; i < KEY_SIZE_BYTES; ++i) { + wprintw(self->window, "%02x", key[i] & 0xff); + } + + wprintw(self->window, "\n\nWith the message: %s\n\n", data); + wprintw(self->window, "Type \"accept %d\" to accept it.\n", n); + + self->blink = true; + beep(); +} + // XXX: int add_req(uint8_t *public_key) { @@ -565,6 +583,7 @@ ToxWindow new_prompt() ret.onKey = &prompt_onKey; ret.onDraw = &prompt_onDraw; ret.onInit = &prompt_onInit; + ret.onFriendRequest = &prompt_onFriendRequest; strcpy(ret.name, "prompt"); return ret; } diff --git a/src/toxic_windows.h b/src/toxic_windows.h index 834941b..8958270 100644 --- a/src/toxic_windows.h +++ b/src/toxic_windows.h @@ -59,6 +59,14 @@ struct ToxWindow_ { WINDOW *window; }; +typedef struct { + WINDOW *topline; + uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; + TOX_USERSTATUS status; + bool is_online; + int max_len; /* set to the window's max x coordinate */ +} StatusBar; + void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata); void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdata); void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata); diff --git a/src/windows.c b/src/windows.c index 5849c1d..f298b71 100644 --- a/src/windows.c +++ b/src/windows.c @@ -22,18 +22,8 @@ static Tox *m; /* CALLBACKS START */ void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata) { - int n = add_req(public_key); - wprintw(prompt->window, "\nFriend request from:\n"); - int i; - - for (i = 0; i < KEY_SIZE_BYTES; ++i) { - wprintw(prompt->window, "%02x", public_key[i] & 0xff); - } - - wprintw(prompt->window, "\nWith the message: %s\n", data); - wprintw(prompt->window, "Type \"accept %d\" to accept it.\n", n); - + for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onFriendRequest != NULL) windows[i].onFriendRequest(&windows[i], public_key, data, length); @@ -49,15 +39,19 @@ void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdat snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME); if (status == 1) { + wattron(prompt->window, COLOR_PAIR(GREEN)); wattron(prompt->window, A_BOLD); wprintw(prompt->window, "\n%s ", nick); wattroff(prompt->window, A_BOLD); wprintw(prompt->window, "has come online\n"); + wattroff(prompt->window, COLOR_PAIR(GREEN)); } else { + wattron(prompt->window, COLOR_PAIR(RED)); wattron(prompt->window, A_BOLD); wprintw(prompt->window, "\n%s ", nick); wattroff(prompt->window, A_BOLD); wprintw(prompt->window, "has gone offline\n"); + wattroff(prompt->window, COLOR_PAIR(RED)); } int i;