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:
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);