diff --git a/telegram-purple.c b/telegram-purple.c index 6584382..e987765 100755 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -267,16 +267,6 @@ static void tgl_do_send_unescape_message (struct tgl_state *TLS, const char *mes g_free(raw); } -static tgl_peer_t *find_peer_by_name (struct tgl_state *TLS, const char *who) { - tgl_peer_t *peer = tgl_peer_get (TLS, TGL_MK_USER(atoi (who))); - if (peer) { return peer; } - peer = tgl_peer_get (TLS, TGL_MK_CHAT(atoi(who))); - if (peer) { return peer; } - peer = tgl_peer_get (TLS, TGL_MK_ENCR_CHAT(atoi(who))); - if (peer) { return peer; } - return NULL; -} - static void start_secret_chat (PurpleBlistNode *node, gpointer data) { PurpleBuddy *buddy = data; connection_data *conn = purple_connection_get_protocol_data ( @@ -454,8 +444,7 @@ static void update_user_handler (struct tgl_state *TLS, struct tgl_user *user, u } } -static void write_secret_chat_cb (struct tgl_state *TLS, void *extra, int success, struct tgl_secret_chat *E) { - debug ("update_secret_chat_handle success=%d", success); +static void write_secret_chat_gw (struct tgl_state *TLS, void *extra, int success, struct tgl_secret_chat *E) { if (!success) { return; } write_secret_chat_file (TLS); } @@ -468,7 +457,7 @@ struct accept_secret_chat_data { static void accept_secret_chat_cb (gpointer _data, const gchar *code) { struct accept_secret_chat_data *data = _data; - tgl_do_accept_encr_chat_request (data->TLS, data->U, write_secret_chat_cb, 0); + tgl_do_accept_encr_chat_request (data->TLS, data->U, write_secret_chat_gw, 0); g_free (data); } @@ -476,7 +465,6 @@ static void accept_secret_chat_cb (gpointer _data, const gchar *code) { static void decline_secret_chat_cb (gpointer _data, const gchar *code) { struct accept_secret_chat_data *data = _data; - /* TODO: implement the api call to cancel secret chats, see tgprpl_remove_buddy */ bl_do_encr_chat_delete (data->TLS, data->U); purple_blist_remove_buddy (p2tgl_buddy_find(data->TLS, data->U->id)); @@ -506,7 +494,7 @@ static void update_secret_chat_handler (struct tgl_state *TLS, struct tgl_secret const char* choice = purple_account_get_string (conn->pa, "accept-secret-chats", "ask"); if (! strcmp (choice, "always")) { - tgl_do_accept_encr_chat_request (TLS, U, write_secret_chat_cb, 0); + tgl_do_accept_encr_chat_request (TLS, U, write_secret_chat_gw, 0); } else if (! strcmp(choice, "ask")) { PurpleBuddy *who = p2tgl_buddy_find (TLS, TGL_MK_USER(U->user_id)); @@ -757,24 +745,24 @@ static GList *tgprpl_chat_join_info (PurpleConnection * gc) { static void tgprpl_login (PurpleAccount * acct) { debug ("tgprpl_login()\n"); - PurpleConnection *gc = purple_account_get_connection(acct); - char const *username = purple_account_get_username(acct); + PurpleConnection *gc = purple_account_get_connection (acct); + char const *username = purple_account_get_username (acct); struct tgl_state *TLS = tgl_state_alloc (); const char *dir = config_dir; - struct passwd *pw = getpwuid(getuid()); + struct passwd *pw = getpwuid (getuid ()); size_t len = strlen (dir) + strlen (pw->pw_dir) + 2 + strlen (username); TLS->base_path = malloc (len); snprintf (TLS->base_path, len, "%s/%s/%s", pw->pw_dir, dir, username); debug ("base configuration path: '%s'", TLS->base_path); - g_mkdir_with_parents(TLS->base_path, 0700); + g_mkdir_with_parents (TLS->base_path, 0700); len += strlen ("/downloads"); char *ddir = malloc (len); sprintf (ddir, "%s/downloads", TLS->base_path); tgl_set_download_directory (TLS, ddir); - g_mkdir_with_parents(ddir, 0700); + g_mkdir_with_parents (ddir, 0700); free (ddir); tgl_set_verbosity (TLS, 4); @@ -1093,7 +1081,7 @@ static PurplePluginProtocolInfo prpl_info = { NULL, // normalize tgprpl_set_buddy_icon, NULL, // remove_group - NULL, // get_cb_real_name + NULL, NULL, // set_chat_topic NULL, // find_blist_chat NULL, // roomlist_get_list diff --git a/tgp-2prpl.c b/tgp-2prpl.c index b9292a1..a3e6d17 100644 --- a/tgp-2prpl.c +++ b/tgp-2prpl.c @@ -51,7 +51,7 @@ int p2tgl_status_is_present (PurpleStatus *status) return !(strcmp (name, "unavailable") == 0 || strcmp (name, "away") == 0); } -static PurpleChat *blist_find_chat_by_hasht_cond(PurpleConnection *gc, +static PurpleChat *blist_find_chat_by_hasht_cond (PurpleConnection *gc, int (*fn)(GHashTable *hasht, void *data), void *data) { PurpleAccount *account = purple_connection_get_account(gc); PurpleBlistNode *node = purple_blist_get_root(); diff --git a/tgp-utils.c b/tgp-utils.c index 21244d1..cafa54c 100644 --- a/tgp-utils.c +++ b/tgp-utils.c @@ -48,6 +48,16 @@ int out_msg (struct tgl_state *TLS, struct tgl_message *M) { return M->out; } +tgl_peer_t *find_peer_by_name (struct tgl_state *TLS, const char *who) { + tgl_peer_t *peer = tgl_peer_get (TLS, TGL_MK_USER(atoi (who))); + if (peer) { return peer; } + peer = tgl_peer_get (TLS, TGL_MK_CHAT(atoi(who))); + if (peer) { return peer; } + peer = tgl_peer_get (TLS, TGL_MK_ENCR_CHAT(atoi(who))); + if (peer) { return peer; } + return NULL; +} + tgl_peer_t *tgp_encr_chat_get_partner (struct tgl_state *TLS, struct tgl_secret_chat *chat) { return tgl_peer_get (TLS, TGL_MK_USER(chat->admin_id == TLS->our_id ? chat->user_id : chat->admin_id)); } diff --git a/tgp-utils.h b/tgp-utils.h index d3daefa..894e1b2 100644 --- a/tgp-utils.h +++ b/tgp-utils.h @@ -26,9 +26,7 @@ #include tgl_peer_t *tgp_encr_chat_get_partner (struct tgl_state *TLS, struct tgl_secret_chat *chat); -const char *format_time (time_t date); -char *format_img_full (int imgstore); -int str_not_empty (const char *string); +tgl_peer_t *find_peer_by_name (struct tgl_state *TLS, const char *who); /** * Return whether this message was created by our client in this session @@ -40,6 +38,9 @@ int our_msg (struct tgl_state *TLS, struct tgl_message *M); */ int out_msg (struct tgl_state *TLS, struct tgl_message *M); +const char *format_time (time_t date); +char *format_img_full (int imgstore); +int str_not_empty (const char *string); char *tgp_g_format_size (gint64 size); void tgp_g_queue_free_full (GQueue *queue, GDestroyNotify free_func);