comparison libpurple/protocols/qq/group_im.c @ 24095:25f62d21b3f8

disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 15 Sep 2008 03:04:07 +0000
parents 147ada94a1d8
children 225e0e9e1055
comparison
equal deleted inserted replaced
24088:147ada94a1d8 24095:25f62d21b3f8
39 #include "group_opt.h" 39 #include "group_opt.h"
40 #include "im.h" 40 #include "im.h"
41 #include "header_info.h" 41 #include "header_info.h"
42 #include "packet_parse.h" 42 #include "packet_parse.h"
43 #include "qq_network.h" 43 #include "qq_network.h"
44 #include "qq_process.h"
45 #include "utils.h" 44 #include "utils.h"
46 45
47 typedef struct _qq_recv_group_im { 46 typedef struct _qq_recv_group_im {
48 guint32 ext_id; 47 guint32 ext_id;
49 guint8 type8; 48 guint8 type8;
84 g_free(msg_filtered); 83 g_free(msg_filtered);
85 84
86 if (bytes == data_len) /* create OK */ 85 if (bytes == data_len) /* create OK */
87 qq_send_room_cmd(gc, QQ_ROOM_CMD_SEND_MSG, group->id, raw_data, data_len); 86 qq_send_room_cmd(gc, QQ_ROOM_CMD_SEND_MSG, group->id, raw_data, data_len);
88 else 87 else
89 purple_debug_error("QQ", 88 purple_debug(PURPLE_DEBUG_ERROR, "QQ",
90 "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes); 89 "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes);
91 } 90 }
92 91
93 /* this is the ACK */ 92 /* this is the ACK */
94 void qq_process_group_cmd_im(guint8 *data, gint len, PurpleConnection *gc) 93 void qq_process_group_cmd_im(guint8 *data, gint len, PurpleConnection *gc)
95 { 94 {
96 /* return should be the internal group id 95 /* return should be the internal group id
97 * but we have nothing to do with it */ 96 * but we have nothing to do with it */
98 return; 97 return;
99 } 98 }
100 99
101 /* receive an application to join the group */ 100 /* receive an application to join the group */
102 void qq_process_room_msg_apply_join(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 101 void qq_process_recv_group_im_apply_join(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
103 { 102 {
104 guint32 ext_id, user_uid; 103 guint32 ext_id, user_uid;
105 guint8 type8; 104 guint8 type8;
106 gchar *reason_utf8, *msg, *reason; 105 gchar *reason_utf8, *msg, *reason;
107 group_member_opt *g; 106 group_member_opt *g;
118 117
119 g_return_if_fail(ext_id > 0 && user_uid > 0); 118 g_return_if_fail(ext_id > 0 && user_uid > 0);
120 119
121 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT); 120 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT);
122 121
123 msg = g_strdup_printf(_("%d requested to join Qun %d"), user_uid, ext_id); 122 msg = g_strdup_printf(_("User %d requested to join group %d"), user_uid, ext_id);
124 reason = g_strdup_printf(_("Message: %s"), reason_utf8); 123 reason = g_strdup_printf(_("Reason: %s"), reason_utf8);
125 124
126 g = g_new0(group_member_opt, 1); 125 g = g_new0(group_member_opt, 1);
127 g->gc = gc; 126 g->gc = gc;
128 g->id = id; 127 g->id = id;
129 g->member = user_uid; 128 g->member = user_uid;
148 g_free(msg); 147 g_free(msg);
149 g_free(reason_utf8); 148 g_free(reason_utf8);
150 } 149 }
151 150
152 /* the request to join a group is rejected */ 151 /* the request to join a group is rejected */
153 void qq_process_room_msg_been_rejected(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 152 void qq_process_recv_group_im_been_rejected(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
154 { 153 {
155 guint32 ext_id, admin_uid; 154 guint32 ext_id, admin_uid;
156 guint8 type8; 155 guint8 type8;
157 gchar *reason_utf8, *msg, *reason; 156 gchar *reason_utf8, *msg, *reason;
158 qq_group *group; 157 qq_group *group;
169 g_return_if_fail(ext_id > 0 && admin_uid > 0); 168 g_return_if_fail(ext_id > 0 && admin_uid > 0);
170 169
171 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT); 170 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT);
172 171
173 msg = g_strdup_printf 172 msg = g_strdup_printf
174 (_("Your request to join Qun %d has been rejected by admin %d"), ext_id, admin_uid); 173 (_("Your request to join group %d has been rejected by admin %d"), ext_id, admin_uid);
175 reason = g_strdup_printf(_("Message: %s"), reason_utf8); 174 reason = g_strdup_printf(_("Reason: %s"), reason_utf8);
176 175
177 purple_notify_warning(gc, _("QQ Qun Operation"), msg, reason); 176 purple_notify_warning(gc, _("QQ Qun Operation"), msg, reason);
178 177
179 group = qq_room_search_id(gc, id); 178 group = qq_room_search_id(gc, id);
180 if (group != NULL) { 179 if (group != NULL) {
181 group->my_role = QQ_ROOM_ROLE_NO; 180 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
182 qq_group_refresh(gc, group); 181 qq_group_refresh(gc, group);
183 } 182 }
184 183
185 g_free(reason); 184 g_free(reason);
186 g_free(msg); 185 g_free(msg);
187 g_free(reason_utf8); 186 g_free(reason_utf8);
188 } 187 }
189 188
190 /* the request to join a group is approved */ 189 /* the request to join a group is approved */
191 void qq_process_room_msg_been_approved(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 190 void qq_process_recv_group_im_been_approved(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
192 { 191 {
193 guint32 ext_id, admin_uid; 192 guint32 ext_id, admin_uid;
194 guint8 type8; 193 guint8 type8;
195 gchar *reason_utf8, *msg; 194 gchar *reason_utf8, *msg;
196 qq_group *group; 195 qq_group *group;
207 g_return_if_fail(ext_id > 0 && admin_uid > 0); 206 g_return_if_fail(ext_id > 0 && admin_uid > 0);
208 /* it is also a "无" here, so do not display */ 207 /* it is also a "无" here, so do not display */
209 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT); 208 bytes += convert_as_pascal_string(data + bytes, &reason_utf8, QQ_CHARSET_DEFAULT);
210 209
211 msg = g_strdup_printf 210 msg = g_strdup_printf
212 (_("Your request to join Qun %d has been approved by admin %d"), ext_id, admin_uid); 211 (_("Your request to join group %d has been approved by admin %d"), ext_id, admin_uid);
213 212
214 purple_notify_warning(gc, _("QQ Qun Operation"), msg, NULL); 213 purple_notify_warning(gc, _("QQ Qun Operation"), msg, NULL);
215 214
216 group = qq_room_search_id(gc, id); 215 group = qq_room_search_id(gc, id);
217 if (group != NULL) { 216 if (group != NULL) {
218 group->my_role = QQ_ROOM_ROLE_YES; 217 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
219 qq_group_refresh(gc, group); 218 qq_group_refresh(gc, group);
220 } 219 }
221 220
222 g_free(msg); 221 g_free(msg);
223 g_free(reason_utf8); 222 g_free(reason_utf8);
224 } 223 }
225 224
226 /* process the packet when removed from a group */ 225 /* process the packet when removed from a group */
227 void qq_process_room_msg_been_removed(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 226 void qq_process_recv_group_im_been_removed(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
228 { 227 {
229 guint32 ext_id, uid; 228 guint32 ext_id, uid;
230 guint8 type8; 229 guint8 type8;
231 gchar *msg; 230 gchar *msg;
232 qq_group *group; 231 qq_group *group;
240 bytes += qq_get8(&type8, data + bytes); 239 bytes += qq_get8(&type8, data + bytes);
241 bytes += qq_get32(&uid, data + bytes); 240 bytes += qq_get32(&uid, data + bytes);
242 241
243 g_return_if_fail(ext_id > 0 && uid > 0); 242 g_return_if_fail(ext_id > 0 && uid > 0);
244 243
245 msg = g_strdup_printf(_("[%d] removed from Qun \"%d\""), uid, ext_id); 244 msg = g_strdup_printf(_("You [%d] have left group \"%d\""), uid, ext_id);
246 purple_notify_info(gc, _("QQ Qun Operation"), msg, NULL); 245 purple_notify_info(gc, _("QQ Qun Operation"), msg, NULL);
247 246
248 group = qq_room_search_id(gc, id); 247 group = qq_room_search_id(gc, id);
249 if (group != NULL) { 248 if (group != NULL) {
250 group->my_role = QQ_ROOM_ROLE_NO; 249 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
251 qq_group_refresh(gc, group); 250 qq_group_refresh(gc, group);
252 } 251 }
253 252
254 g_free(msg); 253 g_free(msg);
255 } 254 }
256 255
257 /* process the packet when added to a group */ 256 /* process the packet when added to a group */
258 void qq_process_room_msg_been_added(guint8 *data, gint len, guint32 id, PurpleConnection *gc) 257 void qq_process_recv_group_im_been_added(guint8 *data, gint len, guint32 id, PurpleConnection *gc)
259 { 258 {
260 guint32 ext_id, uid; 259 guint32 ext_id, uid;
261 guint8 type8; 260 guint8 type8;
262 qq_group *group; 261 qq_group *group;
263 gchar *msg; 262 gchar *msg;
271 bytes += qq_get8(&type8, data + bytes); 270 bytes += qq_get8(&type8, data + bytes);
272 bytes += qq_get32(&uid, data + bytes); 271 bytes += qq_get32(&uid, data + bytes);
273 272
274 g_return_if_fail(ext_id > 0 && uid > 0); 273 g_return_if_fail(ext_id > 0 && uid > 0);
275 274
276 msg = g_strdup_printf(_("[%d] added to Qun \"%d\""), uid, ext_id); 275 msg = g_strdup_printf(_("You [%d] have been added to group \"%d\""), uid, ext_id);
277 purple_notify_info(gc, _("QQ Qun Operation"), msg, _("Qun is in buddy list")); 276 purple_notify_info(gc, _("QQ Qun Operation"), msg, _("This group has been added to your buddy list"));
278 277
279 group = qq_room_search_id(gc, id); 278 group = qq_room_search_id(gc, id);
280 if (group != NULL) { 279 if (group != NULL) {
281 group->my_role = QQ_ROOM_ROLE_YES; 280 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
282 qq_group_refresh(gc, group); 281 qq_group_refresh(gc, group);
283 } else { /* no such group, try to create a dummy first, and then update */ 282 } else { /* no such group, try to create a dummy first, and then update */
284 group = qq_group_create_internal_record(gc, id, ext_id, NULL); 283 group = qq_group_create_internal_record(gc, id, ext_id, NULL);
285 group->my_role = QQ_ROOM_ROLE_YES; 284 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
286 qq_group_refresh(gc, group); 285 qq_group_refresh(gc, group);
287 qq_room_update(gc, 0, group->id); 286 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id);
288 /* the return of this cmd will automatically update the group in blist */ 287 /* the return of this cmd will automatically update the group in blist */
289 } 288 }
290 289
291 g_free(msg); 290 g_free(msg);
292 } 291 }
293 292
294 /* recv an IM from a group chat */ 293 /* recv an IM from a group chat */
295 void qq_process_room_msg_normal(guint8 *data, gint data_len, guint32 id, PurpleConnection *gc, guint16 im_type) 294 void qq_process_recv_group_im(guint8 *data, gint data_len, guint32 id, PurpleConnection *gc, guint16 im_type)
296 { 295 {
297 gchar *msg_with_purple_smiley, *msg_utf8_encoded, *im_src_name; 296 gchar *msg_with_purple_smiley, *msg_utf8_encoded, *im_src_name;
298 guint16 unknown; 297 guint16 unknown;
299 guint32 unknown4; 298 guint32 unknown4;
300 PurpleConversation *conv; 299 PurpleConversation *conv;
309 308
310 /* FIXME: check length here */ 309 /* FIXME: check length here */
311 310
312 qd = (qq_data *) gc->proto_data; 311 qd = (qq_data *) gc->proto_data;
313 312
314 #if 0 313 /* qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", data, data_len, "group im hex dump"); */
315 qq_hex_dump(PURPLE_DEBUG_INFO, "QQ", data, data_len, "group im hex dump");
316 #endif
317 314
318 im_group = g_newa(qq_recv_group_im, 1); 315 im_group = g_newa(qq_recv_group_im, 1);
319 316
320 bytes += qq_get32(&(im_group->ext_id), data + bytes); 317 bytes += qq_get32(&(im_group->ext_id), data + bytes);
321 bytes += qq_get8(&(im_group->type8), data + bytes); 318 bytes += qq_get8(&(im_group->type8), data + bytes);
375 msg_utf8_encoded = qq_to_utf8(msg_with_purple_smiley, QQ_CHARSET_DEFAULT); 372 msg_utf8_encoded = qq_to_utf8(msg_with_purple_smiley, QQ_CHARSET_DEFAULT);
376 373
377 group = qq_room_search_id(gc, id); 374 group = qq_room_search_id(gc, id);
378 g_return_if_fail(group != NULL); 375 g_return_if_fail(group != NULL);
379 376
380 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->title_utf8, purple_connection_get_account(gc)); 377 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->group_name_utf8, purple_connection_get_account(gc));
381 if (conv == NULL && purple_prefs_get_bool("/plugins/prpl/qq/prompt_group_msg_on_recv")) { 378 if (conv == NULL && purple_prefs_get_bool("/plugins/prpl/qq/prompt_group_msg_on_recv")) {
382 /* New conv should open, get group info*/ 379 /* New conv should open, get group info*/
383 qq_room_update(gc, 0, group->id); 380 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id);
384 381
385 serv_got_joined_chat(gc, qd->channel++, group->title_utf8); 382 serv_got_joined_chat(gc, qd->channel++, group->group_name_utf8);
386 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->title_utf8, purple_connection_get_account(gc)); 383 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group->group_name_utf8, purple_connection_get_account(gc));
387 } 384 }
388 385
389 if (conv != NULL) { 386 if (conv != NULL) {
390 member = qq_group_find_member_by_uid(group, im_group->member_uid); 387 member = qq_group_find_member_by_uid(group, im_group->member_uid);
391 if (member == NULL || member->nickname == NULL) 388 if (member == NULL || member->nickname == NULL)