# HG changeset patch # User Mikael Berthe # Date 1300996388 -3600 # Node ID e6beab22099b132ec9175208b73019aaf5a09e4a # Parent a23799244335842c2d8c0fe04ec5f75cb7a883d0 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. diff -r a23799244335 -r e6beab22099b mcabber/mcabber/commands.c --- a/mcabber/mcabber/commands.c Sat Mar 19 20:07:56 2011 +0100 +++ b/mcabber/mcabber/commands.c Thu Mar 24 20:53:08 2011 +0100 @@ -1977,13 +1977,18 @@ 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) @@ -2013,16 +2018,16 @@ 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 @@ -2044,11 +2049,15 @@ 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); @@ -2060,7 +2069,7 @@ { gpointer bud; const char *bjid, *name, *oldgroupname; - guint type; + guint type, on_srv; char *newgroupname, *p; char *group_utf8; @@ -2071,6 +2080,7 @@ bjid = buddy_getjid(bud); name = buddy_getname(bud); type = buddy_gettype(bud); + on_srv = buddy_getonserverflag(bud); oldgroupname = buddy_getgroupname(bud); @@ -2092,25 +2102,28 @@ 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); @@ -2946,7 +2959,7 @@ 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; @@ -2987,10 +3000,11 @@ 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); } diff -r a23799244335 -r e6beab22099b mcabber/mcabber/xmpp.c --- a/mcabber/mcabber/xmpp.c Sat Mar 19 20:07:56 2011 +0100 +++ b/mcabber/mcabber/xmpp.c Thu Mar 24 20:53:08 2011 +0100 @@ -2137,7 +2137,7 @@ 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; @@ -2188,6 +2188,8 @@ 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..."); } diff -r a23799244335 -r e6beab22099b mcabber/mcabber/xmpp.h --- a/mcabber/mcabber/xmpp.h Sat Mar 19 20:07:56 2011 +0100 +++ b/mcabber/mcabber/xmpp.h Thu Mar 24 20:53:08 2011 +0100 @@ -70,7 +70,7 @@ 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); diff -r a23799244335 -r e6beab22099b mcabber/mcabber/xmpp_iqrequest.c --- a/mcabber/mcabber/xmpp_iqrequest.c Sat Mar 19 20:07:56 2011 +0100 +++ b/mcabber/mcabber/xmpp_iqrequest.c Thu Mar 24 20:53:08 2011 +0100 @@ -561,7 +561,7 @@ 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; @@ -572,13 +572,14 @@ 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); @@ -588,6 +589,10 @@ // 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); */ } @@ -602,9 +607,9 @@ } 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);