mirror of
https://github.com/Tha14/toxic.git
synced 2025-07-05 03:26:46 +02:00
implemented status and connectionstatus callbacks
This commit is contained in:
@ -24,7 +24,9 @@ typedef struct {
|
||||
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||
int num;
|
||||
int chatwin;
|
||||
bool active;
|
||||
bool active;
|
||||
bool online;
|
||||
TOX_USERSTATUS status;
|
||||
} friend_t;
|
||||
|
||||
static friend_t friends[MAX_FRIENDS_NUM];
|
||||
@ -34,25 +36,44 @@ static int num_selected = 0;
|
||||
|
||||
void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len)
|
||||
{
|
||||
if (num >= num_friends)
|
||||
if (num < 0 || num >= num_friends)
|
||||
return;
|
||||
|
||||
if (friends[num].chatwin == -1)
|
||||
friends[num].chatwin = add_window(m, new_chat(m, friends[num].num));
|
||||
}
|
||||
|
||||
void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t status)
|
||||
{
|
||||
if (num < 0 || num >= num_friends)
|
||||
return;
|
||||
|
||||
if (status == 1)
|
||||
friends[num].online = true;
|
||||
else
|
||||
friends[num].online = false;
|
||||
}
|
||||
|
||||
void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t len)
|
||||
{
|
||||
if (len >= TOX_MAX_NAME_LENGTH || num >= num_friends)
|
||||
if (len >= TOX_MAX_NAME_LENGTH || num < 0 || num >= num_friends)
|
||||
return;
|
||||
|
||||
memcpy((char *) &friends[num].name, (char *) str, len);
|
||||
friends[num].name[len] = 0;
|
||||
}
|
||||
|
||||
void friendlist_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS status)
|
||||
{
|
||||
if (num < 0 || num >= num_friends)
|
||||
return;
|
||||
|
||||
friends[num].status = status;
|
||||
}
|
||||
|
||||
void friendlist_onStatusMessageChange(ToxWindow *self, int num, uint8_t *str, uint16_t len)
|
||||
{
|
||||
if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num >= num_friends)
|
||||
if (len >= TOX_MAX_STATUSMESSAGE_LENGTH || num < 0 || num >= num_friends)
|
||||
return;
|
||||
|
||||
memcpy((char *) &friends[num].statusmsg, (char *) str, len);
|
||||
@ -71,6 +92,8 @@ int friendlist_onFriendAdded(Tox *m, int num)
|
||||
friends[i].num = num;
|
||||
friends[i].active = true;
|
||||
friends[i].chatwin = -1;
|
||||
friends[i].online = false;
|
||||
friends[i].status = TOX_USERSTATUS_INVALID;
|
||||
|
||||
if (tox_getname(m, num, friends[i].name) != 0 || friends[i].name[0] == '\0')
|
||||
strcpy((char *) friends[i].name, "unknown");
|
||||
@ -172,8 +195,8 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
else
|
||||
wprintw(self->window, " ");
|
||||
|
||||
if (tox_friendstatus(m, friends[i].num) == TOX_FRIEND_ONLINE) {
|
||||
TOX_USERSTATUS status = tox_get_userstatus(m, friends[i].num);
|
||||
if (friends[i].online) {
|
||||
TOX_USERSTATUS status = friends[i].status;
|
||||
int colour = 7; /* Invalid or other errors default to black */
|
||||
|
||||
switch(status) {
|
||||
@ -203,7 +226,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
wrefresh(self->window);
|
||||
}
|
||||
|
||||
@ -226,8 +249,10 @@ ToxWindow new_friendlist()
|
||||
ret.onDraw = &friendlist_onDraw;
|
||||
ret.onInit = &friendlist_onInit;
|
||||
ret.onMessage = &friendlist_onMessage;
|
||||
ret.onConnectionChange = &friendlist_onConnectionChange;
|
||||
ret.onAction = &friendlist_onMessage; // Action has identical behaviour to message
|
||||
ret.onNickChange = &friendlist_onNickChange;
|
||||
ret.onStatusChange = &friendlist_onStatusChange;
|
||||
ret.onStatusMessageChange = &friendlist_onStatusMessageChange;
|
||||
|
||||
strcpy(ret.title, "[friends]");
|
||||
|
Reference in New Issue
Block a user