diff --git a/telegram-adium/TelegramAccount.m b/telegram-adium/TelegramAccount.m index fe65d8f..747e3c0 100644 --- a/telegram-adium/TelegramAccount.m +++ b/telegram-adium/TelegramAccount.m @@ -51,6 +51,11 @@ { [super configurePurpleAccount]; + purple_account_set_string (account, TGP_KEY_PASSWORD_TWO_FACTOR, + [[self preferenceForKey:@"Telegram:"TGP_KEY_PASSWORD_TWO_FACTOR + group:GROUP_ACCOUNT_STATUS] + UTF8String]); + purple_account_set_string (account, TGP_KEY_ACCEPT_SECRET_CHATS, [[self preferenceForKey:@"Telegram:"TGP_KEY_ACCEPT_SECRET_CHATS group:GROUP_ACCOUNT_STATUS] @@ -61,6 +66,11 @@ group:GROUP_ACCOUNT_STATUS] boolValue]); + purple_account_set_bool (account, TGP_KEY_SEND_READ_NOTIFICATIONS, + [[self preferenceForKey:@"Telegram:"TGP_KEY_SEND_READ_NOTIFICATIONS + group:GROUP_ACCOUNT_STATUS] + boolValue]); + purple_account_set_bool (account, TGP_KEY_HISTORY_SYNC_ALL, [[self preferenceForKey:@"Telegram:"TGP_KEY_HISTORY_SYNC_ALL group:GROUP_ACCOUNT_STATUS] diff --git a/telegram-adium/TelegramAccountView.xib b/telegram-adium/TelegramAccountView.xib index 7d65ded..e510fff 100644 --- a/telegram-adium/TelegramAccountView.xib +++ b/telegram-adium/TelegramAccountView.xib @@ -9,6 +9,7 @@ + @@ -80,11 +81,11 @@ - + - + @@ -92,7 +93,7 @@ - + @@ -100,7 +101,7 @@ - + @@ -109,7 +110,7 @@ - + @@ -135,7 +136,7 @@ - + @@ -143,29 +144,29 @@ - + - - + @@ -173,7 +174,7 @@ - + @@ -182,7 +183,7 @@ - + @@ -190,15 +191,22 @@ - + + - + diff --git a/telegram-adium/TelegramAccountViewController.h b/telegram-adium/TelegramAccountViewController.h index 594fed4..510c17b 100644 --- a/telegram-adium/TelegramAccountViewController.h +++ b/telegram-adium/TelegramAccountViewController.h @@ -22,6 +22,7 @@ @interface TelegramAccountViewController : PurpleAccountViewController { IBOutlet NSButton *checkbox_historySyncAll; IBOutlet NSButton *checkbox_displayReadNotifications; + IBOutlet NSButton *checkbox_sendReadNotifications; IBOutlet NSTextField *textField_maxMsgSplitCount; IBOutlet NSTextField *textField_inactiveDaysOffline; diff --git a/telegram-adium/TelegramAccountViewController.m b/telegram-adium/TelegramAccountViewController.m index 8743201..4efb68e 100644 --- a/telegram-adium/TelegramAccountViewController.m +++ b/telegram-adium/TelegramAccountViewController.m @@ -22,7 +22,7 @@ #import #import #import -#import +#import DISPLAY #include "telegram-purple.h" @@ -55,8 +55,11 @@ id s = [account preferenceForKey:@"Telegram:"TGP_KEY_HISTORY_SYNC_ALL group:GROUP_ACCOUNT_STATUS]; [checkbox_historySyncAll setState:[s boolValue]]; - id s4 = [account preferenceForKey:@"Telegram:"TGP_KEY_DISPLAY_READ_NOTIFICATIONS group:GROUP_ACCOUNT_STATUS]; - [checkbox_displayReadNotifications setState:[s4 boolValue]]; + id read = [account preferenceForKey:@"Telegram:"TGP_KEY_DISPLAY_READ_NOTIFICATIONS group:GROUP_ACCOUNT_STATUS]; + [checkbox_displayReadNotifications setState:[read boolValue]]; + + id send = [account preferenceForKey:@"Telegram:"TGP_KEY_SEND_READ_NOTIFICATIONS group:GROUP_ACCOUNT_STATUS]; + [checkbox_sendReadNotifications setState:[send boolValue]]; NSString *inactiveDaysOffline = [account preferenceForKey:@"Telegram:"TGP_KEY_INACTIVE_DAYS_OFFLINE @@ -91,6 +94,10 @@ forKey:@"Telegram:"TGP_KEY_DISPLAY_READ_NOTIFICATIONS group:GROUP_ACCOUNT_STATUS]; + [account setPreference:[NSNumber numberWithBool: [checkbox_sendReadNotifications state]] + forKey:@"Telegram:"TGP_KEY_SEND_READ_NOTIFICATIONS + group:GROUP_ACCOUNT_STATUS]; + [account setPreference:[textField_historyRetrieveDays stringValue] forKey:@"Telegram:"TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD group:GROUP_ACCOUNT_STATUS]; diff --git a/telegram-purple.c b/telegram-purple.c index e547f6c..7147087 100755 --- a/telegram-purple.c +++ b/telegram-purple.c @@ -563,7 +563,7 @@ static void tgprpl_set_status (PurpleAccount * acct, PurpleStatus * status) { if (!gc) { return; } connection_data *conn = purple_connection_get_protocol_data (gc); - if (p2tgl_status_is_present(status)) { + if (p2tgl_status_is_present (status) && p2tgl_send_notifications (acct)) { pending_reads_send_all (conn->pending_reads, conn->TLS); } } @@ -812,12 +812,20 @@ static void tgprpl_init (PurplePlugin *plugin) { TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD, TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD); prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt); + + + // Read notifications opt = purple_account_option_bool_new ("Display read notifications", TGP_KEY_DISPLAY_READ_NOTIFICATIONS, TGP_DEFAULT_DISPLAY_READ_NOTIFICATIONS); prpl_info.protocol_options = g_list_append (prpl_info.protocol_options, opt); + opt = purple_account_option_bool_new ("Send read notifications when present.", + TGP_KEY_SEND_READ_NOTIFICATIONS, + TGP_DEFAULT_SEND_READ_NOTIFICATIONS); + 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 529018b..9e3983d 100644 --- a/telegram-purple.h +++ b/telegram-purple.h @@ -39,22 +39,25 @@ #define TGP_MAX_MSG_SIZE 4096 #define TGP_DEFAULT_MAX_MSG_SPLIT_COUNT 4 +#define TGP_KEY_PASSWORD_TWO_FACTOR "password-two-factor" + #define TGP_DEFAULT_ACCEPT_SECRET_CHATS "ask" #define TGP_KEY_ACCEPT_SECRET_CHATS "accept-secret-chats" #define TGP_DEFAULT_INACTIVE_DAYS_OFFLINE 7 #define TGP_KEY_INACTIVE_DAYS_OFFLINE "inactive-days-offline" -#define TGP_DEFAULT_DISPLAY_READ_NOTIFICATIONS FALSE -#define TGP_KEY_DISPLAY_READ_NOTIFICATIONS "display-read-notifications" - #define TGP_DEFAULT_HISTORY_RETRIEVAL_THRESHOLD 14 #define TGP_KEY_HISTORY_RETRIEVAL_THRESHOLD "history-retrieve-days" #define TGP_KEY_HISTORY_SYNC_ALL "history-sync-all" #define TGP_DEFAULT_HISTORY_SYNC_ALL FALSE -#define TGP_KEY_PASSWORD_TWO_FACTOR "password-two-factor" +#define TGP_DEFAULT_DISPLAY_READ_NOTIFICATIONS FALSE +#define TGP_KEY_DISPLAY_READ_NOTIFICATIONS "display-read-notifications" + +#define TGP_DEFAULT_SEND_READ_NOTIFICATIONS TRUE +#define TGP_KEY_SEND_READ_NOTIFICATIONS "send-read-notifications" void on_chat_get_info (struct tgl_state *TLS, void *extra, int success, struct tgl_chat *C); void on_ready (struct tgl_state *TLS); diff --git a/tgp-2prpl.c b/tgp-2prpl.c index 48d134b..27f979c 100644 --- a/tgp-2prpl.c +++ b/tgp-2prpl.c @@ -50,12 +50,17 @@ gchar *p2tgl_strdup_alias (tgl_peer_t *user) { return g_strdup (user->print_name); } -int p2tgl_status_is_present (PurpleStatus *status) -{ +int p2tgl_status_is_present (PurpleStatus *status) { const char *name = purple_status_get_id (status); return !(strcmp (name, "unavailable") == 0 || strcmp (name, "away") == 0); } +int p2tgl_send_notifications (PurpleAccount *acct) { + int ret = purple_account_get_bool (acct, TGP_KEY_SEND_READ_NOTIFICATIONS, TGP_DEFAULT_SEND_READ_NOTIFICATIONS); + debug ("sending notifications: %d", ret); + return ret; +} + /* Disclaimer: I stole this function from davidgfnet's whatsapp plugin, all credit for it goes to him diff --git a/tgp-2prpl.h b/tgp-2prpl.h index 62c42e3..0efdad0 100644 --- a/tgp-2prpl.h +++ b/tgp-2prpl.h @@ -38,6 +38,7 @@ char *p2tgl_strdup_id (tgl_peer_id_t user); char *p2tgl_strdup_alias(tgl_peer_t *user); int p2tgl_status_is_present (PurpleStatus *status); +int p2tgl_send_notifications (PurpleAccount *acct); PurpleConversation *p2tgl_got_joined_chat (struct tgl_state *TLS, struct tgl_chat *chat); void p2tgl_got_chat_invite (PurpleConnection *gc, tgl_peer_t *chat, tgl_peer_id_t inviter, const char *message); diff --git a/tgp-msg.c b/tgp-msg.c index 1b0150a..ea3beb2 100644 --- a/tgp-msg.c +++ b/tgp-msg.c @@ -376,7 +376,7 @@ static void tgp_msg_display (struct tgl_state *TLS, struct tgp_msg_loading *C) { } } - if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa))) { + if (p2tgl_status_is_present (purple_account_get_active_status (conn->pa)) && p2tgl_send_notifications(conn->pa)) { pending_reads_send_all (conn->pending_reads, conn->TLS); }