about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-17 22:46:50 +0000
committerJames Booth <boothj5@gmail.com>2013-01-17 22:46:50 +0000
commitdad3cd2725acf5c38fa44e8b2260a18bd0fa440a (patch)
tree6d3d05129dbc55469c9d0994f4b9dcc86386f30d
parentfe87af0af85da01f8759fe00e199cde8f3397fea (diff)
downloadprofani-tty-dad3cd2725acf5c38fa44e8b2260a18bd0fa440a.tar.gz
Command /info parameter optional when in chat or private chat
Recipient is used.
-rw-r--r--src/command.c33
-rw-r--r--src/ui.h4
-rw-r--r--src/windows.c31
3 files changed, 60 insertions, 8 deletions
diff --git a/src/command.c b/src/command.c
index e0c18e8e..a95fbfa7 100644
--- a/src/command.c
+++ b/src/command.c
@@ -255,11 +255,12 @@ static struct cmd_t main_commands[] =
           NULL } } },
 
     { "/info",
-        _cmd_info, parse_args, 1, 1,
-        { "/info jid|nick", "Find out a contacts presence information.",
-        { "/info jid|nick",
-          "--------------",
+        _cmd_info, parse_args, 0, 1,
+        { "/info [jid|nick]", "Find out a contacts presence information.",
+        { "/info [jid|nick]",
+          "----------------",
           "Find out a contact, or room members presence information.",
+          "If in a chat window the parameter is not required, the current recipient will be used.",
           NULL } } },
 
     { "/join",
@@ -1672,9 +1673,29 @@ _cmd_info(gchar **args, struct cmd_help_t help)
         cons_show("You are not currently connected.");
     } else {
         if (win_current_is_groupchat()) {
-            win_show_status(usr);
+            if (usr != NULL) {
+                win_room_show_status(usr);
+            } else {
+                win_current_show("You must specify a nickname.");
+            }
+        } else if (win_current_is_chat()) {
+            if (usr != NULL) {
+                win_current_show("No parameter required when in chat.");
+            } else {
+                win_show_status();
+            }
+        } else if (win_current_is_private()) {
+            if (usr != NULL) {
+                win_current_show("No parameter required when in chat.");
+            } else {
+                win_private_show_status();
+            }
         } else {
-            cons_show_status(usr);
+            if (usr != NULL) {
+                cons_show_status(usr);
+            } else {
+                cons_show("Usage: %s", help.usage);
+            }
         }
     }
 
diff --git a/src/ui.h b/src/ui.h
index 1b7a4e99..b69c1f19 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -132,7 +132,9 @@ void win_show_room_member_nick_change(const char * const room,
 void win_show_room_nick_change(const char * const room, const char * const nick);
 void win_show_room_member_presence(const char * const room,
     const char * const nick, const char * const show, const char * const status);
-void win_show_status(const char * const contact);
+void win_room_show_status(const char * const contact);
+void win_show_status(void);
+void win_private_show_status(void);
 
 // console window actions
 void cons_about(void);
diff --git a/src/windows.c b/src/windows.c
index f708b4a3..e26ee37c 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -1184,7 +1184,36 @@ cons_show_status(const char * const contact)
 }
 
 void
-win_show_status(const char * const contact)
+win_show_status(void)
+{
+    char *recipient = win_current_get_recipient();
+    PContact pcontact = contact_list_get_contact(recipient);
+
+    if (pcontact != NULL) {
+        _win_show_contact(current, pcontact);
+    } else {
+        win_current_show("Error getting contact info.");
+    }
+}
+
+void
+win_private_show_status(void)
+{
+    Jid *jid = jid_create(win_current_get_recipient());
+
+    PContact pcontact = muc_get_participant(jid->barejid, jid->resourcepart);
+
+    if (pcontact != NULL) {
+        _win_show_contact(current, pcontact);
+    } else {
+        win_current_show("Error getting contact info.");
+    }
+
+    jid_destroy(jid);
+}
+
+void
+win_room_show_status(const char * const contact)
 {
     PContact pcontact = muc_get_participant(win_current_get_recipient(), contact);