Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/commands.c @ 1976:e6beab22099b
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.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 24 Mar 2011 20:53:08 +0100 |
parents | 45f0f0f60656 |
children | 986e514bec97 |
comparison
equal
deleted
inserted
replaced
1975:a23799244335 | 1976:e6beab22099b |
---|---|
1975 } | 1975 } |
1976 | 1976 |
1977 static void move_group_member(gpointer bud, void *groupnamedata) | 1977 static void move_group_member(gpointer bud, void *groupnamedata) |
1978 { | 1978 { |
1979 const char *bjid, *name, *groupname; | 1979 const char *bjid, *name, *groupname; |
1980 guint on_srv; | |
1980 | 1981 |
1981 groupname = (char *)groupnamedata; | 1982 groupname = (char *)groupnamedata; |
1982 | 1983 |
1983 bjid = buddy_getjid(bud); | 1984 bjid = buddy_getjid(bud); |
1984 name = buddy_getname(bud); | 1985 name = buddy_getname(bud); |
1985 | 1986 on_srv = buddy_getonserverflag(bud); |
1986 xmpp_updatebuddy(bjid, name, *groupname ? groupname : NULL); | 1987 |
1988 if (on_srv) | |
1989 xmpp_updatebuddy(bjid, name, *groupname ? groupname : NULL); | |
1990 else | |
1991 buddy_setname(bud, (char*)name); | |
1987 } | 1992 } |
1988 | 1993 |
1989 static void do_rename(char *arg) | 1994 static void do_rename(char *arg) |
1990 { | 1995 { |
1991 gpointer bud; | 1996 gpointer bud; |
2011 if (!*arg && !(type & ROSTER_TYPE_GROUP)) { | 2016 if (!*arg && !(type & ROSTER_TYPE_GROUP)) { |
2012 scr_LogPrint(LPRINT_NORMAL, "Please specify a new name."); | 2017 scr_LogPrint(LPRINT_NORMAL, "Please specify a new name."); |
2013 return; | 2018 return; |
2014 } | 2019 } |
2015 | 2020 |
2016 if (!(type & ROSTER_TYPE_GROUP) && !on_srv) { | 2021 //if (!(type & ROSTER_TYPE_GROUP) && !on_srv) { |
2017 scr_LogPrint(LPRINT_NORMAL, | 2022 // scr_LogPrint(LPRINT_NORMAL, |
2018 "Note: this item will be added to your server roster."); | 2023 // "Note: this item will be added to your server roster."); |
2019 // If this is a MUC room w/o bookmark, let's give a small hint... | 2024 // // If this is a MUC room w/o bookmark, let's give a small hint... |
2020 if ((type & ROSTER_TYPE_ROOM) && !xmpp_is_bookmarked(bjid)) { | 2025 // if ((type & ROSTER_TYPE_ROOM) && !xmpp_is_bookmarked(bjid)) { |
2021 scr_LogPrint(LPRINT_NORMAL, | 2026 // scr_LogPrint(LPRINT_NORMAL, |
2022 "You should add a room bookmark or it will not be " | 2027 // "You should add a room bookmark or it will not be " |
2023 "recognized as a MUC room next time you run mcabber."); | 2028 // "recognized as a MUC room next time you run mcabber."); |
2024 } | 2029 // } |
2025 } | 2030 //} |
2026 | 2031 |
2027 newname = g_strdup(arg); | 2032 newname = g_strdup(arg); |
2028 // Remove trailing space | 2033 // Remove trailing space |
2029 for (p = newname; *p; p++) ; | 2034 for (p = newname; *p; p++) ; |
2030 while (p > newname && *p == ' ') *p = 0; | 2035 while (p > newname && *p == ' ') *p = 0; |
2042 } else { | 2047 } else { |
2043 // Rename a single buddy | 2048 // Rename a single buddy |
2044 guint del_name = 0; | 2049 guint del_name = 0; |
2045 if (!*newname || !strcmp(arg, "-")) | 2050 if (!*newname || !strcmp(arg, "-")) |
2046 del_name = TRUE; | 2051 del_name = TRUE; |
2047 /* We do not rename the buddy right now because the server could reject | 2052 if (on_srv) { |
2048 * the request. Let's wait for the server answer. | 2053 /* We do not rename the buddy right now because the server could reject |
2049 * buddy_setname(bud, (del_name ? (char*)bjid : name_utf8)); | 2054 * the request. Let's wait for the server answer. |
2050 */ | 2055 */ |
2051 xmpp_updatebuddy(bjid, (del_name ? NULL : name_utf8), group); | 2056 xmpp_updatebuddy(bjid, (del_name ? NULL : name_utf8), group); |
2057 } else { | |
2058 // This is a local item, we rename it without adding to roster. | |
2059 buddy_setname(bud, (del_name ? (char*)bjid : name_utf8)); | |
2060 } | |
2052 } | 2061 } |
2053 | 2062 |
2054 g_free(name_utf8); | 2063 g_free(name_utf8); |
2055 g_free(newname); | 2064 g_free(newname); |
2056 update_roster = TRUE; | 2065 update_roster = TRUE; |
2058 | 2067 |
2059 static void do_move(char *arg) | 2068 static void do_move(char *arg) |
2060 { | 2069 { |
2061 gpointer bud; | 2070 gpointer bud; |
2062 const char *bjid, *name, *oldgroupname; | 2071 const char *bjid, *name, *oldgroupname; |
2063 guint type; | 2072 guint type, on_srv; |
2064 char *newgroupname, *p; | 2073 char *newgroupname, *p; |
2065 char *group_utf8; | 2074 char *group_utf8; |
2066 | 2075 |
2067 if (!current_buddy) | 2076 if (!current_buddy) |
2068 return; | 2077 return; |
2069 bud = BUDDATA(current_buddy); | 2078 bud = BUDDATA(current_buddy); |
2070 | 2079 |
2071 bjid = buddy_getjid(bud); | 2080 bjid = buddy_getjid(bud); |
2072 name = buddy_getname(bud); | 2081 name = buddy_getname(bud); |
2073 type = buddy_gettype(bud); | 2082 type = buddy_gettype(bud); |
2083 on_srv = buddy_getonserverflag(bud); | |
2074 | 2084 |
2075 oldgroupname = buddy_getgroupname(bud); | 2085 oldgroupname = buddy_getgroupname(bud); |
2076 | 2086 |
2077 if (type & ROSTER_TYPE_GROUP) { | 2087 if (type & ROSTER_TYPE_GROUP) { |
2078 scr_LogPrint(LPRINT_NORMAL, "You can't move groups!"); | 2088 scr_LogPrint(LPRINT_NORMAL, "You can't move groups!"); |
2090 | 2100 |
2091 strip_arg_special_chars(newgroupname); | 2101 strip_arg_special_chars(newgroupname); |
2092 | 2102 |
2093 group_utf8 = to_utf8(newgroupname); | 2103 group_utf8 = to_utf8(newgroupname); |
2094 if (strcmp(oldgroupname, group_utf8)) { | 2104 if (strcmp(oldgroupname, group_utf8)) { |
2095 /* guint msgflag; */ | 2105 if (on_srv) { |
2096 | 2106 xmpp_updatebuddy(bjid, name, *group_utf8 ? group_utf8 : NULL); |
2097 xmpp_updatebuddy(bjid, name, *group_utf8 ? group_utf8 : NULL); | 2107 scr_roster_up_down(-1, 1); |
2098 scr_roster_up_down(-1, 1); | 2108 |
2099 | 2109 /* We do not move the buddy right now because the server could reject |
2100 /* We do not move the buddy right now because the server could reject | 2110 * the request. Let's wait for the server answer. |
2101 * the request. Let's wait for the server answer. | 2111 */ |
2102 | 2112 } else { |
2103 // If the buddy has a pending message flag, | 2113 // This is a local item, we move it without adding to roster. |
2104 // we remove it temporarily in order to reset the global group | 2114 guint msgflag; |
2105 // flag. We set it back once the buddy is in the new group, | 2115 |
2106 // which will update the new group's flag. | 2116 // If the buddy has a pending message flag, |
2107 msgflag = buddy_getflags(bud) & ROSTER_FLAG_MSG; | 2117 // we remove it temporarily in order to reset the global group |
2108 if (msgflag) | 2118 // flag. We set it back once the room is in the new group, |
2109 roster_msg_setflag(bjid, FALSE, FALSE); | 2119 // which will update the new group's flag. |
2110 buddy_setgroup(bud, group_utf8); | 2120 msgflag = buddy_getflags(bud) & ROSTER_FLAG_MSG; |
2111 if (msgflag) | 2121 if (msgflag) |
2112 roster_msg_setflag(bjid, FALSE, TRUE); | 2122 roster_msg_setflag(bjid, FALSE, FALSE); |
2113 */ | 2123 buddy_setgroup(bud, group_utf8); |
2124 if (msgflag) | |
2125 roster_msg_setflag(bjid, FALSE, TRUE); | |
2126 } | |
2114 } | 2127 } |
2115 | 2128 |
2116 g_free(group_utf8); | 2129 g_free(group_utf8); |
2117 g_free(newgroupname); | 2130 g_free(newgroupname); |
2118 update_roster = TRUE; | 2131 update_roster = TRUE; |
2944 } | 2957 } |
2945 | 2958 |
2946 static void room_bookmark(gpointer bud, char *arg) | 2959 static void room_bookmark(gpointer bud, char *arg) |
2947 { | 2960 { |
2948 const char *roomid; | 2961 const char *roomid; |
2949 const char *name = NULL, *nick = NULL; | 2962 const char *name = NULL, *nick = NULL, *group = NULL; |
2950 char *tmpnick = NULL; | 2963 char *tmpnick = NULL; |
2951 enum room_autowhois autowhois = 0; | 2964 enum room_autowhois autowhois = 0; |
2952 enum room_printstatus printstatus = 0; | 2965 enum room_printstatus printstatus = 0; |
2953 enum { bm_add = 0, bm_del = 1 } action = 0; | 2966 enum { bm_add = 0, bm_del = 1 } action = 0; |
2954 int autojoin = 0; | 2967 int autojoin = 0; |
2985 name = buddy_getname(bud); | 2998 name = buddy_getname(bud); |
2986 if (!nick_set) | 2999 if (!nick_set) |
2987 nick = buddy_getnickname(bud); | 3000 nick = buddy_getnickname(bud); |
2988 printstatus = buddy_getprintstatus(bud); | 3001 printstatus = buddy_getprintstatus(bud); |
2989 autowhois = buddy_getautowhois(bud); | 3002 autowhois = buddy_getautowhois(bud); |
3003 group = buddy_getgroupname(bud); | |
2990 } | 3004 } |
2991 | 3005 |
2992 xmpp_set_storage_bookmark(roomid, name, nick, NULL, autojoin, | 3006 xmpp_set_storage_bookmark(roomid, name, nick, NULL, autojoin, |
2993 printstatus, autowhois); | 3007 printstatus, autowhois, group); |
2994 g_free (tmpnick); | 3008 g_free (tmpnick); |
2995 } | 3009 } |
2996 | 3010 |
2997 static void display_all_bookmarks(void) | 3011 static void display_all_bookmarks(void) |
2998 { | 3012 { |