14192
|
1 /**
|
|
2 * The QQ2003C protocol plugin
|
|
3 *
|
|
4 * for gaim
|
|
5 *
|
|
6 * Copyright (C) 2004 Puzzlebird
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22
|
|
23 #include "conversation.h"
|
|
24 #include "debug.h"
|
|
25 #include "util.h"
|
|
26
|
|
27 #include "group_find.h"
|
|
28 #include "group_network.h"
|
|
29 #include "qq.h"
|
|
30 #include "utils.h"
|
|
31
|
|
32 /* find the internal_group_id by the reply packet sequence
|
|
33 * return TRUE if we have a record of it, return FALSE if not */
|
|
34 gboolean qq_group_find_internal_group_id_by_seq(GaimConnection *gc, guint16 seq, guint32 *internal_group_id)
|
|
35 {
|
|
36 GList *list;
|
|
37 qq_data *qd;
|
|
38 group_packet *p;
|
|
39
|
14404
|
40 if (internal_group_id == NULL)
|
|
41 return FALSE;
|
14192
|
42 qd = (qq_data *) gc->proto_data;
|
|
43
|
|
44 list = qd->group_packets;
|
|
45 while (list != NULL) {
|
|
46 p = (group_packet *) (list->data);
|
|
47 if (p->send_seq == seq) { /* found and remove */
|
|
48 *internal_group_id = p->internal_group_id;
|
|
49 qd->group_packets = g_list_remove(qd->group_packets, p);
|
|
50 g_free(p);
|
|
51 return TRUE;
|
|
52 }
|
|
53 list = list->next;
|
|
54 }
|
|
55
|
|
56 return FALSE;
|
|
57 }
|
|
58
|
14404
|
59 /* find a qq_buddy by uid, called by im.c */
|
14192
|
60 qq_buddy *qq_group_find_member_by_uid(qq_group *group, guint32 uid)
|
|
61 {
|
|
62 GList *list;
|
|
63 qq_buddy *member;
|
|
64 g_return_val_if_fail(group != NULL && uid > 0, NULL);
|
|
65
|
|
66 list = group->members;
|
|
67 while (list != NULL) {
|
|
68 member = (qq_buddy *) list->data;
|
|
69 if (member->uid == uid)
|
|
70 return member;
|
|
71 else
|
|
72 list = list->next;
|
|
73 }
|
|
74
|
|
75 return NULL;
|
|
76 }
|
|
77
|
|
78 /* remove a qq_buddy by uid, called by qq_group_opt.c */
|
|
79 void qq_group_remove_member_by_uid(qq_group *group, guint32 uid)
|
|
80 {
|
|
81 GList *list;
|
|
82 qq_buddy *member;
|
|
83 g_return_if_fail(group != NULL && uid > 0);
|
|
84
|
|
85 list = group->members;
|
|
86 while (list != NULL) {
|
|
87 member = (qq_buddy *) list->data;
|
|
88 if (member->uid == uid) {
|
|
89 group->members = g_list_remove(group->members, member);
|
|
90 return;
|
|
91 } else {
|
|
92 list = list->next;
|
|
93 }
|
|
94 }
|
|
95 }
|
|
96
|
|
97 qq_buddy *qq_group_find_or_add_member(GaimConnection *gc, qq_group *group, guint32 member_uid)
|
|
98 {
|
|
99 qq_buddy *member, *q_bud;
|
|
100 GaimBuddy *buddy;
|
14629
|
101 g_return_val_if_fail(group != NULL && member_uid > 0, NULL);
|
14192
|
102
|
|
103 member = qq_group_find_member_by_uid(group, member_uid);
|
|
104 if (member == NULL) { /* first appear during my session */
|
|
105 member = g_new0(qq_buddy, 1);
|
|
106 member->uid = member_uid;
|
|
107 buddy = gaim_find_buddy(gaim_connection_get_account(gc), uid_to_gaim_name(member_uid));
|
|
108 if (buddy != NULL) {
|
|
109 q_bud = (qq_buddy *) buddy->proto_data;
|
14404
|
110 if (q_bud != NULL && q_bud->nickname != NULL)
|
14192
|
111 member->nickname = g_strdup(q_bud->nickname);
|
|
112 else if (buddy->alias != NULL)
|
|
113 member->nickname = g_strdup(buddy->alias);
|
|
114 }
|
|
115 group->members = g_list_append(group->members, member);
|
|
116 }
|
|
117
|
|
118 return member;
|
|
119 }
|
|
120
|
|
121 /* find a qq_group by chatroom channel */
|
|
122 qq_group *qq_group_find_by_channel(GaimConnection *gc, gint channel)
|
|
123 {
|
|
124 GaimConversation *conv;
|
|
125 qq_data *qd;
|
|
126 qq_group *group;
|
|
127 GList *list;
|
|
128
|
|
129 qd = (qq_data *) gc->proto_data;
|
|
130
|
|
131 conv = gaim_find_chat(gc, channel);
|
|
132 g_return_val_if_fail(conv != NULL, NULL);
|
|
133
|
|
134 list = qd->groups;
|
|
135 group = NULL;
|
|
136 while (list != NULL) {
|
|
137 group = (qq_group *) list->data;
|
|
138 if (!g_ascii_strcasecmp(gaim_conversation_get_name(conv), group->group_name_utf8))
|
|
139 break;
|
|
140 list = list->next;
|
|
141 }
|
|
142
|
|
143 return group;
|
|
144 }
|
|
145
|
14404
|
146 /* find a qq_group by its id, flag is QQ_INTERNAL_ID or QQ_EXTERNAL_ID */
|
|
147 qq_group *qq_group_find_by_id(GaimConnection *gc, guint32 id, gboolean flag)
|
14192
|
148 {
|
|
149 GList *list;
|
|
150 qq_group *group;
|
|
151 qq_data *qd;
|
|
152
|
14404
|
153 qd = (qq_data *) gc->proto_data;
|
14192
|
154
|
14404
|
155 if (qd->groups == NULL || id <= 0)
|
14192
|
156 return NULL;
|
|
157
|
|
158 list = qd->groups;
|
|
159 while (list != NULL) {
|
|
160 group = (qq_group *) list->data;
|
14404
|
161 if (flag == QQ_INTERNAL_ID ?
|
|
162 (group->internal_group_id == id) : (group->external_group_id == id))
|
14192
|
163 return group;
|
|
164 list = list->next;
|
|
165 }
|
|
166
|
|
167 return NULL;
|
|
168 }
|