1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-03 16:27:46 +02:00

speed up friendlist loading on startup

This commit is contained in:
Jfreegman 2014-03-05 08:01:12 -05:00
parent 2fcfa954ab
commit 4b8de0d16d
3 changed files with 14 additions and 9 deletions

View File

@ -133,7 +133,7 @@ static void friendlist_onStatusMessageChange(ToxWindow *self, int num, uint8_t *
friends[num].statusmsg_len = len; friends[num].statusmsg_len = len;
} }
static void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort) void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort)
{ {
if (max_friends_index < 0 || max_friends_index >= MAX_FRIENDS_NUM) if (max_friends_index < 0 || max_friends_index >= MAX_FRIENDS_NUM)
return; return;

View File

@ -46,6 +46,8 @@ ToxWindow new_friendlist(void);
void disable_chatwin(int f_num); void disable_chatwin(int f_num);
int get_friendnum(uint8_t *name); int get_friendnum(uint8_t *name);
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort);
/* sorts friendlist_index first by connection status then alphabetically */ /* sorts friendlist_index first by connection status then alphabetically */
void sort_friendlist_index(Tox *m); void sort_friendlist_index(Tox *m);

View File

@ -283,6 +283,15 @@ static void do_connection(Tox *m, ToxWindow *prompt)
} }
} }
static void load_friendlist(Tox *m)
{
int i;
uint32_t numfriends = tox_count_friendlist(m);
for (i = 0; i < numfriends; ++i)
friendlist_onFriendAdded(NULL, m, i, false);
}
/* /*
* Store Messenger to given location * Store Messenger to given location
* Return 0 stored successfully * Return 0 stored successfully
@ -361,12 +370,7 @@ static void load_data(Tox *m, char *path)
} }
tox_load(m, buf, len); tox_load(m, buf, len);
load_friendlist(m);
uint32_t i = 0;
uint8_t name[TOX_MAX_NAME_LENGTH];
while (tox_get_name(m, i, name) != -1)
on_friendadded(m, i++, false);
free(buf); free(buf);
fclose(fd); fclose(fd);
@ -384,12 +388,11 @@ static void load_data(Tox *m, char *path)
void exit_toxic(Tox *m) void exit_toxic(Tox *m)
{ {
store_data(m, DATA_FILE); store_data(m, DATA_FILE);
close_all_file_senders(); close_all_file_senders();
kill_all_windows(); kill_all_windows();
log_disable(prompt->promptbuf->log);
free(DATA_FILE); free(DATA_FILE);
free(prompt->stb); free(prompt->stb);
log_disable(prompt->promptbuf->log);
free(prompt->promptbuf->log); free(prompt->promptbuf->log);
free(prompt->promptbuf); free(prompt->promptbuf);
tox_kill(m); tox_kill(m);