comparison src/protocols/yahoo/yahoo.c @ 11970:8f8b4d1ac26e

[gaim-migrate @ 14263] This should mostly fix Yahoo! away/avail messages for yo'sef. I'll fix any other problems with it tomorrow. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 04 Nov 2005 07:36:32 +0000
parents 498a1b29fb11
children 73777ad45562
comparison
equal deleted inserted replaced
11969:498a1b29fb11 11970:8f8b4d1ac26e
153 case YAHOO_STATUS_INVISIBLE: /* this should never happen? */ 153 case YAHOO_STATUS_INVISIBLE: /* this should never happen? */
154 status = YAHOO_STATUS_TYPE_INVISIBLE; 154 status = YAHOO_STATUS_TYPE_INVISIBLE;
155 break; 155 break;
156 case YAHOO_STATUS_CUSTOM: 156 case YAHOO_STATUS_CUSTOM:
157 if (!f->away) 157 if (!f->away)
158 status = YAHOO_STATUS_TYPE_AVAILABLE_WM; 158 status = YAHOO_STATUS_TYPE_AVAILABLE;
159 else 159 else
160 status = YAHOO_STATUS_TYPE_AWAY; 160 status = YAHOO_STATUS_TYPE_AWAY;
161 break; 161 break;
162 case YAHOO_STATUS_IDLE: 162 case YAHOO_STATUS_IDLE:
163 status = YAHOO_STATUS_TYPE_AVAILABLE; 163 status = YAHOO_STATUS_TYPE_AVAILABLE;
2460 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free); 2460 yd->friends = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, yahoo_friend_free);
2461 yd->confs = NULL; 2461 yd->confs = NULL;
2462 yd->conf_id = 2; 2462 yd->conf_id = 2;
2463 2463
2464 if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE)) { 2464 if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE)) {
2465 yd->current_status = YAHOO_STATUS_AVAILABLE; 2465 if (gaim_status_get_attr_string(status, "message") != NULL)
2466 yd->current_status = YAHOO_STATUS_CUSTOM;
2467 else
2468 yd->current_status = YAHOO_STATUS_AVAILABLE;
2466 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BRB)) { 2469 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BRB)) {
2467 yd->current_status = YAHOO_STATUS_BRB; 2470 yd->current_status = YAHOO_STATUS_BRB;
2468 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BUSY)) { 2471 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BUSY)) {
2469 yd->current_status = YAHOO_STATUS_BUSY; 2472 yd->current_status = YAHOO_STATUS_BUSY;
2470 } else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATHOME)) { 2473 } else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATHOME)) {
2482 } else if (!strcmp(id, YAHOO_STATUS_TYPE_STEPPEDOUT)) { 2485 } else if (!strcmp(id, YAHOO_STATUS_TYPE_STEPPEDOUT)) {
2483 yd->current_status = YAHOO_STATUS_STEPPEDOUT; 2486 yd->current_status = YAHOO_STATUS_STEPPEDOUT;
2484 } else if (!strcmp(id, YAHOO_STATUS_TYPE_INVISIBLE)) { 2487 } else if (!strcmp(id, YAHOO_STATUS_TYPE_INVISIBLE)) {
2485 yd->current_status = YAHOO_STATUS_INVISIBLE; 2488 yd->current_status = YAHOO_STATUS_INVISIBLE;
2486 } else if (!strcmp(id, YAHOO_STATUS_TYPE_AWAY)) { 2489 } else if (!strcmp(id, YAHOO_STATUS_TYPE_AWAY)) {
2487 yd->current_status = YAHOO_STATUS_CUSTOM;
2488 } else if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE_WM)) {
2489 yd->current_status = YAHOO_STATUS_CUSTOM; 2490 yd->current_status = YAHOO_STATUS_CUSTOM;
2490 } else if (gc->is_idle) { /* i think this is broken */ 2491 } else if (gc->is_idle) { /* i think this is broken */
2491 yd->current_status = YAHOO_STATUS_IDLE; 2492 yd->current_status = YAHOO_STATUS_IDLE;
2492 } else { 2493 } else {
2493 gaim_debug_error("yahoo", "Unexpected GaimStatus passed to yahoo_set_status!\n"); 2494 gaim_debug_error("yahoo", "Unexpected GaimStatus passed to yahoo_set_status!\n");
3065 GaimConnection *gc = gaim_account_get_connection(account); 3066 GaimConnection *gc = gaim_account_get_connection(account);
3066 struct yahoo_data *yd; 3067 struct yahoo_data *yd;
3067 struct yahoo_packet *pkt; 3068 struct yahoo_packet *pkt;
3068 int old_status; 3069 int old_status;
3069 const char *id; 3070 const char *id;
3071 const char *msg = NULL;
3072 char *tmp = NULL;
3070 char *conv_msg = NULL; 3073 char *conv_msg = NULL;
3071 char *conv_msg2 = NULL;
3072 3074
3073 id = gaim_status_get_id(status); 3075 id = gaim_status_get_id(status);
3074 if (!gaim_status_is_active(status)) 3076 if (!gaim_status_is_active(status))
3075 return; 3077 return;
3076 3078
3079 3081
3080 yd = (struct yahoo_data *)gc->proto_data; 3082 yd = (struct yahoo_data *)gc->proto_data;
3081 old_status = yd->current_status; 3083 old_status = yd->current_status;
3082 3084
3083 if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE)) { 3085 if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE)) {
3084 yd->current_status = YAHOO_STATUS_AVAILABLE; 3086 msg = gaim_status_get_attr_string(status, "message");
3087 if ((msg == NULL) || (*msg == '\0')) {
3088 yd->current_status = YAHOO_STATUS_AVAILABLE;
3089 } else {
3090 yd->current_status = YAHOO_STATUS_CUSTOM;
3091 tmp = yahoo_string_encode(gc, msg, NULL);
3092 conv_msg = gaim_markup_strip_html(tmp);
3093 g_free(tmp);
3094 }
3085 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BRB)) { 3095 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BRB)) {
3086 yd->current_status = YAHOO_STATUS_BRB; 3096 yd->current_status = YAHOO_STATUS_BRB;
3087 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BUSY)) { 3097 } else if (!strcmp(id, YAHOO_STATUS_TYPE_BUSY)) {
3088 yd->current_status = YAHOO_STATUS_BUSY; 3098 yd->current_status = YAHOO_STATUS_BUSY;
3089 } else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATHOME)) { 3099 } else if (!strcmp(id, YAHOO_STATUS_TYPE_NOTATHOME)) {
3102 yd->current_status = YAHOO_STATUS_STEPPEDOUT; 3112 yd->current_status = YAHOO_STATUS_STEPPEDOUT;
3103 } else if (!strcmp(id, YAHOO_STATUS_TYPE_INVISIBLE)) { 3113 } else if (!strcmp(id, YAHOO_STATUS_TYPE_INVISIBLE)) {
3104 yd->current_status = YAHOO_STATUS_INVISIBLE; 3114 yd->current_status = YAHOO_STATUS_INVISIBLE;
3105 } else if (!strcmp(id, YAHOO_STATUS_TYPE_AWAY)) { 3115 } else if (!strcmp(id, YAHOO_STATUS_TYPE_AWAY)) {
3106 yd->current_status = YAHOO_STATUS_CUSTOM; 3116 yd->current_status = YAHOO_STATUS_CUSTOM;
3107 } else if (!strcmp(id, YAHOO_STATUS_TYPE_AVAILABLE_WM)) { 3117
3108 yd->current_status = YAHOO_STATUS_CUSTOM; 3118 msg = gaim_status_get_attr_string(status, "message");
3119 if ((msg == NULL) && (*msg == '\0'))
3120 msg = _("Away");
3121 tmp = yahoo_string_encode(gc, msg, NULL);
3122 conv_msg = gaim_markup_strip_html(tmp);
3123 g_free(tmp);
3109 } else if (gc->is_idle) { /* i think this is broken */ 3124 } else if (gc->is_idle) { /* i think this is broken */
3110 yd->current_status = YAHOO_STATUS_IDLE; 3125 yd->current_status = YAHOO_STATUS_IDLE;
3111 } else { 3126 } else {
3112 gaim_debug_error("yahoo", "Unexpected GaimStatus passed to yahoo_login!\n"); 3127 gaim_debug_error("yahoo", "Unexpected GaimStatus passed to yahoo_login!\n");
3113 yd->current_status = YAHOO_STATUS_AVAILABLE; 3128 yd->current_status = YAHOO_STATUS_AVAILABLE;
3123 3138
3124 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0); 3139 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_STATUS_UPDATE, YAHOO_STATUS_AVAILABLE, 0);
3125 yahoo_packet_hash_int(pkt, 10, yd->current_status); 3140 yahoo_packet_hash_int(pkt, 10, yd->current_status);
3126 3141
3127 if (yd->current_status == YAHOO_STATUS_CUSTOM) { 3142 if (yd->current_status == YAHOO_STATUS_CUSTOM) {
3128 const char *msg = gaim_status_get_attr_string(status, "message"); 3143 yahoo_packet_hash_str(pkt, 19, conv_msg);
3129
3130 if ((msg == NULL) || (*msg == '\0')) {
3131 gaim_debug_info("yahoo", "Attempted to set an empty status message, using a default string.\n");
3132 msg = _("Away");
3133 }
3134
3135 conv_msg = yahoo_string_encode(gc, msg, NULL);
3136 conv_msg2 = gaim_markup_strip_html(conv_msg);
3137 yahoo_packet_hash_str(pkt, 19, conv_msg2);
3138
3139 } else { 3144 } else {
3140 yahoo_packet_hash_str(pkt, 19, ""); 3145 yahoo_packet_hash_str(pkt, 19, "");
3141 } 3146 }
3147
3148 g_free(conv_msg);
3142 3149
3143 if (gc->is_idle) 3150 if (gc->is_idle)
3144 yahoo_packet_hash_str(pkt, 47, "2"); 3151 yahoo_packet_hash_str(pkt, 47, "2");
3145 else if (!gaim_status_type_is_available(gaim_status_get_type(status))) 3152 else if (!gaim_status_type_is_available(gaim_status_get_type(status)))
3146 yahoo_packet_hash_str(pkt, 47, "1"); 3153 yahoo_packet_hash_str(pkt, 47, "1");
3147 3154
3148 yahoo_packet_send_and_free(pkt, yd); 3155 yahoo_packet_send_and_free(pkt, yd);
3149
3150 g_free(conv_msg);
3151 g_free(conv_msg2);
3152 3156
3153 if (old_status == YAHOO_STATUS_INVISIBLE) { 3157 if (old_status == YAHOO_STATUS_INVISIBLE) {
3154 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0); 3158 pkt = yahoo_packet_new(YAHOO_SERVICE_Y6_VISIBLE_TOGGLE, YAHOO_STATUS_AVAILABLE, 0);
3155 yahoo_packet_hash_str(pkt, 13, "1"); 3159 yahoo_packet_hash_str(pkt, 13, "1");
3156 yahoo_packet_send_and_free(pkt, yd); 3160 yahoo_packet_send_and_free(pkt, yd);
3201 g_free(msg2); 3205 g_free(msg2);
3202 } 3206 }
3203 3207
3204 static GList *yahoo_status_types(GaimAccount *account) 3208 static GList *yahoo_status_types(GaimAccount *account)
3205 { 3209 {
3206 GaimConnection *gc = gaim_account_get_connection(account);
3207 struct yahoo_data *yd = NULL;
3208 GaimStatusType *type; 3210 GaimStatusType *type;
3209 GList *types = NULL; 3211 GList *types = NULL;
3210 3212
3211 if (gc)
3212 yd = gc->proto_data;
3213
3214 type = gaim_status_type_new(GAIM_STATUS_OFFLINE, YAHOO_STATUS_TYPE_OFFLINE, _("Offline"), TRUE); 3213 type = gaim_status_type_new(GAIM_STATUS_OFFLINE, YAHOO_STATUS_TYPE_OFFLINE, _("Offline"), TRUE);
3215 types = g_list_append(types, type); 3214 types = g_list_append(types, type);
3216 3215
3217 type = gaim_status_type_new(GAIM_STATUS_AVAILABLE, YAHOO_STATUS_TYPE_AVAILABLE, _("Available"), TRUE); 3216 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, YAHOO_STATUS_TYPE_AVAILABLE,
3217 "Available", TRUE, TRUE, FALSE,
3218 "message", _("Message"),
3219 gaim_value_new(GAIM_TYPE_STRING), NULL);
3218 types = g_list_append(types, type); 3220 types = g_list_append(types, type);
3219 3221
3220 if (!yd || !yd->wm) { 3222 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_AWAY,
3221 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, YAHOO_STATUS_TYPE_AVAILABLE_WM, 3223 _("Away"), TRUE, TRUE, FALSE,
3222 "Available With Message", TRUE, TRUE, FALSE, 3224 "message", _("Message"),
3223 "message", _("Message"), 3225 gaim_value_new(GAIM_TYPE_STRING), NULL);
3224 gaim_value_new(GAIM_TYPE_STRING), NULL); 3226 types = g_list_append(types, type);
3225 types = g_list_append(types, type); 3227
3226 3228 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_BRB, _("Be Right Back"), TRUE);
3227 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_AWAY, 3229 types = g_list_append(types, type);
3228 _("Away"), TRUE, TRUE, FALSE, 3230
3229 "message", _("Message"), 3231 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_BUSY, _("Busy"), TRUE);
3230 gaim_value_new(GAIM_TYPE_STRING), NULL); 3232 types = g_list_append(types, type);
3231 types = g_list_append(types, type); 3233
3232 3234 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTATHOME, _("Not At Home"), TRUE);
3233 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_BRB, _("Be Right Back"), TRUE); 3235 types = g_list_append(types, type);
3234 types = g_list_append(types, type); 3236
3235 3237 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTATDESK, _("Not At Desk"), TRUE);
3236 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_BUSY, _("Busy"), TRUE); 3238 types = g_list_append(types, type);
3237 types = g_list_append(types, type); 3239
3238 3240 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTINOFFICE, _("Not In Office"), TRUE);
3239 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTATHOME, _("Not At Home"), TRUE); 3241 types = g_list_append(types, type);
3240 types = g_list_append(types, type); 3242
3241 3243 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_ONPHONE, _("On The Phone"), TRUE);
3242 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTATDESK, _("Not At Desk"), TRUE); 3244 types = g_list_append(types, type);
3243 types = g_list_append(types, type); 3245
3244 3246 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_ONVACATION, _("On Vacation"), TRUE);
3245 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_NOTINOFFICE, _("Not In Office"), TRUE); 3247 types = g_list_append(types, type);
3246 types = g_list_append(types, type); 3248
3247 3249 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_OUTTOLUNCH, _("Out To Lunch"), TRUE);
3248 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_ONPHONE, _("On The Phone"), TRUE); 3250 types = g_list_append(types, type);
3249 types = g_list_append(types, type); 3251
3250 3252 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_STEPPEDOUT, _("Stepped Out"), TRUE);
3251 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_ONVACATION, _("On Vacation"), TRUE); 3253 types = g_list_append(types, type);
3252 types = g_list_append(types, type); 3254
3253
3254 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_OUTTOLUNCH, _("Out To Lunch"), TRUE);
3255 types = g_list_append(types, type);
3256
3257 type = gaim_status_type_new(GAIM_STATUS_AWAY, YAHOO_STATUS_TYPE_STEPPEDOUT, _("Stepped Out"), TRUE);
3258 types = g_list_append(types, type);
3259 }
3260 type = gaim_status_type_new(GAIM_STATUS_HIDDEN, YAHOO_STATUS_TYPE_INVISIBLE, _("Invisible"), TRUE); 3255 type = gaim_status_type_new(GAIM_STATUS_HIDDEN, YAHOO_STATUS_TYPE_INVISIBLE, _("Invisible"), TRUE);
3261 types = g_list_append(types, type); 3256 types = g_list_append(types, type);
3262 3257
3263 return types; 3258 return types;
3264 } 3259 }