diff --git a/telegram-base.c b/telegram-base.c index de06b49..58026c7 100644 --- a/telegram-base.c +++ b/telegram-base.c @@ -259,7 +259,7 @@ static void code_auth_receive_result (struct tgl_state *TLS, void *extra, int su } } -static void request_code_entered (gpointer data, const gchar *code) { +void request_code_entered (gpointer data, const gchar *code) { struct tgl_state *TLS = data; telegram_conn *conn = TLS->ev_base; char const *username = purple_account_get_username(conn->pa); @@ -299,16 +299,15 @@ static void request_code (struct tgl_state *TLS) { "Telegram wants to verify your identity, please enter the code, that you have received via SMS.", NULL, 0, 0, "code", "OK", G_CALLBACK(request_code_entered), "Cancel", G_CALLBACK(request_code_canceled), conn->pa, NULL, NULL, TLS)) { - const char *sms = purple_account_get_string(tg_get_acc(TLS), "code", ""); - if (*sms == '\0') { - const char *error = "Could not prompt for sms code, please set SMS code in account settings and reconnect."; - purple_connection_error_reason(conn->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, error); - purple_notify_error(_telegram_protocol, "Enter SMS code", "Enter SMS code", error); - return; - } - - request_code_entered (TLS, sms); - purple_account_set_string(tg_get_acc(TLS), "code", ""); + + // purple request API is not available, so we create a new conversation (the Telegram system + // account "7770000") to prompt the user for the code + + conn->in_fallback_chat = 1; + purple_connection_set_state (conn->gc, PURPLE_CONNECTED); + PurpleConversation *conv = purple_conversation_new (PURPLE_CONV_TYPE_IM, conn->pa, "777000"); + purple_conversation_write (conv, "777000", "What is your SMS verification code?", + PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, 0); } } diff --git a/telegram-base.h b/telegram-base.h index 76a5b28..5d6a484 100644 --- a/telegram-base.h +++ b/telegram-base.h @@ -28,4 +28,5 @@ void telegram_login (struct tgl_state *TLS); PurpleConversation *chat_show (PurpleConnection *gc, int id); int chat_add_message (struct tgl_state *TLS, struct tgl_message *M, char *text); void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat); +void request_code_entered (gpointer data, const gchar *code); #endif diff --git a/telegram-purple.c b/telegram-purple.c index 1369e9f..6de30a3 100644 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -648,6 +648,14 @@ static int tgprpl_send_im (PurpleConnection * gc, const char *who, const char *m telegram_conn *conn = purple_connection_get_protocol_data(gc); PurpleAccount *pa = conn->pa; + + // this is part of a workaround to support clients without + // the request API (request.h), see telegram-base.c:request_code() + if (conn->in_fallback_chat) { + request_code_entered (conn->TLS, message); + conn->in_fallback_chat = 0; + return 1; + } PurpleBuddy *b = purple_find_buddy (pa, who); if (!b) { @@ -914,18 +922,12 @@ static PurplePluginProtocolInfo prpl_info = { static void tgprpl_init (PurplePlugin *plugin) { - //PurpleAccountOption *option; - //GList *verification_values = NULL; - PurpleAccountOption *opt; opt = purple_account_option_bool_new("Compatibility Mode (read SMS code from settings)", "compat-verification", 0); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt); - opt = purple_account_option_string_new("SMS Code", "code", ""); - prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, opt); - _telegram_protocol = plugin; } diff --git a/telegram-purple.h b/telegram-purple.h index bb02709..3b36565 100644 --- a/telegram-purple.h +++ b/telegram-purple.h @@ -47,6 +47,7 @@ typedef struct { GQueue *new_messages; GHashTable *joining_chats; guint timer; + int in_fallback_chat; } telegram_conn; struct download_desc {