Mikael Berthe avatar Mikael Berthe committed e6beab2

Do not add items to roster with commands /move and /rename (Hermitifier)
Do not add items to roster with commands /move and /rename.
For MUC, store relevant information in the bookmark.

Comments (0)

Files changed (4)

mcabber/mcabber/commands.c

 static void move_group_member(gpointer bud, void *groupnamedata)
 {
   const char *bjid, *name, *groupname;
+  guint on_srv;
 
   groupname = (char *)groupnamedata;
 
   bjid = buddy_getjid(bud);
   name = buddy_getname(bud);
-
-  xmpp_updatebuddy(bjid, name, *groupname ? groupname : NULL);
+  on_srv = buddy_getonserverflag(bud);
+
+  if (on_srv)
+    xmpp_updatebuddy(bjid, name, *groupname ? groupname : NULL);
+  else
+    buddy_setname(bud, (char*)name);
 }
 
 static void do_rename(char *arg)
     return;
   }
 
-  if (!(type & ROSTER_TYPE_GROUP) && !on_srv) {
-    scr_LogPrint(LPRINT_NORMAL,
-                 "Note: this item will be added to your server roster.");
-    // If this is a MUC room w/o bookmark, let's give a small hint...
-    if ((type & ROSTER_TYPE_ROOM) && !xmpp_is_bookmarked(bjid)) {
-      scr_LogPrint(LPRINT_NORMAL,
-                   "You should add a room bookmark or it will not be "
-                   "recognized as a MUC room next time you run mcabber.");
-    }
-  }
+  //if (!(type & ROSTER_TYPE_GROUP) && !on_srv) {
+  //  scr_LogPrint(LPRINT_NORMAL,
+  //               "Note: this item will be added to your server roster.");
+  //  // If this is a MUC room w/o bookmark, let's give a small hint...
+  //  if ((type & ROSTER_TYPE_ROOM) && !xmpp_is_bookmarked(bjid)) {
+  //    scr_LogPrint(LPRINT_NORMAL,
+  //                 "You should add a room bookmark or it will not be "
+  //                 "recognized as a MUC room next time you run mcabber.");
+  //  }
+  //}
 
   newname = g_strdup(arg);
   // Remove trailing space
     guint del_name = 0;
     if (!*newname || !strcmp(arg, "-"))
       del_name = TRUE;
-    /* We do not rename the buddy right now because the server could reject
-     * the request.  Let's wait for the server answer.
-     * buddy_setname(bud, (del_name ? (char*)bjid : name_utf8));
-     */
-    xmpp_updatebuddy(bjid, (del_name ? NULL : name_utf8), group);
+    if (on_srv) {
+      /* We do not rename the buddy right now because the server could reject
+       * the request.  Let's wait for the server answer.
+       */
+      xmpp_updatebuddy(bjid, (del_name ? NULL : name_utf8), group);
+    } else {
+      // This is a local item, we rename it without adding to roster.
+      buddy_setname(bud, (del_name ? (char*)bjid : name_utf8));
+    }
   }
 
   g_free(name_utf8);
 {
   gpointer bud;
   const char *bjid, *name, *oldgroupname;
-  guint type;
+  guint type, on_srv;
   char *newgroupname, *p;
   char *group_utf8;
 
   bjid = buddy_getjid(bud);
   name = buddy_getname(bud);
   type = buddy_gettype(bud);
+  on_srv = buddy_getonserverflag(bud);
 
   oldgroupname = buddy_getgroupname(bud);
 
 
   group_utf8 = to_utf8(newgroupname);
   if (strcmp(oldgroupname, group_utf8)) {
-    /* guint msgflag; */
-
-    xmpp_updatebuddy(bjid, name, *group_utf8 ? group_utf8 : NULL);
-    scr_roster_up_down(-1, 1);
-
-    /* We do not move the buddy right now because the server could reject
-     * the request.  Let's wait for the server answer.
-
-    // If the buddy has a pending message flag,
-    // we remove it temporarily in order to reset the global group
-    // flag.  We set it back once the buddy is in the new group,
-    // which will update the new group's flag.
-    msgflag = buddy_getflags(bud) & ROSTER_FLAG_MSG;
-    if (msgflag)
-      roster_msg_setflag(bjid, FALSE, FALSE);
-    buddy_setgroup(bud, group_utf8);
-    if (msgflag)
-      roster_msg_setflag(bjid, FALSE, TRUE);
-    */
+    if (on_srv) {
+      xmpp_updatebuddy(bjid, name, *group_utf8 ? group_utf8 : NULL);
+      scr_roster_up_down(-1, 1);
+
+      /* We do not move the buddy right now because the server could reject
+       * the request.  Let's wait for the server answer.
+       */
+    } else {
+      // This is a local item, we move it without adding to roster.
+      guint msgflag;
+
+      // If the buddy has a pending message flag,
+      // we remove it temporarily in order to reset the global group
+      // flag.  We set it back once the room is in the new group,
+      // which will update the new group's flag.
+      msgflag = buddy_getflags(bud) & ROSTER_FLAG_MSG;
+      if (msgflag)
+        roster_msg_setflag(bjid, FALSE, FALSE);
+      buddy_setgroup(bud, group_utf8);
+      if (msgflag)
+        roster_msg_setflag(bjid, FALSE, TRUE);
+    }
   }
 
   g_free(group_utf8);
 static void room_bookmark(gpointer bud, char *arg)
 {
   const char *roomid;
-  const char *name = NULL, *nick = NULL;
+  const char *name = NULL, *nick = NULL, *group = NULL;
   char *tmpnick = NULL;
   enum room_autowhois autowhois = 0;
   enum room_printstatus printstatus = 0;
       nick = buddy_getnickname(bud);
     printstatus = buddy_getprintstatus(bud);
     autowhois   = buddy_getautowhois(bud);
+    group       = buddy_getgroupname(bud);
   }
 
   xmpp_set_storage_bookmark(roomid, name, nick, NULL, autojoin,
-                            printstatus, autowhois);
+                            printstatus, autowhois, group);
   g_free (tmpnick);
 }
 

