1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-05 03:16:45 +02:00

use/display nicks instead of friend numbers for groupchat invites

This commit is contained in:
Jfreegman
2013-09-17 19:11:23 -04:00
parent 84422b5845
commit 42de821e3c
3 changed files with 46 additions and 6 deletions

View File

@ -21,6 +21,7 @@ extern ToxWindow *prompt;
typedef struct {
uint8_t name[TOX_MAX_NAME_LENGTH];
uint8_t namelength;
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
uint16_t statusmsg_len;
int num;
@ -58,6 +59,7 @@ void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t le
return;
memcpy((char *) &friends[num].name, (char *) str, len);
friends[num].namelength = len;
}
void friendlist_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS status)
@ -91,9 +93,12 @@ int friendlist_onFriendAdded(Tox *m, int num)
friends[i].chatwin = -1;
friends[i].online = false;
friends[i].status = TOX_USERSTATUS_NONE;
friends[i].namelength = tox_getname(m, num, friends[i].name);
if (tox_getname(m, num, friends[i].name) == -1 || friends[i].name[0] == '\0')
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
strcpy((char *) friends[i].name, UNKNOWN_NAME);
friends[i].namelength = strlen(UNKNOWN_NAME) + 1;
}
if (i == num_friends)
++num_friends;
@ -251,6 +256,21 @@ void disable_chatwin(int f_num)
friends[f_num].chatwin = -1;
}
/* Returns the respective friend number of name. Returns -1 on no match
This should be used instead of tox_getname for retrieving */
int get_friendnum(uint8_t *name)
{
int i;
int len = strlen(name);
for (i = 0; i < num_friends; ++i) {
if (strncmp(friends[i].name, name, len) == 0)
return friends[i].num;
}
return -1;
}
static void friendlist_onInit(ToxWindow *self, Tox *m)
{