changeset 480:882e1acae422

Add /say_to command
author Mikael Berthe <mikael@lilotux.net>
date Tue, 04 Oct 2005 19:47:50 +0200
parents b82428ac107d
children fa9149832af2
files mcabber/doc/mcabber.1 mcabber/doc/mcabber.1.html mcabber/doc/mcabber.1.txt mcabber/src/commands.c mcabber/src/roster.c mcabber/src/roster.h mcabber/src/screen.c mcabber/src/screen.h
diffstat 8 files changed, 116 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/doc/mcabber.1	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/doc/mcabber.1	Tue Oct 04 19:47:50 2005 +0200
@@ -232,6 +232,10 @@
 Send the text message to the currently selected buddy\&. Can be useful if you want to send a message beginning with a slash, for example\&.
 
 .TP
+\fB/say_to\fR jid text
+Send the text message to the specified jid\&. Please note that this command doesn't set the default resource for a contact, so if you want to send several messages to a specific ressource you will have to use "/say_to" for each message\&.
+
+.TP
 \fB/status\fR [online|avail|invisible|free|dnd|notavail|away [StatusMessage]]
 Set the current status\&. If no status is specified, display the current status\&. If a status message is specified, it will overrride the message* variables\&.
 
--- a/mcabber/doc/mcabber.1.html	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/doc/mcabber.1.html	Tue Oct 04 19:47:50 2005 +0200
@@ -611,6 +611,15 @@
         if you want to send a message beginning with a slash, for example.
 </dd>
 <dt><b>
+/say_to jid text
+</b></dt>
+<dd>
+        Send the text message to the specified jid.
+        Please note that this command doesn't set the default resource for
+        a contact, so if you want to send several messages to a specific
+        ressource you will have to use "/say_to" for each message.
+</dd>
+<dt><b>
 /status [online|avail|invisible|free|dnd|notavail|away [StatusMessage]]
 </b></dt>
 <dd>
@@ -653,7 +662,7 @@
 <div id="footer">
 <p>
 Version 0.6.9-dev<br />
-Last updated 02-Oct-2005 23:33:31 CEST
+Last updated 04-Oct-2005 19:42:07 CEST
 </p>
 </div>
 </div>
--- a/mcabber/doc/mcabber.1.txt	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/doc/mcabber.1.txt	Tue Oct 04 19:47:50 2005 +0200
@@ -208,6 +208,12 @@
         Send the text message to the currently selected buddy.  Can be useful
         if you want to send a message beginning with a slash, for example.
 
+/say_to jid text::
+        Send the text message to the specified jid.
+        Please note that this command doesn't set the default resource for
+        a contact, so if you want to send several messages to a specific
+        ressource you will have to use "/say_to" for each message.
+
 /status [online|avail|invisible|free|dnd|notavail|away [StatusMessage]]::
         Set the current status.  If no status is specified, display the
         current status. +
--- a/mcabber/src/commands.c	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/src/commands.c	Tue Oct 04 19:47:50 2005 +0200
@@ -40,6 +40,7 @@
 static void do_group(char *arg);
 static void do_say(char *arg);
 static void do_msay(char *arg);
+static void do_say_to(char *arg);
 static void do_buffer(char *arg);
 static void do_clear(char *arg);
 static void do_info(char *arg);
@@ -101,6 +102,7 @@
   cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
           &do_roster);
   cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say);
+  cmd_add("say_to", "Say something to a specific buddy", 0, 0, &do_say_to);
   //cmd_add("search");
   //cmd_add("send_auth");
   cmd_add("set", "Set/query an option value", 0, 0, &do_set);
@@ -652,6 +654,54 @@
   scr_set_multimode(FALSE);
 }
 
