From f46b52644c9aa53f43bb3a828b31c0549007d9df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert=20P=C3=B6sel?= <robyer@seznam.cz>
Date: Sun, 23 Apr 2017 13:51:10 +0200
Subject: Facebook: New option to not send typing when invisible

Enabling it helps to not being marked as "active 1 min ago" by Facebook.
---
 protocols/FacebookRM/res/facebook.rc  | 4 ++++
 protocols/FacebookRM/src/constants.h  | 1 +
 protocols/FacebookRM/src/db.h         | 1 +
 protocols/FacebookRM/src/dialogs.cpp  | 2 ++
 protocols/FacebookRM/src/messages.cpp | 7 +++++++
 protocols/FacebookRM/src/resource.h   | 1 +
 6 files changed, 16 insertions(+)

(limited to 'protocols')

diff --git a/protocols/FacebookRM/res/facebook.rc b/protocols/FacebookRM/res/facebook.rc
index f791a3edd7..8c2597af6f 100644
--- a/protocols/FacebookRM/res/facebook.rc
+++ b/protocols/FacebookRM/res/facebook.rc
@@ -176,6 +176,10 @@ BEGIN
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,47,281,10
     CONTROL         "Allow posting statuses to my pages (may slow down login)",IDC_LOAD_PAGES,
                     "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,61,281,10
+    GROUPBOX        "Advanced",IDC_STATIC,7,85,294,67
+    CONTROL         "Don't send typing notifications when Invisible",IDC_NO_TYPING_WHEN_INVISIBLE,
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,98,281,10
+    LTEXT           "Typing is one way how user is determined active. If you don't want to be seen ""active 1 min ago"" on Facebook, enable this and also don't interact with website at all. Sending messages from Miranda should be ok, but don't 100% rely on it.",IDC_STATIC,32,112,262,39
 END
 
 IDD_CAPTCHAFORM DIALOGEX 0, 0, 258, 224
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h
index 3a8da1cdcf..8c527469ea 100644
--- a/protocols/FacebookRM/src/constants.h
+++ b/protocols/FacebookRM/src/constants.h
@@ -101,6 +101,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define DEFAULT_NAME_AS_NICK					1
 #define DEFAULT_LOAD_ALL_CONTACTS				0
 #define DEFAULT_PAGES_ALWAYS_ONLINE				1
+#define DEFAULT_NO_TYPING_WHEN_INVISIBLE		0
 
 #define DEFAULT_EVENT_NOTIFICATIONS_ENABLE		1
 #define DEFAULT_EVENT_FEEDS_ENABLE				0
diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h
index 85c3678d62..a7c4034c02 100644
--- a/protocols/FacebookRM/src/db.h
+++ b/protocols/FacebookRM/src/db.h
@@ -75,6 +75,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define FACEBOOK_KEY_NAME_AS_NICK			"NameAsNick"
 #define FACEBOOK_KEY_LOAD_ALL_CONTACTS		"LoadAllContacts"
 #define FACEBOOK_KEY_PAGES_ALWAYS_ONLINE	"PagesAlwaysOnline"
+#define FACEBOOK_KEY_NO_TYPING_WHEN_INVISIBLE	"NoTypingWhenInvisible"
 
 // Account DB keys - notifications
 #define FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE	"EventNotificationsEnable"
diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp
index 14c99e50cc..b4b12ad06d 100644
--- a/protocols/FacebookRM/src/dialogs.cpp
+++ b/protocols/FacebookRM/src/dialogs.cpp
@@ -449,6 +449,7 @@ INT_PTR CALLBACK FBOptionsStatusesProc(HWND hwnd, UINT message, WPARAM, LPARAM l
 		LoadDBCheckState(proto, hwnd, IDC_SET_STATUS, FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS);
 		LoadDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES, DEFAULT_MAP_STATUSES);
 		LoadDBCheckState(proto, hwnd, IDC_LOAD_PAGES, FACEBOOK_KEY_LOAD_PAGES, DEFAULT_LOAD_PAGES);
+		LoadDBCheckState(proto, hwnd, IDC_NO_TYPING_WHEN_INVISIBLE, FACEBOOK_KEY_NO_TYPING_WHEN_INVISIBLE, DEFAULT_NO_TYPING_WHEN_INVISIBLE);
 
 		return TRUE;
 	}
@@ -468,6 +469,7 @@ INT_PTR CALLBACK FBOptionsStatusesProc(HWND hwnd, UINT message, WPARAM, LPARAM l
 			StoreDBCheckState(proto, hwnd, IDC_DISCONNECT_CHAT, FACEBOOK_KEY_DISCONNECT_CHAT);
 			StoreDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES);
 			StoreDBCheckState(proto, hwnd, IDC_LOAD_PAGES, FACEBOOK_KEY_LOAD_PAGES);
+			StoreDBCheckState(proto, hwnd, IDC_NO_TYPING_WHEN_INVISIBLE, FACEBOOK_KEY_NO_TYPING_WHEN_INVISIBLE);
 
 			BOOL setStatus = IsDlgButtonChecked(hwnd, IDC_SET_STATUS);
 			BOOL setStatusOld = proto->getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS);
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index 1c5e786f9a..a2ada53862 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -133,6 +133,13 @@ void FacebookProto::SendTypingWorker(void *p)
 
 	send_typing *typing = static_cast<send_typing*>(p);
 
+	// Don't send typing notifications when we are invisible and user don't want that
+	bool noTypingWhenInvisible = getBool(FACEBOOK_KEY_NO_TYPING_WHEN_INVISIBLE, DEFAULT_NO_TYPING_WHEN_INVISIBLE);
+	if (noTypingWhenInvisible && isInvisible()) {
+		delete typing;
+		return;
+	}
+
 	// Dont send typing notifications to not friends - Facebook won't give them that info anyway
 	if (!isChatRoom(typing->hContact) && getWord(typing->hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) {
 		delete typing;
diff --git a/protocols/FacebookRM/src/resource.h b/protocols/FacebookRM/src/resource.h
index e5f5cccf9c..8a5cd10fe1 100644
--- a/protocols/FacebookRM/src/resource.h
+++ b/protocols/FacebookRM/src/resource.h
@@ -42,6 +42,7 @@
 #define IDC_PAGES_ALWAYS_ONLINE         1035
 #define IDC_LOAD_PAGES                  1036
 #define IDC_KEEP_UNREAD                 1037
+#define IDC_NO_TYPING_WHEN_INVISIBLE    1038
 #define IDC_MESSAGES_ON_OPEN            1039
 #define IDC_HIDE_CHATS                  1040
 #define IDC_NOTIFICATIONS_ENABLE        1041
-- 
cgit v1.2.3