Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/group_internal.c @ 23754:967344bc404d
applied changes from f12c8903079425d7850fa183df0b3f937b2952be
through 8cebefbc6cd5d84acb69c74e69e8821f11dd225d
Backport of 8cebefbc6cd5d84acb69c74e69e8821f11dd225d to avoid having other changes overwritten.
2008.08.16 - ccpaging <ecc_hy(at)hotmail.com>
* Rename group to room. If you used pidginqq before, this may create a new room with same title, you may
delete old one
* Replace purple_debug with purple_debug_info, purple_debug_warning, purple_debug_error
* Add server notice and server new, and two options to turn on/off
* Minor modify for reducing transaction's debug infor
* Minor modifies for system notice and QQ news.
* Add 4 new strings need translate compare with p10.
committer: Daniel Atallah <daniel.atallah@gmail.com>
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Mon, 15 Sep 2008 02:59:23 +0000 |
parents | 5f454b975a99 |
children | 69c218fd5d54 25f62d21b3f8 |
comparison
equal
deleted
inserted
replaced
23753:5f454b975a99 | 23754:967344bc404d |
---|---|
29 #include "buddy_opt.h" | 29 #include "buddy_opt.h" |
30 #include "group_free.h" | 30 #include "group_free.h" |
31 #include "group_internal.h" | 31 #include "group_internal.h" |
32 #include "utils.h" | 32 #include "utils.h" |
33 | 33 |
34 static gchar *_qq_group_set_my_status_desc(qq_group *group) | 34 static gchar *get_role_desc(qq_group *group) |
35 { | 35 { |
36 const char *status_desc; | 36 const char *role_desc; |
37 g_return_val_if_fail(group != NULL, g_strdup("")); | 37 g_return_val_if_fail(group != NULL, g_strdup("")); |
38 | 38 |
39 switch (group->my_status) { | 39 switch (group->my_role) { |
40 case QQ_GROUP_MEMBER_STATUS_NOT_MEMBER: | 40 case QQ_ROOM_ROLE_NO: |
41 status_desc = _("I am not a member"); | 41 role_desc = _("I am not a member"); |
42 break; | 42 break; |
43 case QQ_GROUP_MEMBER_STATUS_IS_MEMBER: | 43 case QQ_ROOM_ROLE_YES: |
44 status_desc = _("I am a member"); | 44 role_desc = _("I am a member"); |
45 break; | 45 break; |
46 case QQ_GROUP_MEMBER_STATUS_APPLYING: | 46 case QQ_ROOM_ROLE_REQUESTING: |
47 status_desc = _("I am applying to join"); | 47 role_desc = _("I am requesting"); |
48 break; | 48 break; |
49 case QQ_GROUP_MEMBER_STATUS_IS_ADMIN: | 49 case QQ_ROOM_ROLE_ADMIN: |
50 status_desc = _("I am the admin"); | 50 role_desc = _("I am the admin"); |
51 break; | 51 break; |
52 default: | 52 default: |
53 status_desc = _("Unknown status"); | 53 role_desc = _("Unknown status"); |
54 } | 54 } |
55 | 55 |
56 return g_strdup(status_desc); | 56 return g_strdup(role_desc); |
57 } | 57 } |
58 | 58 |
59 static void _qq_group_add_to_blist(PurpleConnection *gc, qq_group *group) | 59 static void add_room_to_blist(PurpleConnection *gc, qq_group *group) |
60 { | 60 { |
61 GHashTable *components; | 61 GHashTable *components; |
62 PurpleGroup *g; | 62 PurpleGroup *g; |
63 PurpleChat *chat; | 63 PurpleChat *chat; |
64 components = qq_group_to_hashtable(group); | 64 components = qq_group_to_hashtable(group); |
65 chat = purple_chat_new(purple_connection_get_account(gc), group->group_name_utf8, components); | 65 chat = purple_chat_new(purple_connection_get_account(gc), group->title_utf8, components); |
66 g = qq_get_purple_group(PURPLE_GROUP_QQ_QUN); | 66 g = qq_get_purple_group(PURPLE_GROUP_QQ_QUN); |
67 purple_blist_add_chat(chat, g, NULL); | 67 purple_blist_add_chat(chat, g, NULL); |
68 purple_debug(PURPLE_DEBUG_INFO, "QQ", "You have added group \"%s\" to blist locally\n", group->group_name_utf8); | 68 purple_debug_info("QQ", "You have added group \"%s\" to blist locally\n", group->title_utf8); |
69 } | 69 } |
70 | 70 |
71 /* Create a dummy qq_group, which includes only internal_id, ext_id, | 71 /* Create a dummy qq_group, which includes only internal_id, ext_id, |
72 * and potentially group_name_utf8, in case we need to call group_conv_show_window | 72 * and potentially title_utf8, in case we need to call group_conv_show_window |
73 * right after creation. All other attributes are set to empty. | 73 * right after creation. All other attributes are set to empty. |
74 * We need to send a get_group_info to the QQ server to update it right away */ | 74 * We need to send a get_group_info to the QQ server to update it right away */ |
75 qq_group *qq_group_create_internal_record(PurpleConnection *gc, | 75 qq_group *qq_group_create_internal_record(PurpleConnection *gc, |
76 guint32 internal_id, guint32 ext_id, gchar *group_name_utf8) | 76 guint32 internal_id, guint32 ext_id, gchar *title_utf8) |
77 { | 77 { |
78 qq_group *group; | 78 qq_group *group; |
79 qq_data *qd; | 79 qq_data *qd; |
80 | 80 |
81 g_return_val_if_fail(internal_id > 0, NULL); | 81 g_return_val_if_fail(internal_id > 0, NULL); |
82 qd = (qq_data *) gc->proto_data; | 82 qd = (qq_data *) gc->proto_data; |
83 | 83 |
84 group = g_new0(qq_group, 1); | 84 group = g_new0(qq_group, 1); |
85 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; | 85 group->my_role = QQ_ROOM_ROLE_NO; |
86 group->my_status_desc = _qq_group_set_my_status_desc(group); | 86 group->my_role_desc = get_role_desc(group); |
87 group->id = internal_id; | 87 group->id = internal_id; |
88 group->ext_id = ext_id; | 88 group->ext_id = ext_id; |
89 group->type8 = 0x01; /* assume permanent Qun */ | 89 group->type8 = 0x01; /* assume permanent Qun */ |
90 group->creator_uid = 10000; /* assume by QQ admin */ | 90 group->creator_uid = 10000; /* assume by QQ admin */ |
91 group->group_category = 0x01; | 91 group->category = 0x01; |
92 group->auth_type = 0x02; /* assume need auth */ | 92 group->auth_type = 0x02; /* assume need auth */ |
93 group->group_name_utf8 = g_strdup(group_name_utf8 == NULL ? "" : group_name_utf8); | 93 group->title_utf8 = g_strdup(title_utf8 == NULL ? "" : title_utf8); |
94 group->group_desc_utf8 = g_strdup(""); | 94 group->desc_utf8 = g_strdup(""); |
95 group->notice_utf8 = g_strdup(""); | 95 group->notice_utf8 = g_strdup(""); |
96 group->members = NULL; | 96 group->members = NULL; |
97 | 97 |
98 qd->groups = g_list_append(qd->groups, group); | 98 qd->groups = g_list_append(qd->groups, group); |
99 _qq_group_add_to_blist(gc, group); | 99 add_room_to_blist(gc, group); |
100 | 100 |
101 return group; | 101 return group; |
102 } | 102 } |
103 | 103 |
104 void qq_group_delete_internal_record(qq_data *qd, guint32 id) | 104 void qq_group_delete_internal_record(qq_data *qd, guint32 id) |
122 /* convert a qq_group to hash-table, which could be component of PurpleChat */ | 122 /* convert a qq_group to hash-table, which could be component of PurpleChat */ |
123 GHashTable *qq_group_to_hashtable(qq_group *group) | 123 GHashTable *qq_group_to_hashtable(qq_group *group) |
124 { | 124 { |
125 GHashTable *components; | 125 GHashTable *components; |
126 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | 126 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
127 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status)); | 127 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_ROLE), g_strdup_printf("%d", group->my_role)); |
128 group->my_status_desc = _qq_group_set_my_status_desc(group); | 128 group->my_role_desc = get_role_desc(group); |
129 | 129 |
130 g_hash_table_insert(components, | 130 g_hash_table_insert(components, |
131 g_strdup(QQ_GROUP_KEY_INTERNAL_ID), g_strdup_printf("%d", group->id)); | 131 g_strdup(QQ_ROOM_KEY_INTERNAL_ID), g_strdup_printf("%d", group->id)); |
132 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_EXTERNAL_ID), | 132 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_EXTERNAL_ID), |
133 g_strdup_printf("%d", group->ext_id)); | 133 g_strdup_printf("%d", group->ext_id)); |
134 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_TYPE), g_strdup_printf("%d", group->type8)); | 134 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_TYPE), g_strdup_printf("%d", group->type8)); |
135 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); | 135 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); |
136 g_hash_table_insert(components, | 136 g_hash_table_insert(components, |
137 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY), g_strdup_printf("%d", group->group_category)); | 137 g_strdup(QQ_ROOM_KEY_CATEGORY), g_strdup_printf("%d", group->category)); |
138 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); | 138 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); |
139 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc)); | 139 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_ROLE_DESC), g_strdup(group->my_role_desc)); |
140 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); | 140 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_TITLE_UTF8), g_strdup(group->title_utf8)); |
141 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); | 141 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_DESC_UTF8), g_strdup(group->desc_utf8)); |
142 return components; | 142 return components; |
143 } | 143 } |
144 | 144 |
145 /* create a qq_group from hashtable */ | 145 /* create a qq_group from hashtable */ |
146 qq_group *qq_group_from_hashtable(PurpleConnection *gc, GHashTable *data) | 146 qq_group *qq_group_from_hashtable(PurpleConnection *gc, GHashTable *data) |
150 | 150 |
151 g_return_val_if_fail(data != NULL, NULL); | 151 g_return_val_if_fail(data != NULL, NULL); |
152 qd = (qq_data *) gc->proto_data; | 152 qd = (qq_data *) gc->proto_data; |
153 | 153 |
154 group = g_new0(qq_group, 1); | 154 group = g_new0(qq_group, 1); |
155 group->my_status = | 155 group->my_role = |
156 qq_string_to_dec_value | 156 qq_string_to_dec_value |
157 (NULL == | 157 (NULL == |
158 g_hash_table_lookup(data, | 158 g_hash_table_lookup(data, |
159 QQ_GROUP_KEY_MEMBER_STATUS) ? | 159 QQ_ROOM_KEY_ROLE) ? |
160 g_strdup_printf("%d", QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) : | 160 g_strdup_printf("%d", QQ_ROOM_ROLE_NO) : |
161 g_hash_table_lookup(data, QQ_GROUP_KEY_MEMBER_STATUS)); | 161 g_hash_table_lookup(data, QQ_ROOM_KEY_ROLE)); |
162 group->id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_INTERNAL_ID)); | 162 group->id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_INTERNAL_ID)); |
163 group->ext_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID)); | 163 group->ext_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_EXTERNAL_ID)); |
164 group->type8 = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_TYPE)); | 164 group->type8 = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_TYPE)); |
165 group->creator_uid = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_CREATOR_UID)); | 165 group->creator_uid = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_CREATOR_UID)); |
166 group->group_category = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_CATEGORY)); | 166 group->category = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_CATEGORY)); |
167 group->auth_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_AUTH_TYPE)); | 167 group->auth_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_AUTH_TYPE)); |
168 group->group_name_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_NAME_UTF8)); | 168 group->title_utf8 = g_strdup(g_hash_table_lookup(data, QQ_ROOM_KEY_TITLE_UTF8)); |
169 group->group_desc_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_DESC_UTF8)); | 169 group->desc_utf8 = g_strdup(g_hash_table_lookup(data, QQ_ROOM_KEY_DESC_UTF8)); |
170 group->my_status_desc = _qq_group_set_my_status_desc(group); | 170 group->my_role_desc = get_role_desc(group); |
171 | 171 |
172 qd->groups = g_list_append(qd->groups, group); | 172 qd->groups = g_list_append(qd->groups, group); |
173 | 173 |
174 return group; | 174 return group; |
175 } | 175 } |
182 g_return_if_fail(group != NULL); | 182 g_return_if_fail(group != NULL); |
183 | 183 |
184 ext_id = g_strdup_printf("%d", group->ext_id); | 184 ext_id = g_strdup_printf("%d", group->ext_id); |
185 chat = purple_blist_find_chat(purple_connection_get_account(gc), ext_id); | 185 chat = purple_blist_find_chat(purple_connection_get_account(gc), ext_id); |
186 g_free(ext_id); | 186 g_free(ext_id); |
187 if (chat == NULL && group->my_status != QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { | 187 if (chat == NULL && group->my_role != QQ_ROOM_ROLE_NO) { |
188 _qq_group_add_to_blist(gc, group); | 188 add_room_to_blist(gc, group); |
189 } else if (chat != NULL) { /* we have a local record, update its info */ | 189 return; |
190 /* if there is group_name_utf8, we update the group name */ | |
191 if (group->group_name_utf8 != NULL && strlen(group->group_name_utf8) > 0) | |
192 purple_blist_alias_chat(chat, group->group_name_utf8); | |
193 g_hash_table_replace(chat->components, | |
194 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status)); | |
195 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
196 g_hash_table_replace(chat->components, | |
197 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc)); | |
198 g_hash_table_replace(chat->components, | |
199 g_strdup(QQ_GROUP_KEY_INTERNAL_ID), | |
200 g_strdup_printf("%d", group->id)); | |
201 g_hash_table_replace(chat->components, | |
202 g_strdup(QQ_GROUP_KEY_EXTERNAL_ID), | |
203 g_strdup_printf("%d", group->ext_id)); | |
204 g_hash_table_replace(chat->components, | |
205 g_strdup(QQ_GROUP_KEY_TYPE), g_strdup_printf("%d", group->type8)); | |
206 g_hash_table_replace(chat->components, | |
207 g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); | |
208 g_hash_table_replace(chat->components, | |
209 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY), | |
210 g_strdup_printf("%d", group->group_category)); | |
211 g_hash_table_replace(chat->components, | |
212 g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); | |
213 g_hash_table_replace(chat->components, | |
214 g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); | |
215 g_hash_table_replace(chat->components, | |
216 g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); | |
217 } | 190 } |
218 } | 191 |
219 | 192 if (chat == NULL) { |
220 /* NOTE: If we knew how to convert between an external and internal group id, as the official | 193 return; |
194 } | |
195 | |
196 /* we have a local record, update its info */ | |
197 /* if there is title_utf8, we update the group name */ | |
198 if (group->title_utf8 != NULL && strlen(group->title_utf8) > 0) | |
199 purple_blist_alias_chat(chat, group->title_utf8); | |
200 g_hash_table_replace(chat->components, | |
201 g_strdup(QQ_ROOM_KEY_ROLE), g_strdup_printf("%d", group->my_role)); | |
202 group->my_role_desc = get_role_desc(group); | |
203 g_hash_table_replace(chat->components, | |
204 g_strdup(QQ_ROOM_KEY_ROLE_DESC), g_strdup(group->my_role_desc)); | |
205 g_hash_table_replace(chat->components, | |
206 g_strdup(QQ_ROOM_KEY_INTERNAL_ID), | |
207 g_strdup_printf("%d", group->id)); | |
208 g_hash_table_replace(chat->components, | |
209 g_strdup(QQ_ROOM_KEY_EXTERNAL_ID), | |
210 g_strdup_printf("%d", group->ext_id)); | |
211 g_hash_table_replace(chat->components, | |
212 g_strdup(QQ_ROOM_KEY_TYPE), g_strdup_printf("%d", group->type8)); | |
213 g_hash_table_replace(chat->components, | |
214 g_strdup(QQ_ROOM_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); | |
215 g_hash_table_replace(chat->components, | |
216 g_strdup(QQ_ROOM_KEY_CATEGORY), | |
217 g_strdup_printf("%d", group->category)); | |
218 g_hash_table_replace(chat->components, | |
219 g_strdup(QQ_ROOM_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); | |
220 g_hash_table_replace(chat->components, | |
221 g_strdup(QQ_ROOM_KEY_TITLE_UTF8), g_strdup(group->title_utf8)); | |
222 g_hash_table_replace(chat->components, | |
223 g_strdup(QQ_ROOM_KEY_DESC_UTF8), g_strdup(group->desc_utf8)); | |
224 } | |
225 | |
226 /* NOTE: If we knew how to convert between an external and internal group id, as the official | |
221 * client seems to, the following would be unnecessary. That would be ideal. */ | 227 * client seems to, the following would be unnecessary. That would be ideal. */ |
222 | 228 |
223 /* Use list to specify if id's alternate id is pending discovery. */ | 229 /* Use list to specify if id's alternate id is pending discovery. */ |
224 void qq_set_pending_id(GSList **list, guint32 id, gboolean pending) | 230 void qq_set_pending_id(GSList **list, guint32 id, gboolean pending) |
225 { | 231 { |
226 if (pending) | 232 if (pending) |
227 *list = g_slist_prepend(*list, GINT_TO_POINTER(id)); | 233 *list = g_slist_prepend(*list, GINT_TO_POINTER(id)); |
228 else | 234 else |
229 *list = g_slist_remove(*list, GINT_TO_POINTER(id)); | 235 *list = g_slist_remove(*list, GINT_TO_POINTER(id)); |
230 } | 236 } |
231 | 237 |
232 /* Return the location of id in list, or NULL if not found */ | 238 /* Return the location of id in list, or NULL if not found */ |
233 GSList *qq_get_pending_id(GSList *list, guint32 id) | 239 GSList *qq_get_pending_id(GSList *list, guint32 id) |