about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-13 19:12:23 +0000
committerJames Booth <boothj5@gmail.com>2014-01-13 19:12:23 +0000
commitbc1d4df2303f31f0bd97aa2c15e4494e17291963 (patch)
tree8c86242195b37ef158e9aa221a70965431f05744
parent671fa839e8f41b28a792893e7e1a42056f768594 (diff)
downloadprofani-tty-bc1d4df2303f31f0bd97aa2c15e4494e17291963.tar.gz
Open new chat win, or use existing for /otr start <contact>
-rw-r--r--src/command/commands.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index ac5397a6..75c478b0 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2331,18 +2331,34 @@ cmd_otr(gchar **args, struct cmd_help_t help)
         }
         return TRUE;
     } else if (strcmp(args[0], "start") == 0) {
-        win_type_t win_type = ui_current_win_type();
+        if (args[1] != NULL) {
+            char *contact = args[1];
+            char *barejid = roster_barejid_from_name(contact);
+            if (barejid == NULL) {
+                barejid = contact;
+            }
 
-        if (win_type != WIN_CHAT) {
-            ui_current_print_line("You must be in a regular chat window to start an OTR session.");
-        } else if (ui_current_win_is_otr()) {
-            ui_current_print_line("You are already in an OTR session.");
+            if (prefs_get_boolean(PREF_STATES)) {
+                if (!chat_session_exists(barejid)) {
+                    chat_session_start(barejid, TRUE);
+                }
+            }
+
+            ui_new_chat_win(barejid);
         } else {
-            if (!otr_key_loaded()) {
-                ui_current_print_line("You have not generated or loaded a private key, use '/otr gen'");
+            win_type_t win_type = ui_current_win_type();
+
+            if (win_type != WIN_CHAT) {
+                ui_current_print_line("You must be in a regular chat window to start an OTR session.");
+            } else if (ui_current_win_is_otr()) {
+                ui_current_print_line("You are already in an OTR session.");
             } else {
-                char *recipient = ui_current_recipient();
-                message_send("?OTR?", recipient);
+                if (!otr_key_loaded()) {
+                    ui_current_print_line("You have not generated or loaded a private key, use '/otr gen'");
+                } else {
+                    char *recipient = ui_current_recipient();
+                    message_send("?OTR?", recipient);
+                }
             }
         }
         return TRUE;