Add option for disabling sending a message read recipes, and fix some bugs in adium settings menu

This commit is contained in:
mjentsch 2015-05-30 15:52:17 +02:00
parent 0033837210
commit e7554c739c
9 changed files with 70 additions and 27 deletions

View file

@ -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]

View file

@ -9,6 +9,7 @@
<connections>
<outlet property="checkbox_displayReadNotifications" destination="Tat-1e-jqI" id="1m9-1n-bKm"/>
<outlet property="checkbox_historySyncAll" destination="Qob-Rq-UJj" id="1dM-ig-DQa"/>
<outlet property="checkbox_sendReadNotifications" destination="4Xx-hY-Mzh" id="OMa-pG-ePd"/>
<outlet property="radio_Encryption" destination="RGC-Jo-M5e" id="gMv-Gj-Dyg"/>
<outlet property="textField_accountUID" destination="Mv3-b8-21b" id="Cxi-GZ-5oi"/>
<outlet property="textField_accountUIDLabel" destination="yae-v6-YMB" id="XHk-zX-T5y"/>
@ -80,11 +81,11 @@
<point key="canvasLocation" x="380.5" y="38"/>
</customView>
<customView id="DGa-mQ-g3C" userLabel="Options">
<rect key="frame" x="0.0" y="0.0" width="272" height="190"/>
<rect key="frame" x="0.0" y="6" width="272" height="248"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zRH-KJ-uvC" userLabel="Accept Secret Chats">
<rect key="frame" x="6" y="50" width="168" height="17"/>
<rect key="frame" x="6" y="60" width="168" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="Ignore history older than" id="MSN-Hj-aRS">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -92,7 +93,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="C4T-Hq-g5C" userLabel="Accept Secret Chats">
<rect key="frame" x="6" y="32" width="138" height="17"/>
<rect key="frame" x="6" y="42" width="138" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" id="ARj-qB-Q5Z">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -100,7 +101,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="gKj-Oj-qll">
<rect key="frame" x="176" y="45" width="49" height="22"/>
<rect key="frame" x="176" y="55" width="49" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="lVr-43-iAS">
<numberFormatter key="formatter" formatterBehavior="default10_4" numberStyle="decimal" minimumIntegerDigits="1" maximumIntegerDigits="2000000000" maximumFractionDigits="3" id="tH1-pY-m7Q"/>
<font key="font" metaFont="system"/>
@ -109,7 +110,7 @@
</textFieldCell>
</textField>
<matrix verticalHuggingPriority="750" fixedFrame="YES" allowsEmptySelection="NO" autorecalculatesCellSize="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RGC-Jo-M5e">
<rect key="frame" x="176" y="119" width="76" height="58"/>
<rect key="frame" x="176" y="177" width="76" height="58"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
<size key="cellSize" width="66" height="18"/>
<size key="intercellSpacing" width="4" height="2"/>
@ -135,7 +136,7 @@
</cells>
</matrix>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sb8-oa-s84">
<rect key="frame" x="231" y="50" width="126" height="14"/>
<rect key="frame" x="231" y="60" width="126" height="14"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="left" title="Days" id="cOl-DG-CvA">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@ -143,29 +144,29 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EEO-n2-kS3">
<rect key="frame" x="6" y="35" width="126" height="14"/>
<rect key="frame" x="6" y="45" width="126" height="14"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="left" title="(0 days for unlimited)" id="TQS-UR-EnH">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Tat-1e-jqI">
<rect key="frame" x="6" y="93" width="178" height="24"/>
<buttonCell key="cell" type="check" title="Display read notifications" bezelStyle="regularSquare" imagePosition="left" scrollable="YES" lineBreakMode="clipping" state="on" inset="2" id="l1g-r5-pNb">
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4Xx-hY-Mzh">
<rect key="frame" x="6" y="117" width="251" height="24"/>
<buttonCell key="cell" type="check" title="Send read notifications when present" bezelStyle="regularSquare" imagePosition="left" scrollable="YES" lineBreakMode="clipping" state="on" inset="2" id="vdV-Ig-yub">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qob-Rq-UJj">
<rect key="frame" x="6" y="73" width="213" height="18"/>
<rect key="frame" x="6" y="90" width="213" height="18"/>
<buttonCell key="cell" type="check" title="Fetch past history on first login" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="uu6-Td-pzN">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4Mf-Qx-mrn" userLabel="Accept Secret Chats">
<rect key="frame" x="6" y="160" width="135" height="17"/>
<rect key="frame" x="6" y="218" width="135" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" userInterfaceLayoutDirection="rightToLeft" alignment="left" title="Accept secret chats?" id="t4Q-j1-35n">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -173,7 +174,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Nvv-1I-L31">
<rect key="frame" x="176" y="10" width="49" height="22"/>
<rect key="frame" x="176" y="20" width="49" height="22"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="Pm0-Jw-ayL">
<numberFormatter key="formatter" formatterBehavior="default10_4" numberStyle="decimal" minimumIntegerDigits="1" maximumIntegerDigits="2000000000" maximumFractionDigits="3" id="L9W-52-Xg9"/>
<font key="font" metaFont="system"/>
@ -182,7 +183,7 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="m95-No-oJH" userLabel="Accept Secret Chats">
<rect key="frame" x="6" y="15" width="168" height="17"/>
<rect key="frame" x="6" y="25" width="168" height="17"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" userInterfaceLayoutDirection="rightToLeft" alignment="left" title="Display users offline after" id="zJx-0I-fdw">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
@ -190,15 +191,22 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TaV-3x-dxE">
<rect key="frame" x="231" y="15" width="126" height="14"/>
<rect key="frame" x="231" y="25" width="126" height="14"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="left" title="Days" id="Aav-dA-OrQ">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Tat-1e-jqI">
<rect key="frame" x="6" y="147" width="178" height="24"/>
<buttonCell key="cell" type="check" title="Display read notifications" bezelStyle="regularSquare" imagePosition="left" scrollable="YES" lineBreakMode="clipping" state="on" inset="2" id="l1g-r5-pNb">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
</button>
</subviews>
<point key="canvasLocation" x="356" y="294"/>
<point key="canvasLocation" x="356" y="323"/>
</customView>
<userDefaultsController representsSharedInstance="YES" id="OjL-yD-9te"/>
</objects>

View file

@ -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;

View file

@ -22,7 +22,7 @@
#import <Adium/AIService.h>
#import <AIUtilities/AIStringFormatter.h>
#import <AIUtilities/AIAttributedStringAdditions.h>
#import <AIUtilities/AIPopUpButtonAdditions.h>
#import <AIUtilities/AIPopUpButtonAdditions.h>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];

View file

@ -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;
}

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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);
}