about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-06-17 15:43:54 +0300
committerMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-06-17 15:43:54 +0300
commite4e53d6e01642e0f4ca98d7fb41e20d39d045bfe (patch)
tree741f5bc49d30c65fd61275452e63763204b7cc6c /src/ui
parent476c73251c2787930f866c76484eb1417a834cea (diff)
downloadprofani-tty-e4e53d6e01642e0f4ca98d7fb41e20d39d045bfe.tar.gz
Don't forget encryption status for OX and PGP.
Use a pgp.enabled and ox.enabled array the same way that omemo.enabled
is used.

Fixes https://github.com/profanity-im/profanity/issues/1694
Fixes https://github.com/profanity-im/profanity/issues/733
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/chatwin.c60
1 files changed, 53 insertions, 7 deletions
diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c
index b9fae2af..4088ae38 100644
--- a/src/ui/chatwin.c
+++ b/src/ui/chatwin.c
@@ -60,6 +60,36 @@
 static void _chatwin_history(ProfChatWin* chatwin, const char* const contact_barejid);
 static void _chatwin_set_last_message(ProfChatWin* chatwin, const char* const id, const char* const message);
 
+gboolean
+_pgp_automatic_start(const char* const recipient)
+{
+    gboolean result = FALSE;
+    char* account_name = session_get_account_name();
+    ProfAccount* account = accounts_get_account(account_name);
+
+    if (g_list_find_custom(account->pgp_enabled, recipient, (GCompareFunc)g_strcmp0)) {
+        result = TRUE;
+    }
+
+    account_free(account);
+    return result;
+}
+
+gboolean
+_ox_automatic_start(const char* const recipient)
+{
+    gboolean result = FALSE;
+    char* account_name = session_get_account_name();
+    ProfAccount* account = accounts_get_account(account_name);
+
+    if (g_list_find_custom(account->ox_enabled, recipient, (GCompareFunc)g_strcmp0)) {
+        result = TRUE;
+    }
+
+    account_free(account);
+    return result;
+}
+
 ProfChatWin*
 chatwin_new(const char* const barejid)
 {
@@ -82,20 +112,36 @@ chatwin_new(const char* const barejid)
 
     // We start a new OMEMO session if this contact has been configured accordingly.
     // However, if OTR is *also* configured, ask the user to choose between OMEMO and OTR.
-#ifdef HAVE_OMEMO
+
+    gboolean is_ox_secure = FALSE;
     gboolean is_otr_secure = FALSE;
+    gboolean is_omemo_secure = FALSE;
+#ifdef HAVE_LIBGPGME
+    is_ox_secure = _ox_automatic_start(barejid);
+#endif
+
+#ifdef HAVE_OMEMO
+    is_omemo_secure = omemo_automatic_start(barejid);
+#endif
+
 #ifdef HAVE_LIBOTR
     is_otr_secure = otr_is_secure(barejid);
-#endif // HAVE_LIBOTR
-    if (omemo_automatic_start(barejid) && is_otr_secure) {
-        win_println(window, THEME_DEFAULT, "!", "This chat could be either OMEMO or OTR encrypted, but not both. "
-                                                "Use '/omemo start' or '/otr start' to select the encryption method.");
-    } else if (omemo_automatic_start(barejid)) {
+#endif
+
+    if (is_omemo_secure + is_otr_secure + _pgp_automatic_start(barejid) + is_ox_secure > 1) {
+        win_println(window, THEME_DEFAULT, "!", "This chat could be either OMEMO, PGP, OX or OTR encrypted, but not more than one. "
+                                                "Use '/omemo start', '/pgp start', '/ox start' or '/otr start' to select the encryption method.");
+    } else if (is_omemo_secure) {
         // Start the OMEMO session
         omemo_start_session(barejid);
         chatwin->is_omemo = TRUE;
+    } else if (_pgp_automatic_start(barejid)) {
+        // Start the PGP session
+        chatwin->pgp_send = TRUE;
+    } else if (is_ox_secure) {
+        // Start the OX session
+        chatwin->is_ox = TRUE;
     }
-#endif // HAVE_OMEMO
 
     if (prefs_get_boolean(PREF_MAM)) {
         iq_mam_request(chatwin);