changeset 444:5927c3bfba13

Add /status_to command
author Mikael Berthe <mikael@lilotux.net>
date Sun, 25 Sep 2005 00:33:56 +0200
parents d8ddb26b9c14
children 7bf6c0c6a714
files mcabber/src/commands.c mcabber/src/jabglue.c mcabber/src/jabglue.h mcabber/src/screen.c
diffstat 4 files changed, 60 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Thu Sep 22 19:27:13 2005 +0200
+++ b/mcabber/src/commands.c	Sun Sep 25 00:33:56 2005 +0200
@@ -34,6 +34,7 @@
 // Commands callbacks
 static void do_roster(char *arg);
 static void do_status(char *arg);
+static void do_status_to(char *arg);
 static void do_add(char *arg);
 static void do_del(char *arg);
 static void do_group(char *arg);
@@ -103,6 +104,8 @@
   //cmd_add("send_auth");
   cmd_add("set", "Set/query an option value", 0, 0, &do_set);
   cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status);
+  cmd_add("status_to", "Show or set your status for one recipient",
+          COMPL_JID, COMPL_STATUS, &do_status_to);
 
   // Status category
   compl_add_category_word(COMPL_STATUS, "online");
@@ -377,18 +380,16 @@
     scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
 }
 
-static void do_status(char *arg)
+//  setstatus(recipient, arg)
+// Set your Jabber status.
+// - if recipient is not NULL, the status is sent to this contact only
+// - arg must be "status message" (message is optional)
+static void setstatus(const char *recipient, const char *arg)
 {
   enum imstatus st;
   int len;
   char *msg;
 
-  if (!arg || (*arg == 0)) {
-    scr_LogPrint(LPRINT_NORMAL, "Your status is: %c",
-                 imstatus2char[jb_getstatus()]);
-    return;
-  }
-
   msg = strchr(arg, ' ');
   if (!msg)
     len = strlen(arg);
@@ -404,7 +405,7 @@
   else if (!strncasecmp(arg, "notavail",  len)) st = notavail;
   else if (!strncasecmp(arg, "free",      len)) st = freeforchat;
   else {
-    scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
+    scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!");
     return;
   }
 
@@ -414,7 +415,43 @@
   } else
     msg = NULL;
 
-  jb_setstatus(st, msg);
+  jb_setstatus(st, recipient, msg);
+}
+
+static void do_status(char *arg)
+{
+  if (!arg || (!*arg)) {
+    scr_LogPrint(LPRINT_NORMAL, "Your status is: %c",
+                 imstatus2char[jb_getstatus()]);
+    return;
+  }
+  setstatus(NULL, arg);
+}
+
+static void do_status_to(char *arg)
+{
+  char *id, *st;
+  if (!arg || (*arg == 0)) {
+    scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
+    return;
+  }
+
+  // Split recipient jid, status
+  id = g_strdup(arg);
+  st = strchr(id, ' ');
+  if (!st) {
+    scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
+    g_free(id);
+    return;
+  }
+
+  *st++ = 0;
+  while (*st && *st == ' ')
+    st++;
+
+  // FIXME check id =~ jabber id
+  scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", id, st);
+  setstatus(id, st);
 }
 
 static void do_add(char *arg)
--- a/mcabber/src/jabglue.c	Thu Sep 22 19:27:13 2005 +0200
+++ b/mcabber/src/jabglue.c	Sun Sep 25 00:33:56 2005 +0200
@@ -158,7 +158,7 @@
   if (!jc) return;
 
   // announce it to  everyone else
-  jb_setstatus(offline, "");
+  jb_setstatus(offline, NULL, "");
 
   // announce it to the user
   statehandler(jc, JCONN_STATE_OFF);
@@ -255,7 +255,7 @@
   return mystatus;
 }
 
-void jb_setstatus(enum imstatus st, const char *msg)
+void jb_setstatus(enum imstatus st, const char *recipient, const char *msg)
 {
   xmlnode x;
   gchar *utf8_msg;
@@ -264,6 +264,9 @@
 
   x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
 
+  if (recipient)
+    xmlnode_put_attrib(x, "to", recipient);
+
   switch(st) {
     case away:
         xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
@@ -315,7 +318,11 @@
   xmlnode_free(x);
   g_free(utf8_msg);
 
-  //sendvisibility();   ???
+  // If we didn't change our _global_ status, we are done
+  if (recipient) return;
+
+  // Buddy per buddy invisibility handling
+  //sendvisibility();
 
   // We'll need to update the roster if we switch to/from offline because
   // we don't know the presences of buddies when offline...
@@ -464,7 +471,7 @@
 
   //setautostatus(jhook.manualstatus);
 
-  jb_setstatus(available, NULL);
+  jb_setstatus(available, NULL, NULL);
   buddylist_build();
   /*
   for (i = 0; i < clist.count; i++) {
--- a/mcabber/src/jabglue.h	Thu Sep 22 19:27:13 2005 +0200
+++ b/mcabber/src/jabglue.h	Sun Sep 25 00:33:56 2005 +0200
@@ -46,7 +46,7 @@
 void jb_delbuddy(const char *jid);
 void jb_updatebuddy(const char *jid, const char *name, const char *group);
 inline enum imstatus jb_getstatus();
-void jb_setstatus(enum imstatus st, const char *msg);
+void jb_setstatus(enum imstatus st, const char *recipient, const char *msg);
 void jb_send_msg(const char *, const char *);
 void jb_send_raw(const char *str);
 void jb_keepalive();
--- a/mcabber/src/screen.c	Thu Sep 22 19:27:13 2005 +0200
+++ b/mcabber/src/screen.c	Sun Sep 25 00:33:56 2005 +0200
@@ -804,10 +804,10 @@
     oldstatus = jb_getstatus();
     msg = settings_opt_get("message_autoaway");
     if (!msg) msg = MSG_AUTOAWAY;
-    jb_setstatus(away, msg);
+    jb_setstatus(away, NULL, msg);
   } else {
     // Back
-    jb_setstatus(oldstatus, NULL);
+    jb_setstatus(oldstatus, NULL, NULL);
   }
 }