+static void do_say_to(char *arg)
+{
+  char *jid, *msg;
+  char *bare_jid, *p;
+
+  if (!jb_getonline()) {
+    scr_LogPrint(LPRINT_NORMAL, "You are not connected");
+    return;
+  }
+
+  msg = strchr(arg, ' ');
+  if (!msg) {
+    scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
+    return;
+  }
+
+  jid = g_strndup(arg, msg - arg);
+
+  if (check_jid_syntax(jid)) {
+    scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid);
+    g_free(jid);
+    return;
+  }
+
+  while (*msg == ' ') msg++;
+  if (!*msg) {
+    scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter");
+    g_free(jid);
+    return;
+  }
+
+  // We must use the bare jid in hk_message_out()
+  p = strchr(jid, '/');
+  if (p) bare_jid = g_strndup(jid, p - jid);
+  else   bare_jid = jid;
+
+  // Jump to window, create one if needed
+  scr_RosterJumpJid(bare_jid);
+
+  // local part (UI, logging, etc.)
+  hk_message_out(bare_jid, 0, msg);
+
+  // Network part
+  jb_send_msg(jid, msg, ROSTER_TYPE_USER, NULL);
+  g_free(jid);
+  if (p) g_free(bare_jid);
+}
+
 static void do_buffer(char *arg)
 {
   int search_dir = 0;
--- a/mcabber/src/roster.c	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/src/roster.c	Tue Oct 04 19:47:50 2005 +0200
@@ -175,7 +175,7 @@
 // Comparison function used to search in the roster (compares jids and types)
 static gint roster_compare_jid_type(roster *a, roster *b) {
   if (! (a->type & b->type))
-    return -1; // arbitrary (but should be != , of course)
+    return -1; // arbitrary (but should be != 0, of course)
   return strcasecmp(a->jid, b->jid);
 }
 
@@ -197,7 +197,7 @@
   if (!jidname) return NULL;
 
   if (!roster_type)
-    roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM |
+    roster_type = ROSTER_TYPE_USER  | ROSTER_TYPE_ROOM |
                   ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP;
 
   sample.type = roster_type;
@@ -893,6 +893,25 @@
   return roster_usr->flags;
 }
 
+//  buddy_search_jid(jid)
+// Look for a buddy with specified jid.
+// Search begins at buddylist; if no match is found in the the buddylist,
+// return NULL;
+GList *buddy_search_jid(char *jid)
+{
+  GList *buddy;
+  roster *roster_usr;
+
+  if (!buddylist) return NULL;
+
+  for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) {
+    roster_usr = (roster*)buddy->data;
+    if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid))
+      return buddy;
+  }
+  return NULL;
+}
+
 //  buddy_search(string)
 // Look for a buddy whose name or jid contains string.
 // Search begins at current_buddy; if no match is found in the the buddylist,
--- a/mcabber/src/roster.h	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/src/roster.h	Tue Oct 04 19:47:50 2005 +0200
@@ -84,6 +84,7 @@
 void    buddy_del_all_resources(gpointer rosterdata);
 void    buddy_setflags(gpointer rosterdata, guint flags, guint value);
 guint   buddy_getflags(gpointer rosterdata);
+GList  *buddy_search_jid(char *jid);
 GList  *buddy_search(char *string);
 gpointer unread_msg(gpointer rosterdata);
 
--- a/mcabber/src/screen.c	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/src/screen.c	Tue Oct 04 19:47:50 2005 +0200
@@ -777,8 +777,8 @@
   doupdate();
 }
 
-void scr_WriteMessage(const char *jid, const char *text, time_t timestamp,
-        guint prefix_flags)
+inline void scr_WriteMessage(const char *jid, const char *text,
+                             time_t timestamp, guint prefix_flags)
 {
   if (!timestamp) timestamp = time(NULL);
 
@@ -918,6 +918,27 @@
     scr_ShowBuddyWindow();
 }
 
+//  scr_RosterJumpJid(jid)
+// Jump to buddy jid.
+// NOTE: With this function, the buddy is added to the roster if doesn't exist.
+void scr_RosterJumpJid(char *barejid)
+{
+  GSList *roster_elt;
+  // Look for an existing buddy
+  roster_elt = roster_find(barejid, jidsearch,
+                 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM);
+  // Create it if necessary
+  if (!roster_elt)
+    roster_elt = roster_add_user(barejid, NULL, NULL, ROSTER_TYPE_USER);
+  // Set a lock to see it in the buddylist
+  buddy_setflags(BUDDATA(roster_elt), ROSTER_FLAG_LOCK, TRUE);
+  buddylist_build();
+  // Jump to the buddy
+  set_current_buddy(buddy_search_jid(barejid));
+  if (chatmode)
+    scr_ShowBuddyWindow();
+}
+
 //  scr_RosterUnreadMessage(next)
 // Go to a new message.  If next is not null, try to go to the next new
 // message.  If it is not possible or if next is NULL, go to the first new
--- a/mcabber/src/screen.h	Mon Oct 03 23:59:56 2005 +0200
+++ b/mcabber/src/screen.h	Tue Oct 04 19:47:50 2005 +0200
@@ -51,6 +51,7 @@
 void scr_RosterUp(void);
 void scr_RosterDown(void);
 void scr_RosterSearch(char *);
+void scr_RosterJumpJid(char *);
 void scr_BufferTopBottom(int topbottom);
 void scr_BufferClear(void);
 void scr_BufferSearch(int direction, const char *text);