mcabber/mcabber/xmpp.c

 void xmpp_set_storage_bookmark(const char *roomid, const char *name,
                                const char *nick, const char *passwd,
                                int autojoin, enum room_printstatus pstatus,
-                               enum room_autowhois awhois)
+                               enum room_autowhois awhois, const char *group)
 {
   LmMessageNode *x;
   bool changed = FALSE;
       lm_message_node_set_attributes(x, "autowhois",
                                      (awhois == autowhois_on) ? "1" : "0",
                                      NULL);
+    if (group)
+      lm_message_node_add_child(x, "group", group);
     changed = TRUE;
     scr_LogPrint(LPRINT_LOGNORM, "Updating bookmarks...");
   }

mcabber/mcabber/xmpp.h

 void xmpp_set_storage_bookmark(const char *roomid, const char *name,
                                const char *nick, const char *passwd,
                                int autojoin, enum room_printstatus pstatus,
-                               enum room_autowhois awhois);
+                               enum room_autowhois awhois, const char *group);
 struct annotation *xmpp_get_storage_rosternotes(const char *barejid,
                                                 int silent);
 void xmpp_set_storage_rosternotes(const char *barejid, const char *note);

mcabber/mcabber/xmpp_iqrequest.c

 static void storage_bookmarks_parse_conference(LmMessageNode *node)
 {
   const char *fjid, *name, *autojoin;
-  const char *pstatus, *awhois;
+  const char *pstatus, *awhois, *group;
   char *bjid;
   GSList *room_elt;
 
   autojoin = lm_message_node_get_attribute(node, "autojoin");
   awhois = lm_message_node_get_attribute(node, "autowhois");
   pstatus = lm_message_node_get_child_value(node, "print_status");
+  group = lm_message_node_get_child_value(node, "group");
 
   bjid = jidtodisp(fjid); // Bare jid
 
   // Make sure this is a room (it can be a conversion user->room)
   room_elt = roster_find(bjid, jidsearch, 0);
   if (!room_elt) {
-    room_elt = roster_add_user(bjid, name, NULL, ROSTER_TYPE_ROOM,
+    room_elt = roster_add_user(bjid, name, group, ROSTER_TYPE_ROOM,
                                sub_none, -1);
   } else {
     buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
     // in the roster.
     if (name)
       buddy_setname(room_elt->data, name);
+
+    // The same question for roster group.
+    if (group)
+      buddy_setgroup(room_elt->data, group);
     */
   }
 
   }
   if (awhois) {
     enum room_autowhois i = autowhois_default;
-    if (!strcmp(awhois, "1"))
+    if (!strcmp(awhois, "1") || !(strcmp(awhois, "true")))
       i = autowhois_on;
-    else if (!strcmp(awhois, "0"))
+    else if (!strcmp(awhois, "0") || !(strcmp(awhois, "false")))
       i = autowhois_off;
     if (i != autowhois_default)
       buddy_setautowhois(room_elt->data, i);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.