Changeset d860a8d for protocols/bee_user.c
- Timestamp:
- 2010-04-01T03:38:50Z (14 years ago)
- Branches:
- master
- Children:
- e63507a
- Parents:
- 81e04e1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/bee_user.c
r81e04e1 rd860a8d 81 81 return NULL; 82 82 } 83 84 int bee_user_msg( bee_t *bee, bee_user_t *bu, const char *msg, int flags ) 85 { 86 char *buf = NULL; 87 int st; 88 89 if( ( bu->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) 90 { 91 buf = escape_html( msg ); 92 msg = buf; 93 } 94 95 st = bu->ic->acc->prpl->buddy_msg( bu->ic, bu->handle, msg, flags ); 96 g_free( buf ); 97 98 return st; 99 } 100 101 102 /* IM->UI callbacks */ 103 void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message ) 104 { 105 bee_t *bee = ic->bee; 106 bee_user_t *bu, *old; 107 108 if( !( bu = bee_user_by_handle( bee, ic, handle ) ) ) 109 { 110 if( g_strcasecmp( set_getstr( &ic->bee->set, "handle_unknown" ), "add" ) == 0 ) 111 { 112 bu = bee_user_new( bee, ic, handle ); 113 } 114 else 115 { 116 if( set_getbool( &ic->bee->set, "debug" ) || g_strcasecmp( set_getstr( &ic->bee->set, "handle_unknown" ), "ignore" ) != 0 ) 117 { 118 imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle ); 119 imcb_log( ic, "flags = %d, state = %s, message = %s", flags, 120 state ? state : "NULL", message ? message : "NULL" ); 121 } 122 123 return; 124 } 125 } 126 127 /* May be nice to give the UI something to compare against. */ 128 old = g_memdup( bu, sizeof( bee_user_t ) ); 129 130 /* TODO(wilmer): OPT_AWAY, or just state == NULL ? */ 131 bu->flags = ( flags & OPT_LOGGED_IN ? BEE_USER_ONLINE : 0 ) | 132 ( flags & OPT_AWAY ? BEE_USER_AWAY : 0 ); 133 bu->status = g_strdup( ( flags & OPT_AWAY ) && state == NULL ? "Away" : state ); 134 bu->status_msg = g_strdup( message ); 135 136 if( bee->ui->user_status ) 137 bee->ui->user_status( bee, bu, old ); 138 139 g_free( old->status_msg ); 140 g_free( old->status ); 141 g_free( old ); 142 #if 0 143 oa = u->away != NULL; 144 oo = u->online; 145 146 g_free( u->away ); 147 g_free( u->status_msg ); 148 u->away = u->status_msg = NULL; 149 150 if( ( flags & OPT_LOGGED_IN ) && !u->online ) 151 { 152 irc_spawn( ic->irc, u ); 153 u->online = 1; 154 } 155 else if( !( flags & OPT_LOGGED_IN ) && u->online ) 156 { 157 struct groupchat *c; 158 159 irc_kill( ic->irc, u ); 160 u->online = 0; 161 162 /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */ 163 for( c = ic->groupchats; c; c = c->next ) 164 remove_chat_buddy_silent( c, handle ); 165 } 166 167 if( flags & OPT_AWAY ) 168 { 169 if( state && message ) 170 { 171 u->away = g_strdup_printf( "%s (%s)", state, message ); 172 } 173 else if( state ) 174 { 175 u->away = g_strdup( state ); 176 } 177 else if( message ) 178 { 179 u->away = g_strdup( message ); 180 } 181 else 182 { 183 u->away = g_strdup( "Away" ); 184 } 185 } 186 else 187 { 188 u->status_msg = g_strdup( message ); 189 } 190 191 /* LISPy... */ 192 if( ( set_getbool( &ic->bee->set, "away_devoice" ) ) && /* Don't do a thing when user doesn't want it */ 193 ( u->online ) && /* Don't touch offline people */ 194 ( ( ( u->online != oo ) && !u->away ) || /* Voice joining people */ 195 ( ( u->online == oo ) && ( oa == !u->away ) ) ) ) /* (De)voice people changing state */ 196 { 197 char *from; 198 199 if( set_getbool( &ic->bee->set, "simulate_netsplit" ) ) 200 { 201 from = g_strdup( ic->irc->myhost ); 202 } 203 else 204 { 205 from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick, 206 ic->irc->myhost ); 207 } 208 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel, 209 u->away?'-':'+', u->nick ); 210 g_free( from ); 211 } 212 #endif 213 } 214 215 void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at ) 216 { 217 #if 0 218 bee_t *bee = ic->bee; 219 char *wrapped; 220 user_t *u; 221 222 u = user_findhandle( ic, handle ); 223 224 if( !u ) 225 { 226 char *h = set_getstr( &bee->set, "handle_unknown" ); 227 228 if( g_strcasecmp( h, "ignore" ) == 0 ) 229 { 230 if( set_getbool( &bee->set, "debug" ) ) 231 imcb_log( ic, "Ignoring message from unknown handle %s", handle ); 232 233 return; 234 } 235 else if( g_strncasecmp( h, "add", 3 ) == 0 ) 236 { 237 int private = set_getbool( &bee->set, "private" ); 238 239 if( h[3] ) 240 { 241 if( g_strcasecmp( h + 3, "_private" ) == 0 ) 242 private = 1; 243 else if( g_strcasecmp( h + 3, "_channel" ) == 0 ) 244 private = 0; 245 } 246 247 imcb_add_buddy( ic, handle, NULL ); 248 u = user_findhandle( ic, handle ); 249 u->is_private = private; 250 } 251 else 252 { 253 imcb_log( ic, "Message from unknown handle %s:", handle ); 254 u = user_find( irc, irc->mynick ); 255 } 256 } 257 258 if( ( g_strcasecmp( set_getstr( &ic->bee->set, "strip_html" ), "always" ) == 0 ) || 259 ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->bee->set, "strip_html" ) ) ) 260 strip_html( msg ); 261 262 wrapped = word_wrap( msg, 425 ); 263 irc_msgfrom( irc, u->nick, wrapped ); 264 g_free( wrapped ); 265 #endif 266 }
Note: See TracChangeset
for help on using the changeset viewer.