Commit f496648d authored by vvaltman's avatar vvaltman

Make get_state once per hour

parent 1831415f
......@@ -164,6 +164,7 @@ void net_loop (int flags, int (*is_end)(void)) {
}
event_add (ev, 0);
}
int last_get_state = time (0);
while (!is_end || !is_end ()) {
event_base_loop (tgl_state.ev_base, EVLOOP_ONCE);
......@@ -183,6 +184,10 @@ void net_loop (int flags, int (*is_end)(void)) {
}
exit (0);
}
if (time (0) - last_get_state > 3600) {
tgl_do_lookup_state ();
last_get_state = time (0);
}
write_state_file ();
update_prompt ();
if (unknown_user_list_pos) {
......
......@@ -3216,6 +3216,21 @@ static int get_state_on_answer (struct query *q UU) {
return 0;
}
static int lookup_state_on_answer (struct query *q UU) {
assert (fetch_int () == (int)CODE_updates_state);
int pts = fetch_int ();
int qts = fetch_int ();
fetch_int ();
int seq = fetch_int ();
fetch_int ();
if (pts > tgl_state.pts || qts > tgl_state.qts || seq > tgl_state.seq) {
tgl_do_get_difference (0, 0, 0);
}
return 0;
}
//int get_difference_active;
static int get_difference_on_answer (struct query *q UU) {
//get_difference_active = 0;
......@@ -3307,6 +3322,11 @@ static int get_difference_on_answer (struct query *q UU) {
return 0;
}
static struct query_methods lookup_state_methods = {
.on_answer = lookup_state_on_answer,
.type = TYPE_TO_PARAM(updates_state)
};
static struct query_methods get_state_methods = {
.on_answer = get_state_on_answer,
.type = TYPE_TO_PARAM(updates_state)
......@@ -3317,6 +3337,16 @@ static struct query_methods get_difference_methods = {
.type = TYPE_TO_PARAM(updates_difference)
};
void tgl_do_lookup_state (void) {
if (tgl_state.locks & TGL_LOCK_DIFF) {
return;
}
clear_packet ();
tgl_do_insert_header ();
out_int (CODE_updates_get_state);
tglq_send_query (tgl_state.DC_working, packet_ptr - packet_buffer, packet_buffer, &lookup_state_methods, 0, 0, 0);
}
void tgl_do_get_difference (int sync_from_start, void (*callback)(void *callback_extra, int success), void *callback_extra) {
//get_difference_active = 1;
//difference_got = 0;
......
......@@ -273,6 +273,7 @@ void tgl_do_create_encr_chat_request (int user_id, void (*callback)(void *callba
void tgl_do_create_secret_chat (tgl_peer_id_t id, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
void tgl_do_accept_encr_chat_request (struct tgl_secret_chat *E, void (*callback)(void *callback_extra, int success, struct tgl_secret_chat *E), void *callback_extra);
void tgl_do_get_difference (int sync_from_start, void (*callback)(void *callback_extra, int success), void *callback_extra);
void tgl_do_lookup_state (void);
void tgl_do_add_user_to_chat (tgl_peer_id_t chat_id, tgl_peer_id_t id, int limit, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
void tgl_do_del_user_from_chat (tgl_peer_id_t chat_id, tgl_peer_id_t id, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
void tgl_do_create_group_chat (tgl_peer_id_t id, char *chat_topic, void (*callback)(void *callback_extra, int success, struct tgl_message *M), void *callback_extra);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment