diff --git a/mtproto-client.c b/mtproto-client.c index d221f4c..c6250e8 100644 --- a/mtproto-client.c +++ b/mtproto-client.c @@ -1548,7 +1548,7 @@ void work_new_detailed_info (struct connection *c UU, long long msg_id UU) { void work_updates_to_long (struct connection *c UU, long long msg_id UU) { assert (fetch_int (c->mtconnection) == (int)CODE_updates_too_long); logprintf ("updates to long... Getting difference\n"); - do_get_difference (c->instance); + do_get_difference (c->instance, 0); } void work_bad_msg_notification (struct connection *c UU, long long msg_id UU) { diff --git a/purple-plugin/telegram-purple.c b/purple-plugin/telegram-purple.c index f6c2d51..dcba7c4 100644 --- a/purple-plugin/telegram-purple.c +++ b/purple-plugin/telegram-purple.c @@ -183,8 +183,6 @@ static void login_verification_fail(PurpleAccount *acct) static void tgprpl_output_cb(gpointer data, gint source, PurpleInputCondition cond) { mtproto_handle *conn = data; - logprintf("tgprpl_output_cb(%p)\n", data); - logprintf("mtp=%p, fd=%d, rh=%d, wh=%d\n", conn->mtp, conn->fd, conn->rh, conn->wh); if (!conn->mtp) { logprintf ("connection no loner existing, do nothing. \n"); return; @@ -365,9 +363,9 @@ void telegram_on_ready (struct telegram *instance) tggroup = purple_group_new ("Telegram"); purple_blist_add_group (tggroup, NULL); } - do_update_contact_list(instance); + do_get_difference(instance, 0); do_get_dialog_list(instance); - do_get_difference(instance); + do_update_contact_list(instance); telegram_flush (conn->tg); conn->timer = purple_timeout_add (5000, queries_timerfunc, conn); } @@ -477,8 +475,6 @@ void message_allocated_handler(struct telegram *tg, struct message *M) peer_id_t to_id = M->to_id; char *from = g_strdup_printf("%d", id); char *to = g_strdup_printf("%d", to_id.id); - logprintf ("from: %s\n", from); - logprintf ("fwd_date: %d\n", M->date); switch (to_id.type) { case PEER_CHAT: logprintf ("PEER_CHAT\n"); diff --git a/queries.c b/queries.c index c095b54..2345565 100644 --- a/queries.c +++ b/queries.c @@ -59,12 +59,8 @@ char *get_downloads_directory (void); int verbosity; -extern int offline_mode; int offline_mode = 0; -extern int sync_from_start; -int sync_from_start = 0; - #define memcmp8(a,b) memcmp ((a), (b), 8) DEFINE_TREE (query, struct query *, memcmp8, 0) ; @@ -246,12 +242,12 @@ void query_result (struct telegram *instance, long long id UU) { void insert_event_timer (struct telegram *instance, struct event_timer *ev) { - logprintf ( "INSERT: %lf %p %p\n", ev->timeout, ev->self, ev->alarm); + // logprintf ( "INSERT: %lf %p %p\n", ev->timeout, ev->self, ev->alarm); instance->timer_tree = tree_insert_timer (instance->timer_tree, ev, lrand48 ()); } void remove_event_timer (struct telegram *instance, struct event_timer *ev) { - logprintf ( "REMOVE: %lf %p %p\n", ev->timeout, ev->self, ev->alarm); + // logprintf ( "REMOVE: %lf %p %p\n", ev->timeout, ev->self, ev->alarm); instance->timer_tree = tree_delete_timer (instance->timer_tree, ev); } @@ -2580,7 +2576,6 @@ void do_send_create_encr_chat (struct telegram *instance, void *x, unsigned char } out_int (mtp, get_peer_id (E->id)); out_cstring (mtp, instance->g_a, 256); - // TODO: properly... write_secret_chat_file (instance, instance->secret_path); BN_clear_free (g); @@ -2745,13 +2740,14 @@ int get_difference_on_answer (struct query *q UU) { bl_do_set_date (mtp->bl, mtp, fetch_int (mtp)); bl_do_set_seq (mtp->bl, mtp, fetch_int (mtp)); instance->unread_messages = fetch_int (mtp); + logprintf ("UNREAD MESSAGES: %d\n", ml_pos); //write_state_file (); for (i = 0; i < ml_pos; i++) { event_update_new_message (instance, instance->ML[i]); ////print_message (ML[i]); } if (x == CODE_updates_difference_slice) { - do_get_difference (instance); + do_get_difference (instance, 0); } else { //difference_got = 1; } @@ -2770,7 +2766,8 @@ struct query_methods get_difference_methods = { .on_answer = get_difference_on_answer }; -void do_get_difference (struct telegram *instance) { +void do_get_difference (struct telegram *instance, int sync_from_start) { + logprintf ("do_get_difference()\n"); struct mtproto_connection *mtp = instance->connection; struct dc *DC_working = telegram_get_working_dc(instance); @@ -2778,13 +2775,12 @@ void do_get_difference (struct telegram *instance) { //difference_got = 0; clear_packet (mtp); do_insert_header (mtp); + logprintf("do_get_difference(pts:%d, last_date:%d, qts: %d)\n", instance->proto.pts, instance->proto.last_date, instance->proto.qts); if (instance->proto.seq > 0 || sync_from_start) { if (instance->proto.pts == 0) { instance->proto.pts = 1; } if (instance->proto.qts == 0) { instance->proto.qts = 1; } if (instance->proto.last_date == 0) { instance->proto.last_date = 1; } - logprintf("do_get_difference(pts:%d, last_date:%d, qts: %d)\n", - instance->proto.pts, instance->proto.last_date, instance->proto.qts); out_int (mtp, CODE_updates_get_difference); out_int (mtp, instance->proto.pts); out_int (mtp, instance->proto.last_date); diff --git a/queries.h b/queries.h index 30435d6..a141004 100644 --- a/queries.h +++ b/queries.h @@ -112,7 +112,7 @@ void do_export_auth (struct telegram *instance, int num); void do_add_contact (struct telegram *instance, const char *phone, int phone_len, const char *first_name, int first_name_len, const char *last_name, int last_name_len, int force); void do_msg_search (struct telegram *instance, peer_id_t id, int from, int to, int limit, const char *s); void do_accept_encr_chat_request (struct telegram *instance, struct secret_chat *E); -void do_get_difference (struct telegram*); +void do_get_difference (struct telegram*, int sync_from_start); void do_mark_read (struct telegram *instance, peer_id_t id); void do_visualize_key (struct binlog *bl, peer_id_t id); void do_create_keys_end (struct telegram *, struct secret_chat *U); diff --git a/telegram.c b/telegram.c index d402997..5464243 100755 --- a/telegram.c +++ b/telegram.c @@ -317,7 +317,7 @@ void telegram_store_session(struct telegram *instance) assure_file_exists(instance->config_path, "secret"); write_auth_file(&instance->auth, instance->auth_path); write_state_file(&instance->proto, instance->state_path); - write_secret_chat_file(instance, instance->state_path); + write_secret_chat_file(instance, instance->secret_path); } void on_authorized(struct mtproto_connection *c, void* data);