Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 1377:cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
- add the command /room setopt
- add option 'muc_auto_whois'
The MUC settings auto_whois and print_status can be set on
a per-room basis.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Tue, 27 Nov 2007 23:57:20 +0100 |
parents | c7e709719c43 |
children | 61fc9eddf763 |
comparison
equal
deleted
inserted
replaced
1376:a0deb5124ebf | 1377:cd9182f0b5c7 |
---|---|
1998 char *p; | 1998 char *p; |
1999 char *mbuf; | 1999 char *mbuf; |
2000 const char *ournick; | 2000 const char *ournick; |
2001 enum imrole mbrole = role_none; | 2001 enum imrole mbrole = role_none; |
2002 enum imaffiliation mbaffil = affil_none; | 2002 enum imaffiliation mbaffil = affil_none; |
2003 enum room_printstatus printstatus; | |
2004 enum room_autowhois autowhois; | |
2003 const char *mbjid = NULL, *mbnick = NULL; | 2005 const char *mbjid = NULL, *mbnick = NULL; |
2004 const char *actorjid = NULL, *reason = NULL; | 2006 const char *actorjid = NULL, *reason = NULL; |
2005 bool new_member = FALSE; // True if somebody else joins the room (not us) | 2007 bool new_member = FALSE; // True if somebody else joins the room (not us) |
2006 unsigned int statuscode = 0; | 2008 guint statuscode = 0; |
2009 guint nickchange = 0; | |
2007 GSList *room_elt; | 2010 GSList *room_elt; |
2008 int log_muc_conf; | 2011 int log_muc_conf; |
2009 guint msgflags; | 2012 guint msgflags; |
2010 | 2013 |
2011 log_muc_conf = settings_opt_get_int("log_muc_conf"); | 2014 log_muc_conf = settings_opt_get_int("log_muc_conf"); |
2082 p = xmlnode_get_attrib(y, "code"); | 2085 p = xmlnode_get_attrib(y, "code"); |
2083 if (p) | 2086 if (p) |
2084 statuscode = atoi(p); | 2087 statuscode = atoi(p); |
2085 } | 2088 } |
2086 | 2089 |
2090 // Get the room's "print_status" settings | |
2091 printstatus = buddy_getprintstatus(room_elt->data); | |
2092 if (printstatus == status_default) { | |
2093 printstatus = (guint) settings_opt_get_int("muc_print_status"); | |
2094 if (printstatus > 3) | |
2095 printstatus = status_default; | |
2096 } | |
2097 | |
2087 // Check for nickname change | 2098 // Check for nickname change |
2088 if (statuscode == 303 && mbnick) { | 2099 if (statuscode == 303 && mbnick) { |
2089 mbuf = g_strdup_printf("%s is now known as %s", rname, mbnick); | 2100 mbuf = g_strdup_printf("%s is now known as %s", rname, mbnick); |
2090 scr_WriteIncomingMessage(roomjid, mbuf, usttime, | 2101 scr_WriteIncomingMessage(roomjid, mbuf, usttime, |
2091 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); | 2102 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
2094 g_free(mbuf); | 2105 g_free(mbuf); |
2095 buddy_resource_setname(room_elt->data, rname, mbnick); | 2106 buddy_resource_setname(room_elt->data, rname, mbnick); |
2096 // Maybe it's _our_ nickname... | 2107 // Maybe it's _our_ nickname... |
2097 if (ournick && !strcmp(rname, ournick)) | 2108 if (ournick && !strcmp(rname, ournick)) |
2098 buddy_setnickname(room_elt->data, mbnick); | 2109 buddy_setnickname(room_elt->data, mbnick); |
2110 nickchange = TRUE; | |
2099 } | 2111 } |
2100 | 2112 |
2101 // Check for departure/arrival | 2113 // Check for departure/arrival |
2102 if (!mbnick && ust == offline) { | 2114 if (!mbnick && ust == offline) { |
2103 enum { leave=0, kick, ban } how = leave; | 2115 enum { leave=0, kick, ban } how = leave; |
2167 mbuf = g_strdup_printf("%s has left", rname); | 2179 mbuf = g_strdup_printf("%s has left", rname); |
2168 } | 2180 } |
2169 } | 2181 } |
2170 } | 2182 } |
2171 | 2183 |
2172 msgflags = HBB_PREFIX_INFO; | 2184 // Display the mbuf message if we're concerned |
2173 if (!we_left && settings_opt_get_int("muc_flag_joins") != 2) | 2185 // or if the print_status isn't set to none. |
2174 msgflags |= HBB_PREFIX_NOFLAG; | 2186 if (we_left || printstatus != status_none) { |
2175 | 2187 msgflags = HBB_PREFIX_INFO; |
2176 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); | 2188 if (!we_left && settings_opt_get_int("muc_flag_joins") != 2) |
2189 msgflags |= HBB_PREFIX_NOFLAG; | |
2190 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); | |
2191 } | |
2177 | 2192 |
2178 if (log_muc_conf) | 2193 if (log_muc_conf) |
2179 hlog_write_message(roomjid, 0, -1, mbuf); | 2194 hlog_write_message(roomjid, 0, -1, mbuf); |
2180 | 2195 |
2181 if (we_left) { | 2196 if (we_left) { |
2208 scr_WriteIncomingMessage(roomjid, mbuf, 0, | 2223 scr_WriteIncomingMessage(roomjid, mbuf, 0, |
2209 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); | 2224 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
2210 if (log_muc_conf) | 2225 if (log_muc_conf) |
2211 hlog_write_message(roomjid, 0, -1, mbuf); | 2226 hlog_write_message(roomjid, 0, -1, mbuf); |
2212 g_free(mbuf); | 2227 g_free(mbuf); |
2213 mbuf = g_strdup_printf("%s has joined", rname); | 2228 if (printstatus != status_none) |
2229 mbuf = g_strdup_printf("%s has joined", rname); | |
2230 else | |
2231 mbuf = NULL; | |
2214 new_member = TRUE; | 2232 new_member = TRUE; |
2215 } | 2233 } |
2216 } else { | 2234 } else { |
2235 mbuf = NULL; | |
2217 if (strcmp(ournick, rname)) { | 2236 if (strcmp(ournick, rname)) { |
2218 mbuf = g_strdup_printf("%s has joined", rname); | 2237 if (printstatus != status_none) |
2238 mbuf = g_strdup_printf("%s has joined", rname); | |
2219 new_member = TRUE; | 2239 new_member = TRUE; |
2220 } else | 2240 } |
2221 mbuf = NULL; | |
2222 } | 2241 } |
2223 | 2242 |
2224 if (mbuf) { | 2243 if (mbuf) { |
2225 msgflags = HBB_PREFIX_INFO; | 2244 msgflags = HBB_PREFIX_INFO; |
2226 if (!settings_opt_get_int("muc_flag_joins")) | 2245 if (!settings_opt_get_int("muc_flag_joins")) |
2228 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); | 2247 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); |
2229 if (log_muc_conf) | 2248 if (log_muc_conf) |
2230 hlog_write_message(roomjid, 0, -1, mbuf); | 2249 hlog_write_message(roomjid, 0, -1, mbuf); |
2231 g_free(mbuf); | 2250 g_free(mbuf); |
2232 } | 2251 } |
2233 } | 2252 } else { |
2253 // This is a simple member status change | |
2254 | |
2255 if (printstatus == status_all && !nickchange) { | |
2256 mbuf = g_strdup_printf("Member status has changed: %s [%c] %s", rname, | |
2257 imstatus2char[ust], ((ustmsg) ? ustmsg : "")); | |
2258 scr_WriteIncomingMessage(roomjid, mbuf, usttime, HBB_PREFIX_INFO, 0); | |
2259 g_free(mbuf); | |
2260 } | |
2261 } | |
2262 | |
2263 // Sanity check, shouldn't happen... | |
2264 if (!rname) | |
2265 return; | |
2234 | 2266 |
2235 // Update room member status | 2267 // Update room member status |
2236 if (rname) { | 2268 roster_setstatus(roomjid, rname, bpprio, ust, ustmsg, usttime, |
2237 roster_setstatus(roomjid, rname, bpprio, ust, ustmsg, usttime, | 2269 mbrole, mbaffil, mbjid); |
2238 mbrole, mbaffil, mbjid); | 2270 |
2239 if (new_member && settings_opt_get_int("muc_auto_whois")) { | 2271 autowhois = buddy_getautowhois(room_elt->data); |
2240 // FIXME: This will fail for some UTF-8 nicknames. | 2272 if (autowhois == autowhois_default) |
2241 gchar *joiner_nick = from_utf8(rname); | 2273 autowhois = (settings_opt_get_int("muc_auto_whois") ? |
2242 room_whois(room_elt->data, joiner_nick, FALSE); | 2274 autowhois_on : autowhois_off); |
2243 g_free(joiner_nick); | 2275 |
2244 } | 2276 if (new_member && autowhois == autowhois_on) { |
2245 } else | 2277 // FIXME: This will fail for some UTF-8 nicknames. |
2246 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */ | 2278 gchar *joiner_nick = from_utf8(rname); |
2279 room_whois(room_elt->data, joiner_nick, FALSE); | |
2280 g_free(joiner_nick); | |
2281 } | |
2247 | 2282 |
2248 scr_DrawRoster(); | 2283 scr_DrawRoster(); |
2249 } | 2284 } |
2250 | 2285 |
2251 static void handle_packet_presence(jconn conn, char *type, char *from, | 2286 static void handle_packet_presence(jconn conn, char *type, char *from, |