about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-11-27 21:53:56 +0000
committerJames Booth <boothj5@gmail.com>2012-11-27 21:53:56 +0000
commitebf8911ffc2fc10c66f3c72c2958119d1e41b4db (patch)
tree861b6dfc0a21ea5ea95d2de9983837558096db71 /src
parent4e78f8f14902e5ff496d9213afcee28b7e5d1f68 (diff)
downloadprofani-tty-ebf8911ffc2fc10c66f3c72c2958119d1e41b4db.tar.gz
Implemented /sub show
Diffstat (limited to 'src')
-rw-r--r--src/command.c28
-rw-r--r--src/ui.h2
-rw-r--r--src/windows.c13
3 files changed, 37 insertions, 6 deletions
diff --git a/src/command.c b/src/command.c
index 7ca54b71..705be6de 100644
--- a/src/command.c
+++ b/src/command.c
@@ -982,6 +982,11 @@ _cmd_sub(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
+    if (!win_current_is_chat() && (jid == NULL)) {
+        cons_show("You must specify a contact.");
+        return TRUE;
+    }
+
     if (jid != NULL) {
         jid = strdup(jid);
     } else {
@@ -1003,7 +1008,28 @@ _cmd_sub(gchar **args, struct cmd_help_t help)
         cons_show("Sent subscription request to %s.", bare_jid);
         log_info("Sent subscription request to %s.", bare_jid);
     } else if (strcmp(subcmd, "show") == 0) {
-        /* TODO: not implemented yet */
+        PContact contact = contact_list_get_contact(bare_jid);
+        if (contact == NULL) {
+            if (win_current_is_chat()) {
+                win_current_show("No subscription information for %s.", bare_jid);
+            } else {
+                cons_show("No subscription information for %s.", bare_jid);
+            }
+        } else if (p_contact_subscription(contact) == NULL) {
+            if (win_current_is_chat()) {
+                win_current_show("No subscription information for %s.", bare_jid);
+            } else {
+                cons_show("No subscription information for %s.", bare_jid);
+            }
+        } else {
+            if (win_current_is_chat()) {
+                win_current_show("%s subscription status: %s.", bare_jid,
+                    p_contact_subscription(contact));
+            } else {
+                cons_show("%s subscription status: %s.", bare_jid,
+                    p_contact_subscription(contact));
+            }
+        }
     } else {
         cons_show("Usage: %s", help.usage);
     }
diff --git a/src/ui.h b/src/ui.h
index 02128714..981407b5 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -98,7 +98,7 @@ int win_current_is_chat(void);
 int win_current_is_groupchat(void);
 int win_current_is_private(void);
 char* win_current_get_recipient(void);
-void win_current_show(const char * const msg);
+void win_current_show(const char * const msg, ...);
 void win_current_bad_show(const char * const msg);
 void win_current_page_off(void);
 
diff --git a/src/windows.c b/src/windows.c
index f75c0bb9..6efc9e19 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -488,11 +488,16 @@ win_current_get_recipient(void)
 }
 
 void
-win_current_show(const char * const msg)
+win_current_show(const char * const msg, ...)
 {
-    WINDOW *win = current->win;
-    _win_show_time(win);
-    wprintw(win, "%s\n", msg);
+    va_list arg;
+    va_start(arg, msg);
+    GString *fmt_msg = g_string_new(NULL);
+    g_string_vprintf(fmt_msg, msg, arg);
+    _win_show_time(current->win);
+    wprintw(current->win, "%s\n", fmt_msg->str);
+    g_string_free(fmt_msg, TRUE);
+    va_end(arg);
 
     dirty = TRUE;
 }