diff --git a/src/friendlist.c b/src/friendlist.c index ab49b05..cb51cbb 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -24,7 +24,7 @@ typedef struct { uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH]; int num; int chatwin; - bool active; + bool active; } friend_t; static friend_t friends[MAX_FRIENDS_NUM]; @@ -72,9 +72,8 @@ int friendlist_onFriendAdded(Tox *m, int num) friends[i].num = num; friends[i].active = true; friends[i].chatwin = -1; - tox_getname(m, num, friends[i].name); + //tox_getname(m, num, friends[i].name); strcpy((char *) friends[i].name, "unknown"); - strcpy((char *) friends[i].status, "Offline"); if (i == num_friends) ++num_friends; @@ -173,19 +172,43 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) for (i = 0; i < num_friends; ++i) { if (friends[i].active) { - if (i == num_selected) - wattron(self->window, COLOR_PAIR(3)); - - wprintw(self->window, " > "); + bool is_online = tox_friendstatus(m, i) == TOX_FRIEND_ONLINE; + TOX_USERSTATUS status = tox_get_userstatus(m, i); if (i == num_selected) - wattroff(self->window, COLOR_PAIR(3)); + wprintw(self->window, " > "); + else + wprintw(self->window, " "); - attron(A_BOLD); - wprintw(self->window, "%s ", friends[i].name); - attroff(A_BOLD); + if (is_online) { + int colour; - wprintw(self->window, "(%s)\n", friends[i].status); + switch(status) { + case TOX_USERSTATUS_NONE: + colour = 1; + break; + + case TOX_USERSTATUS_AWAY: + colour = 5; + break; + + case TOX_USERSTATUS_BUSY: + case TOX_USERSTATUS_INVALID: + default: + colour = 3; + break; + } + + wattron(self->window, COLOR_PAIR(colour)); + attron(A_BOLD); + wprintw(self->window, "%s \n", friends[i].name); + attroff(A_BOLD); + wattroff(self->window, COLOR_PAIR(colour)); + } else { + attron(A_BOLD); + wprintw(self->window, "%s \n", friends[i].name); + attroff(A_BOLD); + } } } diff --git a/src/prompt.c b/src/prompt.c index 5fb4334..521f624 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -294,13 +294,13 @@ void cmd_status(ToxWindow *self, Tox *m, char **args) if (!strncmp(status, "online", strlen("online"))) { status_kind = TOX_USERSTATUS_NONE; - status_text = "ONLINE"; + status_text = "Online"; } else if (!strncmp(status, "away", strlen("away"))) { status_kind = TOX_USERSTATUS_AWAY; - status_text = "AWAY"; + status_text = "Away"; } else if (!strncmp(status, "busy", strlen("busy"))) { status_kind = TOX_USERSTATUS_BUSY; - status_text = "BUSY"; + status_text = "Busy"; } else { wprintw(self->window, "Invalid status.\n"); return; diff --git a/src/windows.c b/src/windows.c index 4fcb653..83d60df 100644 --- a/src/windows.c +++ b/src/windows.c @@ -84,9 +84,8 @@ void on_friendadded(Tox *m, int friendnumber) { friendlist_onFriendAdded(m, friendnumber); - if (store_data(m, DATA_FILE)) { + if (store_data(m, DATA_FILE)) wprintw(prompt->window, "\nCould not store Tox data\n"); - } } /* CALLBACKS END */