mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-12 23:33:03 +01:00
use API function for friend count instead of global var
This commit is contained in:
parent
da99d776df
commit
42cd80efe9
@ -99,7 +99,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
|
||||
alert_window(self, WINDOW_ALERT_1, true);
|
||||
}
|
||||
|
||||
static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len)
|
||||
static void chat_onNickChange(ToxWindow *self, Tox *m, int num, uint8_t *nick, uint16_t len)
|
||||
{
|
||||
if (self->num != num)
|
||||
return;
|
||||
|
@ -20,7 +20,6 @@ extern char *DATA_FILE;
|
||||
extern ToxWindow *prompt;
|
||||
|
||||
static int max_friends_index = 0; /* marks the index of the last friend in friends array */
|
||||
static int num_friends = 0;
|
||||
static int num_selected = 0;
|
||||
|
||||
ToxicFriend friends[MAX_FRIENDS_NUM];
|
||||
@ -40,7 +39,7 @@ static int index_name_cmp(const void *n1, const void *n2)
|
||||
}
|
||||
|
||||
/* sorts friendlist_index first by connection status then alphabetically */
|
||||
void sort_friendlist_index(void)
|
||||
void sort_friendlist_index(Tox *m)
|
||||
{
|
||||
int i;
|
||||
int n = 0;
|
||||
@ -50,7 +49,7 @@ void sort_friendlist_index(void)
|
||||
friendlist_index[n++] = friends[i].num;
|
||||
}
|
||||
|
||||
qsort(friendlist_index, num_friends, sizeof(int), index_name_cmp);
|
||||
qsort(friendlist_index, tox_count_friendlist(m), sizeof(int), index_name_cmp);
|
||||
}
|
||||
|
||||
static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len)
|
||||
@ -83,10 +82,10 @@ static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int num, uint
|
||||
return;
|
||||
|
||||
friends[num].online = status == 1 ? true : false;
|
||||
sort_friendlist_index();
|
||||
sort_friendlist_index(m);
|
||||
}
|
||||
|
||||
static void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t len)
|
||||
static void friendlist_onNickChange(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len)
|
||||
{
|
||||
if (len > TOX_MAX_NAME_LENGTH || num >= max_friends_index)
|
||||
return;
|
||||
@ -95,7 +94,7 @@ static void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint
|
||||
len = strlen(str) + 1;
|
||||
memcpy(friends[num].name, str, len);
|
||||
friends[num].namelength = len;
|
||||
sort_friendlist_index();
|
||||
sort_friendlist_index(m);
|
||||
}
|
||||
|
||||
static void friendlist_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS status)
|
||||
@ -139,13 +138,11 @@ static void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort
|
||||
friends[i].namelength = strlen(friends[i].name) + 1;
|
||||
}
|
||||
|
||||
++num_friends;
|
||||
|
||||
if (i == max_friends_index)
|
||||
++max_friends_index;
|
||||
|
||||
if (sort)
|
||||
sort_friendlist_index();
|
||||
sort_friendlist_index(m);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -203,6 +200,8 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *
|
||||
|
||||
static void select_friend(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
int num_friends = tox_count_friendlist(m);
|
||||
|
||||
if (key == KEY_UP) {
|
||||
if (--num_selected < 0)
|
||||
num_selected = num_friends - 1;
|
||||
@ -224,19 +223,20 @@ static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
|
||||
}
|
||||
|
||||
max_friends_index = i;
|
||||
--num_friends;
|
||||
|
||||
/* make sure num_selected stays within num_friends range */
|
||||
int num_friends = tox_count_friendlist(m);
|
||||
|
||||
if (num_friends && num_selected == num_friends)
|
||||
--num_selected;
|
||||
|
||||
sort_friendlist_index();
|
||||
sort_friendlist_index(m);
|
||||
store_data(m, DATA_FILE);
|
||||
}
|
||||
|
||||
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
if (num_friends == 0)
|
||||
if (tox_count_friendlist(m) == 0)
|
||||
return;
|
||||
|
||||
int f = friendlist_index[num_selected];
|
||||
@ -273,6 +273,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
bool fix_statuses = x2 != self->x; /* true if window x axis has changed */
|
||||
int num_friends = tox_count_friendlist(m);
|
||||
|
||||
wattron(self->window, COLOR_PAIR(CYAN));
|
||||
wprintw(self->window, " Open a chat window with the");
|
||||
|
@ -22,6 +22,6 @@ void disable_chatwin(int f_num);
|
||||
int get_friendnum(uint8_t *name);
|
||||
|
||||
/* sorts friendlist_index first by connection status then alphabetically */
|
||||
void sort_friendlist_index(void);
|
||||
void sort_friendlist_index(Tox *m);
|
||||
|
||||
#endif /* end of include guard: FRIENDLIST_H_53I41IM */
|
||||
|
@ -547,7 +547,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
prompt_init_statusbar(prompt, m);
|
||||
sort_friendlist_index();
|
||||
sort_friendlist_index(m);
|
||||
|
||||
while (true) {
|
||||
do_tox(m, prompt);
|
||||
|
@ -72,7 +72,7 @@ struct ToxWindow {
|
||||
void(*onFriendAdded)(ToxWindow *, Tox *, int, bool);
|
||||
void(*onConnectionChange)(ToxWindow *, Tox *, int, uint8_t);
|
||||
void(*onMessage)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
|
||||
void(*onNickChange)(ToxWindow *, int, uint8_t *, uint16_t);
|
||||
void(*onNickChange)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
|
||||
void(*onStatusChange)(ToxWindow *, Tox *, int, TOX_USERSTATUS);
|
||||
void(*onStatusMessageChange)(ToxWindow *, int, uint8_t *, uint16_t);
|
||||
void(*onAction)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
|
||||
|
@ -66,7 +66,7 @@ void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, v
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onNickChange != NULL)
|
||||
windows[i].onNickChange(&windows[i], friendnumber, string, length);
|
||||
windows[i].onNickChange(&windows[i], m, friendnumber, string, length);
|
||||
}
|
||||
|
||||
if (store_data(m, DATA_FILE))
|
||||
|
Loading…
Reference in New Issue
Block a user