optimise tree view a tiny bit

don't refresh all the time, wait for the data to be ready. waiting on
the data is not a good idea either, but it is better than to
continously refresh all the data
This commit is contained in:
Florian Stinglmayr 2019-07-19 21:32:22 +02:00
parent af49931b49
commit a9f23fc278
7 changed files with 53 additions and 9 deletions

View File

@ -45,6 +45,12 @@ bool dc_session_logout(dc_session_t s);
*/
bool dc_session_login(dc_session_t s, dc_account_t login);
/**
* Returns true if the session is ready, i.e. a login has been performed
* and the READY event has been parsed from the websocket.
*/
bool dc_session_is_ready(dc_session_t s);
bool dc_session_has_token(dc_session_t s);
/**

View File

@ -9,6 +9,7 @@ struct dc_session_
dc_api_t api;
dc_account_t login;
dc_gateway_t gateway;
bool ready;
GHashTable *accounts;
GHashTable *channels;
@ -161,6 +162,8 @@ static void dc_session_handle_ready(dc_session_t s, dc_event_t e)
dc_session_add_channel(s, chan);
}
}
s->ready = true;
}
static void dc_session_handler(dc_gateway_t gw, dc_event_t e, void *p)
@ -237,6 +240,8 @@ bool dc_session_logout(dc_session_t s)
s->gateway = NULL;
}
s->ready = false;
return true;
}
@ -248,6 +253,8 @@ bool dc_session_login(dc_session_t s, dc_account_t login)
dc_session_logout(s);
}
s->ready = false;
s->login = dc_ref(login);
if (!dc_account_has_token(login)) {
if (!dc_api_authenticate(s->api, s->login)) {
@ -276,6 +283,12 @@ bool dc_session_has_token(dc_session_t s)
return dc_account_has_token(s->login);
}
bool dc_session_is_ready(dc_session_t s)
{
return_if_true(s == NULL, false);
return s->ready;
}
dc_api_t dc_session_api(dc_session_t s)
{
return_if_true(s == NULL, NULL);

View File

@ -17,6 +17,7 @@ void ncdc_treeitem_set_label(ncdc_treeitem_t i, wchar_t const *s);
void *ncdc_treeitem_tag(ncdc_treeitem_t i);
void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t);
size_t ncdc_treeitem_size(ncdc_treeitem_t i);
void ncdc_treeitem_clear(ncdc_treeitem_t i);
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c);
void ncdc_treeitem_remove(ncdc_treeitem_t i, ncdc_treeitem_t c);

View File

@ -50,7 +50,16 @@ bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac,
dc_unref(current_session);
current_session = dc_ref(s);
LOG(n, L"login: %ls: authentication successful, waiting for data...", av[1]);
LOG(n, L"login: %ls: authentication successful, waiting for ready from websocket...",
av[1]
);
while (!dc_session_is_ready(current_session))
;
LOG(n, L"login: %ls: ready", av[1]);
ncdc_mainwindow_update_guilds(n);
ret = true;
cleanup:

View File

@ -21,6 +21,8 @@ bool ncdc_cmd_logout(ncdc_mainwindow_t n, size_t ac,
dc_unref(current_session);
current_session = NULL;
ncdc_mainwindow_update_guilds(n);
LOG(n, L"logout: successfully logged out");
error:

View File

@ -397,7 +397,6 @@ void ncdc_mainwindow_refresh(ncdc_mainwindow_t n)
{
ncdc_textview_t v = 0;
ncdc_mainwindow_update_guilds(n);
ncdc_treeview_render(n->guildview, n->guilds, n->guilds_h, n->guilds_w);
wnoutrefresh(n->guilds);

View File

@ -22,6 +22,19 @@ struct ncdc_treeitem_
void *tag;
};
struct ncdc_treeview_
{
dc_refable_t ref;
/* root element
*/
ncdc_treeitem_t root;
/* currently selected item
*/
ncdc_treeitem_t current;
};
static void ncdc_treeitem_free(ncdc_treeitem_t t)
{
return_if_true(t == NULL,);
@ -63,6 +76,12 @@ ncdc_treeitem_t ncdc_treeitem_new_string(wchar_t const *s)
return t;
}
size_t ncdc_treeitem_size(ncdc_treeitem_t i)
{
return_if_true(i == NULL || i->children == NULL, 0);
return i->children->len;
}
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c)
{
return_if_true(i == NULL || c == NULL,);
@ -132,13 +151,6 @@ ncdc_treeitem_render(ncdc_treeitem_t t, WINDOW *win,
return off;
}
struct ncdc_treeview_
{
dc_refable_t ref;
ncdc_treeitem_t root;
};
static void ncdc_treeview_free(ncdc_treeview_t t)
{
return_if_true(t == NULL,);
@ -159,6 +171,8 @@ ncdc_treeview_t ncdc_treeview_new(void)
t->root = ncdc_treeitem_new();
goto_if_true(t->root == NULL, error);
t->current = t->root;
return dc_ref(t);
error: