Mercurial > ~mikael > mcabber > hg
annotate mcabber/mcabber/roster.c @ 1852:057b514b1f12
Fix 3 minor warnings
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 01 Apr 2010 21:12:56 +0200 |
parents | f0a07658e009 |
children | e45d13074721 |
rev | line source |
---|---|
72 | 1 /* |
2 * roster.c -- Local roster implementation | |
393 | 3 * |
1729
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1727
diff
changeset
|
4 * Copyright (C) 2005-2010 Mikael Berthe <mikael@lilotux.net> |
72 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
22 #include <string.h> | |
23 | |
24 #include "roster.h" | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
25 #include "utils.h" |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
26 #include "hooks.h" |
72 | 27 |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
28 extern void hlog_save_state(void); |
72 | 29 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
30 char *strrole[] = { /* Should match enum in roster.h */ |
584 | 31 "none", |
32 "moderator", | |
33 "participant", | |
34 "visitor" | |
35 }; | |
36 | |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
37 char *straffil[] = { /* Should match enum in roster.h */ |
584 | 38 "none", |
39 "owner", | |
40 "admin", | |
1331
a97701d8d735
Fix typo in the straffil structure (reported by gst)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
41 "member", |
584 | 42 "outcast" |
43 }; | |
44 | |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
45 char *strprintstatus[] = { /* Should match enum in roster.h */ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
46 "default", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
47 "none", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
48 "in_and_out", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
49 "all" |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
50 }; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
51 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
52 char *strautowhois[] = { /* Should match enum in roster.h */ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
53 "default", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
54 "off", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
55 "on", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
56 }; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
57 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
58 /* Resource structure */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
59 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
60 typedef struct { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
61 gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
62 gchar prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
63 enum imstatus status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
64 gchar *status_msg; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
65 time_t status_timestamp; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
66 enum imrole role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
67 enum imaffiliation affil; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
68 gchar *realjid; /* for chatrooms, if buddy's real jid is known */ |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
69 guint events; |
1600 | 70 char *caps; |
1691 | 71 #ifdef XEP0022 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
72 struct jep0022 jep22; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
73 #endif |
1691 | 74 #ifdef XEP0085 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
75 struct jep0085 jep85; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
76 #endif |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
77 #ifdef HAVE_GPGME |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
78 struct pgp_data pgpdata; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
79 #endif |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
80 } res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
81 |
72 | 82 /* This is a private structure type for the roster */ |
83 | |
84 typedef struct { | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
85 gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
86 gchar *jid; |
72 | 87 guint type; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
88 enum subscr subscription; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
89 GSList *resource; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
90 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
91 /* For groupchats */ |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
92 gchar *nickname; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
93 gchar *topic; |
952 | 94 guint inside_room; |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
95 guint print_status; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
96 guint auto_whois; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
97 |
1355 | 98 /* on_server is TRUE if the item is present on the server roster */ |
99 guint on_server; | |
100 | |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
101 /* To keep track of last status message */ |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
102 gchar *offline_status_message; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
103 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
104 /* Flag used for the UI */ |
72 | 105 guint flags; |
1802
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
106 guint ui_prio; // Boolean, positive if "attention" is requested |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
107 |
72 | 108 // list: user -> points to his group; group -> points to its users list |
109 GSList *list; | |
110 } roster; | |
111 | |
112 | |
113 /* ### Variables ### */ | |
114 | |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
115 static guchar display_filter; |
72 | 116 static GSList *groups; |
236 | 117 static GSList *unread_list; |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
118 static GHashTable *unread_jids; |
72 | 119 GList *buddylist; |
78 | 120 GList *current_buddy; |
330 | 121 GList *alternate_buddy; |
72 | 122 |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
123 static roster roster_special; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
124 |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
125 static int unread_jid_del(const char *jid); |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
126 |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
127 #define DFILTER_ALL 63 |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
128 #define DFILTER_ONLINE 62 |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
129 |
72 | 130 |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
131 /* ### Initialization ### */ |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
132 |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
133 void roster_init(void) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
134 { |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
135 roster_special.name = SPECIAL_BUFFER_STATUS_ID; |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
136 roster_special.type = ROSTER_TYPE_SPECIAL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
137 } |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
138 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
139 /* ### Resources functions ### */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
140 |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
141 static inline void free_resource_data(res *p_res) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
142 { |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
143 if (!p_res) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
144 return; |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
145 g_free((gchar*)p_res->status_msg); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
146 g_free((gchar*)p_res->name); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
147 g_free((gchar*)p_res->realjid); |
1691 | 148 #ifdef XEP0022 |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
149 g_free(p_res->jep22.last_msgid_sent); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
150 g_free(p_res->jep22.last_msgid_rcvd); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
151 #endif |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
152 #ifdef HAVE_GPGME |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
153 g_free(p_res->pgpdata.sign_keyid); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
154 #endif |
1600 | 155 g_free(p_res->caps); |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
156 g_free(p_res); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
157 } |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
158 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
159 static void free_all_resources(GSList **reslist) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
160 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
161 GSList *lip; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
162 |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
163 for (lip = *reslist; lip ; lip = g_slist_next(lip)) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
164 free_resource_data((res*)lip->data); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
165 // Free all nodes but the first (which is static) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
166 g_slist_free(*reslist); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
167 *reslist = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
168 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
169 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
170 // Resources are sorted in ascending order |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
171 static gint resource_compare_prio(res *a, res *b) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
172 if (a->prio < b->prio) return -1; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
173 else return 1; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
174 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
175 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
176 // get_resource(rost, resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
177 // Return a pointer to the resource with name resname, in rost's resources list |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
178 // - if rost has no resources, return NULL |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
179 // - if resname is defined, return the match or NULL |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
180 // - if resname is NULL, the last resource is returned, currently |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
181 // This could change in the future, because we should return the best one |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
182 // (priority? last used? and fall back to the first resource) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
183 // |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
184 static res *get_resource(roster *rost, const char *resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
185 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
186 GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
187 res *r = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
188 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
189 for (p = rost->resource; p; p = g_slist_next(p)) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
190 r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
191 if (resname && !strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
192 return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
193 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
194 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
195 // The last resource is one of the resources with the highest priority, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
196 // however, we don't know if it is the more-recently-used. |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
197 if (!resname) return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
198 return NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
199 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
200 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
201 // get_or_add_resource(rost, resname, priority) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
202 // - if there is a "resname" resource in rost's resources, return a pointer |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
203 // on this resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
204 // - if not, add the resource, set the name, and return a pointer on this |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
205 // new resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
206 static res *get_or_add_resource(roster *rost, const char *resname, gchar prio) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
207 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
208 GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
209 res *nres; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
210 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
211 if (!resname) return NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
212 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
213 for (p = rost->resource; p; p = g_slist_next(p)) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
214 res *r = p->data; |
1092
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
215 if (!strcmp(r->name, resname)) { |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
216 if (prio != r->prio) { |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
217 r->prio = prio; |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
218 rost->resource = g_slist_sort(rost->resource, |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
219 (GCompareFunc)&resource_compare_prio); |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
220 } |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
221 return r; |
1092
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
222 } |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
223 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
224 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
225 // Resource not found |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
226 nres = g_new0(res, 1); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
227 nres->name = g_strdup(resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
228 nres->prio = prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
229 rost->resource = g_slist_insert_sorted(rost->resource, nres, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
230 (GCompareFunc)&resource_compare_prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
231 return nres; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
232 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
233 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
234 static void del_resource(roster *rost, const char *resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
235 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
236 GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
237 GSList *p_res_elt = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
238 res *p_res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
239 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
240 if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
241 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
242 for (p = rost->resource; p; p = g_slist_next(p)) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
243 res *r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
244 if (!strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
245 p_res_elt = p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
246 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
247 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
248 if (!p_res_elt) return; // Resource not found |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
249 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
250 p_res = p_res_elt->data; |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
251 |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
252 // Keep a copy of the status message when a buddy goes offline |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
253 if (g_slist_length(rost->resource) == 1) { |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
254 g_free(rost->offline_status_message); |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
255 rost->offline_status_message = p_res->status_msg; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
256 p_res->status_msg = NULL; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
257 } |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
258 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
259 // Free allocations and delete resource node |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
260 free_resource_data(p_res); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
261 rost->resource = g_slist_delete_link(rost->resource, p_res_elt); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
262 return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
263 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
264 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
265 |
72 | 266 /* ### Roster functions ### */ |
267 | |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
268 static inline void free_roster_user_data(roster *roster_usr) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
269 { |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
270 if (!roster_usr) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
271 return; |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
272 g_free((gchar*)roster_usr->jid); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
273 g_free((gchar*)roster_usr->name); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
274 g_free((gchar*)roster_usr->nickname); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
275 g_free((gchar*)roster_usr->topic); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
276 g_free((gchar*)roster_usr->offline_status_message); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
277 free_all_resources(&roster_usr->resource); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
278 g_free(roster_usr); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
279 } |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
280 |
72 | 281 // Comparison function used to search in the roster (compares jids and types) |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
331
diff
changeset
|
282 static gint roster_compare_jid_type(roster *a, roster *b) { |
89 | 283 if (! (a->type & b->type)) |
480 | 284 return -1; // arbitrary (but should be != 0, of course) |
72 | 285 return strcasecmp(a->jid, b->jid); |
286 } | |
287 | |
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
288 // Comparison function used to search in the roster (compares names and types) |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
289 static gint roster_compare_name_type(roster *a, roster *b) { |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
290 if (! (a->type & b->type)) |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
291 return -1; // arbitrary (but should be != 0, of course) |
783
25022410f80f
Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
292 return strcmp(a->name, b->name); |
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
293 } |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
294 |
72 | 295 // Comparison function used to sort the roster (by name) |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
331
diff
changeset
|
296 static gint roster_compare_name(roster *a, roster *b) { |
783
25022410f80f
Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
297 return strcmp(a->name, b->name); |
72 | 298 } |
299 | |
300 // Finds a roster element (user, group, agent...), by jid or name | |
89 | 301 // If roster_type is 0, returns match of any type. |
72 | 302 // Returns the roster GSList element, or NULL if jid/name not found |
78 | 303 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type) |
72 | 304 { |
305 GSList *sl_roster_elt = groups; | |
1058 | 306 GSList *resource; |
72 | 307 roster sample; |
308 GCompareFunc comp; | |
309 | |
192 | 310 if (!jidname) return NULL; |
72 | 311 |
89 | 312 if (!roster_type) |
480 | 313 roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
314 ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP; |
89 | 315 |
72 | 316 sample.type = roster_type; |
317 if (type == jidsearch) { | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
318 sample.jid = (gchar*)jidname; |
72 | 319 comp = (GCompareFunc)&roster_compare_jid_type; |
320 } else if (type == namesearch) { | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
321 sample.name = (gchar*)jidname; |
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
322 comp = (GCompareFunc)&roster_compare_name_type; |
72 | 323 } else |
885
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
324 return NULL; // Should not happen... |
72 | 325 |
326 while (sl_roster_elt) { | |
327 roster *roster_elt = (roster*)sl_roster_elt->data; | |
328 if (roster_type & ROSTER_TYPE_GROUP) { | |
783
25022410f80f
Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
329 if ((type == namesearch) && !strcmp(jidname, roster_elt->name)) |
72 | 330 return sl_roster_elt; |
331 } | |
1058 | 332 resource = g_slist_find_custom(roster_elt->list, &sample, comp); |
333 if (resource) return resource; | |
72 | 334 sl_roster_elt = g_slist_next(sl_roster_elt); |
335 } | |
336 return NULL; | |
337 } | |
338 | |
339 // Returns pointer to new group, or existing group with that name | |
78 | 340 GSList *roster_add_group(const char *name) |
72 | 341 { |
342 roster *roster_grp; | |
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
343 GSList *p_group; |
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
344 |
72 | 345 // #1 Check name doesn't already exist |
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
346 p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP); |
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
347 if (!p_group) { |
72 | 348 // #2 Create the group node |
349 roster_grp = g_new0(roster, 1); | |
350 roster_grp->name = g_strdup(name); | |
351 roster_grp->type = ROSTER_TYPE_GROUP; | |
352 // #3 Insert (sorted) | |
353 groups = g_slist_insert_sorted(groups, roster_grp, | |
354 (GCompareFunc)&roster_compare_name); | |
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
355 p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP); |
72 | 356 } |
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
357 return p_group; |
72 | 358 } |
359 | |
1803
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
360 // Comparison function used to sort the unread list by ui (attn) priority |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
361 static gint _roster_compare_uiprio(roster *a, roster *b) { |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
362 return (b->ui_prio - a->ui_prio); |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
363 } |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
364 |
72 | 365 // Returns a pointer to the new user, or existing user with that name |
1355 | 366 // Note: if onserver is -1, the flag won't be changed. |
78 | 367 GSList *roster_add_user(const char *jid, const char *name, const char *group, |
1355 | 368 guint type, enum subscr esub, gint onserver) |
72 | 369 { |
370 roster *roster_usr; | |
371 roster *my_group; | |
372 GSList *slist; | |
373 | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
374 if ((type != ROSTER_TYPE_USER) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
375 (type != ROSTER_TYPE_ROOM) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
376 (type != ROSTER_TYPE_AGENT)) { |
72 | 377 // XXX Error message? |
378 return NULL; | |
379 } | |
380 | |
78 | 381 // Let's be arbitrary: default group has an empty name (""). |
382 if (!group) group = ""; | |
383 | |
72 | 384 // #1 Check this user doesn't already exist |
563
b0f1b127bfb6
Prevent from adding a duplicate jid (when types are different)
Mikael Berthe <mikael@lilotux.net>
parents:
562
diff
changeset
|
385 slist = roster_find(jid, jidsearch, 0); |
607 | 386 if (slist) { |
387 char *oldgroupname; | |
388 // That's an update | |
389 roster_usr = slist->data; | |
390 roster_usr->subscription = esub; | |
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
391 if (onserver >= 0) |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
392 buddy_setonserverflag(slist->data, onserver); |
607 | 393 if (name) |
394 buddy_setname(slist->data, (char*)name); | |
395 // Let's check if the group name has changed | |
396 oldgroupname = ((roster*)((GSList*)roster_usr->list)->data)->name; | |
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
397 if (group && strcmp(oldgroupname, group)) { |
607 | 398 buddy_setgroup(slist->data, (char*)group); |
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
399 // Note: buddy_setgroup() updates the user lists so we cannot |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
400 // use slist anymore. |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
401 return roster_find(jid, jidsearch, 0); |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
402 } |
607 | 403 return slist; |
404 } | |
72 | 405 // #2 add group if necessary |
406 slist = roster_add_group(group); | |
407 if (!slist) return NULL; | |
408 my_group = (roster*)slist->data; | |
409 // #3 Create user node | |
410 roster_usr = g_new0(roster, 1); | |
411 roster_usr->jid = g_strdup(jid); | |
78 | 412 if (name) { |
413 roster_usr->name = g_strdup(name); | |
414 } else { | |
415 gchar *p, *str = g_strdup(jid); | |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
974
diff
changeset
|
416 p = strchr(str, JID_RESOURCE_SEPARATOR); |
78 | 417 if (p) *p = '\0'; |
418 roster_usr->name = g_strdup(str); | |
419 g_free(str); | |
420 } | |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
421 if (unread_jid_del(jid)) { |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
422 roster_usr->flags |= ROSTER_FLAG_MSG; |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
423 // Append the roster_usr to unread_list |
1803
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
424 unread_list = g_slist_insert_sorted(unread_list, roster_usr, |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
425 (GCompareFunc)&_roster_compare_uiprio); |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
426 } |
603 | 427 roster_usr->type = type; |
428 roster_usr->subscription = esub; | |
429 roster_usr->list = slist; // (my_group SList element) | |
1355 | 430 if (onserver == 1) |
431 roster_usr->on_server = TRUE; | |
72 | 432 // #4 Insert node (sorted) |
433 my_group->list = g_slist_insert_sorted(my_group->list, roster_usr, | |
564 | 434 (GCompareFunc)&roster_compare_name); |
72 | 435 return roster_find(jid, jidsearch, type); |
436 } | |
437 | |
438 // Removes user (jid) from roster, frees allocated memory | |
78 | 439 void roster_del_user(const char *jid) |
72 | 440 { |
441 GSList *sl_user, *sl_group; | |
442 GSList **sl_group_listptr; | |
443 roster *roster_usr; | |
246 | 444 GSList *node; |
72 | 445 |
1431
486809ccffc0
Let /del remove a MUC entry from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
446 sl_user = roster_find(jid, jidsearch, |
486809ccffc0
Let /del remove a MUC entry from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
447 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
89 | 448 if (sl_user == NULL) |
72 | 449 return; |
450 roster_usr = (roster*)sl_user->data; | |
246 | 451 |
452 // Remove (if present) from unread messages list | |
453 node = g_slist_find(unread_list, roster_usr); | |
454 if (node) unread_list = g_slist_delete_link(unread_list, node); | |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
455 // If there is a pending unread message, keep track of it |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
456 if (roster_usr->flags & ROSTER_FLAG_MSG) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
457 unread_jid_add(roster_usr->jid); |
246 | 458 |
1389
cefda9174d62
Fix an old bug in roster_del_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1377
diff
changeset
|
459 sl_group = roster_usr->list; |
cefda9174d62
Fix an old bug in roster_del_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1377
diff
changeset
|
460 |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
461 // Let's free roster_usr memory (jid, name, status message...) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
462 free_roster_user_data(roster_usr); |
72 | 463 |
464 // That's a little complex, we need to dereference twice | |
465 sl_group_listptr = &((roster*)(sl_group->data))->list; | |
466 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); | |
78 | 467 |
468 // We need to rebuild the list | |
469 if (current_buddy) | |
470 buddylist_build(); | |
210 | 471 // TODO What we could do, too, is to check if the deleted node is |
78 | 472 // current_buddy, in which case we could move current_buddy to the |
473 // previous (or next) node. | |
72 | 474 } |
475 | |
210 | 476 // Free all roster data and call buddylist_build() to free the buddylist. |
164 | 477 void roster_free(void) |
478 { | |
479 GSList *sl_grp = groups; | |
480 | |
301
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
481 // Free unread_list |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
482 if (unread_list) { |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
483 g_slist_free(unread_list); |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
484 unread_list = NULL; |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
485 } |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
486 |
164 | 487 // Walk through groups |
488 while (sl_grp) { | |
489 roster *roster_grp = (roster*)sl_grp->data; | |
490 GSList *sl_usr = roster_grp->list; | |
491 // Walk through this group users | |
492 while (sl_usr) { | |
493 roster *roster_usr = (roster*)sl_usr->data; | |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
494 // If there is a pending unread message, keep track of it |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
495 if (roster_usr->flags & ROSTER_FLAG_MSG) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
496 unread_jid_add(roster_usr->jid); |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
497 // Free roster_usr data (jid, name, status message...) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
498 free_roster_user_data(roster_usr); |
164 | 499 sl_usr = g_slist_next(sl_usr); |
500 } | |
501 // Free group's users list | |
502 if (roster_grp->list) | |
503 g_slist_free(roster_grp->list); | |
504 // Free group's name and jid | |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
505 g_free((gchar*)roster_grp->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
506 g_free((gchar*)roster_grp->name); |
214 | 507 g_free(roster_grp); |
164 | 508 sl_grp = g_slist_next(sl_grp); |
509 } | |
510 // Free groups list | |
511 if (groups) { | |
512 g_slist_free(groups); | |
513 groups = NULL; | |
514 // Update (i.e. free) buddylist | |
515 if (buddylist) | |
516 buddylist_build(); | |
517 } | |
518 } | |
519 | |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
520 // roster_setstatus() |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
521 // Note: resname, role, affil and realjid are for room members only |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
522 void roster_setstatus(const char *jid, const char *resname, gchar prio, |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
523 enum imstatus bstat, const char *status_msg, |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
524 time_t status_time, |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
525 enum imrole role, enum imaffiliation affil, |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
526 const char *realjid) |
72 | 527 { |
528 GSList *sl_user; | |
529 roster *roster_usr; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
530 res *p_res; |
72 | 531 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
532 sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
533 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
92 | 534 // If we can't find it, we add it |
89 | 535 if (sl_user == NULL) |
1355 | 536 sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, |
537 sub_none, -1); | |
72 | 538 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
539 // If there is no resource name, we can leave now |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
540 if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
541 |
72 | 542 roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
543 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
544 // New or updated resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
545 p_res = get_or_add_resource(roster_usr, resname, prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
546 p_res->status = bstat; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
547 if (p_res->status_msg) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
548 g_free((gchar*)p_res->status_msg); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
549 p_res->status_msg = NULL; |
221 | 550 } |
551 if (status_msg) | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
552 p_res->status_msg = g_strdup(status_msg); |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
553 if (!status_time) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
554 time(&status_time); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
555 p_res->status_timestamp = status_time; |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
556 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
557 p_res->role = role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
558 p_res->affil = affil; |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
559 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
560 if (p_res->realjid) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
561 g_free((gchar*)p_res->realjid); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
562 p_res->realjid = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
563 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
564 if (realjid) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
565 p_res->realjid = g_strdup(realjid); |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
566 |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
567 // If bstat is offline, we MUST delete the resource, actually |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
568 if (bstat == offline) { |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
569 del_resource(roster_usr, resname); |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
570 return; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
571 } |
72 | 572 } |
573 | |
78 | 574 // roster_setflags() |
575 // Set one or several flags to value (TRUE/FALSE) | |
80 | 576 void roster_setflags(const char *jid, guint flags, guint value) |
78 | 577 { |
578 GSList *sl_user; | |
579 roster *roster_usr; | |
580 | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
581 sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
582 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
89 | 583 if (sl_user == NULL) |
78 | 584 return; |
585 | |
586 roster_usr = (roster*)sl_user->data; | |
587 if (value) | |
588 roster_usr->flags |= flags; | |
589 else | |
590 roster_usr->flags &= ~flags; | |
591 } | |
148 | 592 |
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1812
diff
changeset
|
593 // roster_unread_check() |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1812
diff
changeset
|
594 static void roster_unread_check(void) |
1809
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
595 { |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
596 guint unread_count = 0; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
597 gpointer unread_ptr, first_unread; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
598 guint muc_unread = 0, muc_attention = 0; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
599 guint attention_count = 0; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
600 |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
601 unread_ptr = first_unread = unread_msg(NULL); |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
602 if (first_unread) { |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
603 do { |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
604 guint type = buddy_gettype(unread_ptr); |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
605 unread_count++; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
606 |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
607 if (type & ROSTER_TYPE_ROOM) { |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
608 muc_unread++; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
609 if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_MUC_HL_MESSAGE) |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
610 muc_attention++; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
611 } else { |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
612 if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_ATTENTION_MESSAGE) |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
613 attention_count++; |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
614 } |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
615 unread_ptr = unread_msg(unread_ptr); |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
616 } while (unread_ptr && unread_ptr != first_unread); |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
617 } |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
618 |
1812
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
619 hk_unread_list_change(unread_count, attention_count, |
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
620 muc_unread, muc_attention); |
1809
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
621 } |
eef8c9fff727
Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents:
1806
diff
changeset
|
622 |
148 | 623 // roster_msg_setflag() |
624 // Set the ROSTER_FLAG_MSG to the given value for the given jid. | |
625 // It will update the buddy's group message flag. | |
236 | 626 // Update the unread messages list too. |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
627 void roster_msg_setflag(const char *jid, guint special, guint value) |
148 | 628 { |
629 GSList *sl_user; | |
630 roster *roster_usr, *roster_grp; | |
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
631 int new_roster_item = FALSE; |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
632 guint unread_list_modified = FALSE; |
148 | 633 |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
634 if (special) { |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
635 //sl_user = roster_find(jid, namesearch, ROSTER_TYPE_SPECIAL); |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
636 //if (!sl_user) return; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
637 //roster_usr = (roster*)sl_user->data; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
638 roster_usr = &roster_special; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
639 if (value) { |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
640 if (!(roster_usr->flags & ROSTER_FLAG_MSG)) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
641 unread_list_modified = TRUE; |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
642 roster_usr->flags |= ROSTER_FLAG_MSG; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
643 // Append the roster_usr to unread_list, but avoid duplicates |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
644 if (!g_slist_find(unread_list, roster_usr)) |
1803
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
645 unread_list = g_slist_insert_sorted(unread_list, roster_usr, |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
646 (GCompareFunc)&_roster_compare_uiprio); |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
647 } else { |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
648 if (roster_usr->flags & ROSTER_FLAG_MSG) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
649 unread_list_modified = TRUE; |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
650 roster_usr->flags &= ~ROSTER_FLAG_MSG; |
1802
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
651 roster_usr->ui_prio = 0; |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
652 if (unread_list) { |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
653 GSList *node = g_slist_find(unread_list, roster_usr); |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
654 if (node) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
655 unread_list = g_slist_delete_link(unread_list, node); |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
656 } |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
657 } |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
658 goto roster_msg_setflag_return; |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
659 } |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
660 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
661 sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
662 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
678
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
663 // If we can't find it, we add it |
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
664 if (sl_user == NULL) { |
1355 | 665 sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, sub_none, -1); |
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
666 new_roster_item = TRUE; |
678
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
667 } |
148 | 668 |
669 roster_usr = (roster*)sl_user->data; | |
670 roster_grp = (roster*)roster_usr->list->data; | |
671 if (value) { | |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
672 if (!(roster_usr->flags & ROSTER_FLAG_MSG)) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
673 unread_list_modified = TRUE; |
148 | 674 // Message flag is TRUE. This is easy, we just have to set both flags |
675 // to TRUE... | |
676 roster_usr->flags |= ROSTER_FLAG_MSG; | |
677 roster_grp->flags |= ROSTER_FLAG_MSG; // group | |
236 | 678 // Append the roster_usr to unread_list, but avoid duplicates |
679 if (!g_slist_find(unread_list, roster_usr)) | |
1803
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
680 unread_list = g_slist_insert_sorted(unread_list, roster_usr, |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
681 (GCompareFunc)&_roster_compare_uiprio); |
148 | 682 } else { |
683 // Message flag is FALSE. | |
684 guint msg = FALSE; | |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
685 if (roster_usr->flags & ROSTER_FLAG_MSG) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
686 unread_list_modified = TRUE; |
148 | 687 roster_usr->flags &= ~ROSTER_FLAG_MSG; |
1802
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
688 roster_usr->ui_prio = 0; |
236 | 689 if (unread_list) { |
690 GSList *node = g_slist_find(unread_list, roster_usr); | |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
691 if (node) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
692 unread_list = g_slist_delete_link(unread_list, node); |
236 | 693 } |
148 | 694 // For the group value we need to watch all buddies in this group; |
695 // if one is flagged, then the group will be flagged. | |
696 // I will re-use sl_user and roster_usr here, as they aren't used | |
697 // anymore. | |
698 sl_user = roster_grp->list; | |
699 while (sl_user) { | |
700 roster_usr = (roster*)sl_user->data; | |
701 if (roster_usr->flags & ROSTER_FLAG_MSG) { | |
702 msg = TRUE; | |
703 break; | |
704 } | |
705 sl_user = g_slist_next(sl_user); | |
706 } | |
707 if (!msg) | |
708 roster_grp->flags &= ~ROSTER_FLAG_MSG; | |
709 else | |
710 roster_grp->flags |= ROSTER_FLAG_MSG; | |
711 // Actually the "else" part is useless, because the group | |
712 // ROSTER_FLAG_MSG should already be set... | |
713 } | |
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
714 |
1010
54405d09b15a
Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
715 if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr))) |
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
716 buddylist_build(); |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
717 |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
718 roster_msg_setflag_return: |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
719 if (unread_list_modified) { |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
720 hlog_save_state(); |
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1812
diff
changeset
|
721 roster_unread_check(); |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
722 } |
148 | 723 } |
724 | |
1802
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
725 // roster_setuiprio(jid, special, prio_value, action) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
726 // Set the "attention" priority value for the given roster item. |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
727 // Note that this function doesn't create the roster item if it doesn't exist. |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
728 void roster_setuiprio(const char *jid, guint special, guint value, |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
729 enum setuiprio_ops action) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
730 { |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
731 guint oldval, newval; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
732 roster *roster_usr; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
733 |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
734 if (special) { |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
735 roster_usr = &roster_special; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
736 } else { |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
737 GSList *sl_user = roster_find(jid, jidsearch, |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
738 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
739 if (!sl_user) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
740 return; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
741 |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
742 roster_usr = (roster*)sl_user->data; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
743 } |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
744 oldval = roster_usr->ui_prio; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
745 |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
746 if (action == prio_max) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
747 newval = MAX(oldval, value); |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
748 else if (action == prio_inc) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
749 newval = oldval + value; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
750 else // prio_set |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
751 newval = value; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
752 |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
753 roster_usr->ui_prio = newval; |
1803
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
754 unread_list = g_slist_sort(unread_list, |
7d3060070d10
Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents:
1802
diff
changeset
|
755 (GCompareFunc)&_roster_compare_uiprio); |
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1812
diff
changeset
|
756 roster_unread_check(); |
1802
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
757 } |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
758 |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
759 guint roster_getuiprio(const char *jid, guint special) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
760 { |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
761 roster *roster_usr; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
762 GSList *sl_user; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
763 |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
764 if (special) { |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
765 roster_usr = &roster_special; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
766 return roster_usr->ui_prio; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
767 } |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
768 |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
769 sl_user = roster_find(jid, jidsearch, |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
770 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
771 if (!sl_user) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
772 return 0; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
773 roster_usr = (roster*)sl_user->data; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
774 return roster_usr->ui_prio; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
775 } |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
776 |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
777 const char *roster_getname(const char *jid) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
778 { |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
779 GSList *sl_user; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
780 roster *roster_usr; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
781 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
782 sl_user = roster_find(jid, jidsearch, |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
783 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
784 if (sl_user == NULL) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
785 return NULL; // Not in the roster... |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
786 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
787 roster_usr = (roster*)sl_user->data; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
788 return roster_usr->name; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
789 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
790 |
863
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
791 const char *roster_getnickname(const char *jid) |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
792 { |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
793 GSList *sl_user; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
794 roster *roster_usr; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
795 |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
796 sl_user = roster_find(jid, jidsearch, |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
797 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
798 if (sl_user == NULL) |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
799 return NULL; // Not in the roster... |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
800 |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
801 roster_usr = (roster*)sl_user->data; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
802 return roster_usr->nickname; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
803 } |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
804 |
89 | 805 void roster_settype(const char *jid, guint type) |
806 { | |
807 GSList *sl_user; | |
808 roster *roster_usr; | |
809 | |
810 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) | |
811 return; | |
812 | |
813 roster_usr = (roster*)sl_user->data; | |
814 roster_usr->type = type; | |
815 } | |
816 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
817 enum imstatus roster_getstatus(const char *jid, const char *resname) |
90 | 818 { |
819 GSList *sl_user; | |
820 roster *roster_usr; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
821 res *p_res; |
90 | 822 |
823 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); | |
824 if (sl_user == NULL) | |
825 return offline; // Not in the roster, anyway... | |
826 | |
827 roster_usr = (roster*)sl_user->data; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
828 p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
829 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
830 return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
831 return offline; |
90 | 832 } |
833 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
834 const char *roster_getstatusmsg(const char *jid, const char *resname) |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
835 { |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
836 GSList *sl_user; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
837 roster *roster_usr; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
838 res *p_res; |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
839 |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
840 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
841 if (sl_user == NULL) |
425
03f1e37759a6
roster_getstatusmsg() should return a pointer
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
842 return NULL; // Not in the roster, anyway... |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
843 |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
844 roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
845 p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
846 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
847 return p_res->status_msg; |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
848 return roster_usr->offline_status_message; |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
849 } |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
850 |
1727
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
851 char roster_getprio(const char *jid, const char *resname) |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
852 { |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
853 GSList *sl_user; |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
854 roster *roster_usr; |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
855 res *p_res; |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
856 |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
857 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
858 if (sl_user == NULL) |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
859 return offline; // Not in the roster, anyway... |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
860 |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
861 roster_usr = (roster*)sl_user->data; |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
862 p_res = get_resource(roster_usr, resname); |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
863 if (p_res) |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
864 return p_res->prio; |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
865 return 0; |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
866 } |
15e6b21df606
Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents:
1691
diff
changeset
|
867 |
89 | 868 guint roster_gettype(const char *jid) |
869 { | |
870 GSList *sl_user; | |
871 roster *roster_usr; | |
872 | |
873 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) | |
874 return 0; | |
875 | |
876 roster_usr = (roster*)sl_user->data; | |
877 return roster_usr->type; | |
878 } | |
879 | |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
880 guint roster_getsubscription(const char *jid) |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
881 { |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
882 GSList *sl_user; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
883 roster *roster_usr; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
884 |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
885 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
886 return 0; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
887 |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
888 roster_usr = (roster*)sl_user->data; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
889 return roster_usr->subscription; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
890 } |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
891 |
610
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
892 // roster_unsubscribed() |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
893 // We have lost buddy's presence updates; this function clears the status |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
894 // message, sets the buddy offline and frees the resources |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
895 void roster_unsubscribed(const char *jid) |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
896 { |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
897 GSList *sl_user; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
898 roster *roster_usr; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
899 |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
900 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
901 if (sl_user == NULL) |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
902 return; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
903 |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
904 roster_usr = (roster*)sl_user->data; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
905 free_all_resources(&roster_usr->resource); |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
906 } |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
907 |
72 | 908 |
909 /* ### BuddyList functions ### */ | |
910 | |
120 | 911 // buddylist_set_hide_offline_buddies(hide) |
72 | 912 // "hide" values: 1=hide 0=show_all -1=invert |
120 | 913 void buddylist_set_hide_offline_buddies(int hide) |
72 | 914 { |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
915 if (hide < 0) { // NEG (invert) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
916 if (display_filter == DFILTER_ALL) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
917 display_filter = DFILTER_ONLINE; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
918 else |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
919 display_filter = DFILTER_ALL; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
920 } else if (hide == 0) { // FALSE (don't hide -- andfo_) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
921 display_filter = DFILTER_ALL; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
922 } else { // TRUE (hide -- andfo) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
923 display_filter = DFILTER_ONLINE; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
924 } |
72 | 925 } |
926 | |
1413 | 927 int buddylist_isset_filter(void) |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
928 { |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
929 return (display_filter != DFILTER_ALL); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
930 } |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
931 |
1504
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
932 int buddylist_is_status_filtered(enum imstatus status) |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
933 { |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
934 return display_filter & (1 << status); |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
935 } |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
936 |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
937 void buddylist_set_filter(guchar filter) |
120 | 938 { |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
939 display_filter = filter; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
940 } |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
941 |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
942 guchar buddylist_get_filter(void) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
943 { |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
944 return display_filter; |
120 | 945 } |
946 | |
72 | 947 // buddylist_build() |
948 // Creates the buddylist from the roster entries. | |
949 void buddylist_build(void) | |
950 { | |
951 GSList *sl_roster_elt = groups; | |
952 roster *roster_elt; | |
81 | 953 roster *roster_current_buddy = NULL; |
330 | 954 roster *roster_alternate_buddy = NULL; |
128 | 955 int shrunk_group; |
72 | 956 |
81 | 957 // We need to remember which buddy is selected. |
958 if (current_buddy) | |
959 roster_current_buddy = BUDDATA(current_buddy); | |
960 current_buddy = NULL; | |
330 | 961 if (alternate_buddy) |
962 roster_alternate_buddy = BUDDATA(alternate_buddy); | |
963 alternate_buddy = NULL; | |
81 | 964 |
72 | 965 // Destroy old buddylist |
966 if (buddylist) { | |
967 g_list_free(buddylist); | |
968 buddylist = NULL; | |
969 } | |
970 | |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
971 buddylist = g_list_append(buddylist, &roster_special); |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
972 |
72 | 973 // Create the new list |
974 while (sl_roster_elt) { | |
975 GSList *sl_roster_usrelt; | |
976 roster *roster_usrelt; | |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
977 guint pending_group = TRUE; |
72 | 978 roster_elt = (roster*) sl_roster_elt->data; |
979 | |
128 | 980 shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE; |
981 | |
72 | 982 sl_roster_usrelt = roster_elt->list; |
983 while (sl_roster_usrelt) { | |
984 roster_usrelt = (roster*) sl_roster_usrelt->data; | |
985 | |
986 // Buddy will be added if either: | |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
987 // - buddy's status matches the display_filter |
72 | 988 // - buddy has a lock (for example the buddy window is currently open) |
989 // - buddy has a pending (non-read) message | |
128 | 990 // - group isn't hidden (shrunk) |
147 | 991 // - this is the current_buddy |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
992 if (roster_usrelt == roster_current_buddy || |
1504
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
993 buddylist_is_status_filtered(buddy_getstatus((gpointer)roster_usrelt, |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
994 NULL)) || |
72 | 995 (buddy_getflags((gpointer)roster_usrelt) & |
974
36f7753dfb59
Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
996 (ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) { |
72 | 997 // This user should be added. Maybe the group hasn't been added yet? |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
998 if (pending_group) { |
72 | 999 // It hasn't been done yet |
1000 buddylist = g_list_append(buddylist, roster_elt); | |
1001 pending_group = FALSE; | |
1002 } | |
1003 // Add user | |
128 | 1004 // XXX Should we add the user if there is a message and |
1005 // the group is shrunk? If so, we'd need to check LOCK flag too, | |
1006 // perhaps... | |
1007 if (!shrunk_group) | |
1008 buddylist = g_list_append(buddylist, roster_usrelt); | |
72 | 1009 } |
1010 | |
1011 sl_roster_usrelt = g_slist_next(sl_roster_usrelt); | |
1012 } | |
1013 sl_roster_elt = g_slist_next(sl_roster_elt); | |
1014 } | |
78 | 1015 |
81 | 1016 // Check if we can find our saved current_buddy... |
1017 if (roster_current_buddy) | |
1018 current_buddy = g_list_find(buddylist, roster_current_buddy); | |
330 | 1019 if (roster_alternate_buddy) |
1020 alternate_buddy = g_list_find(buddylist, roster_alternate_buddy); | |
78 | 1021 // current_buddy initialization |
1022 if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1)) | |
81 | 1023 current_buddy = g_list_first(buddylist); |
72 | 1024 } |
1025 | |
1026 // buddy_hide_group(roster, hide) | |
1027 // "hide" values: 1=hide 0=show_all -1=invert | |
1028 void buddy_hide_group(gpointer rosterdata, int hide) | |
1029 { | |
207 | 1030 roster *roster_usr = rosterdata; |
72 | 1031 if (hide > 0) // TRUE (hide) |
207 | 1032 roster_usr->flags |= ROSTER_FLAG_HIDE; |
72 | 1033 else if (hide < 0) // NEG (invert) |
207 | 1034 roster_usr->flags ^= ROSTER_FLAG_HIDE; |
72 | 1035 else // FALSE (don't hide) |
207 | 1036 roster_usr->flags &= ~ROSTER_FLAG_HIDE; |
72 | 1037 } |
1038 | |
1039 const char *buddy_getjid(gpointer rosterdata) | |
1040 { | |
1475
ef09de538e8f
Fix compilation error (reported by H. D. Oezbilen)
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
1041 roster *roster_usr = rosterdata; |
1292
382ec54b584e
Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1205
diff
changeset
|
1042 if (!rosterdata) |
382ec54b584e
Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1205
diff
changeset
|
1043 return NULL; |
207 | 1044 return roster_usr->jid; |
1045 } | |
1046 | |
210 | 1047 // buddy_setgroup() |
1048 // Change the group of current buddy | |
1049 // | |
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1050 // Note: buddy_setgroup() updates the user lists. |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1051 // |
210 | 1052 void buddy_setgroup(gpointer rosterdata, char *newgroupname) |
1053 { | |
1054 roster *roster_usr = rosterdata; | |
1055 GSList **sl_group; | |
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1056 GSList *sl_newgroup; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1057 roster *my_newgroup; |
210 | 1058 |
1059 // A group has no group :) | |
1060 if (roster_usr->type & ROSTER_TYPE_GROUP) return; | |
1061 | |
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1062 // Add newgroup if necessary |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1063 if (!newgroupname) newgroupname = ""; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1064 sl_newgroup = roster_add_group(newgroupname); |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1065 if (!sl_newgroup) return; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1066 my_newgroup = (roster*)sl_newgroup->data; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1067 |
210 | 1068 // Remove the buddy from current group |
1069 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; | |
1070 *sl_group = g_slist_remove(*sl_group, rosterdata); | |
393 | 1071 |
621
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
1072 // Remove old group if it is empty |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
1073 if (!*sl_group) { |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
1074 roster *roster_grp = (roster*)((GSList*)roster_usr->list)->data; |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1075 g_free((gchar*)roster_grp->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1076 g_free((gchar*)roster_grp->name); |
621
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
1077 g_free(roster_grp); |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
1078 groups = g_slist_remove(groups, roster_grp); |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
1079 } |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
1080 |
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1081 // Add the buddy to its new group |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1082 roster_usr->list = sl_newgroup; // (my_newgroup SList element) |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1083 my_newgroup->list = g_slist_insert_sorted(my_newgroup->list, roster_usr, |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1084 (GCompareFunc)&roster_compare_name); |
212 | 1085 |
210 | 1086 buddylist_build(); |
1087 } | |
1088 | |
207 | 1089 void buddy_setname(gpointer rosterdata, char *newname) |
1090 { | |
1091 roster *roster_usr = rosterdata; | |
209 | 1092 GSList **sl_group; |
207 | 1093 |
1094 // TODO For groups, we need to check for unicity | |
1095 // However, renaming a group boils down to moving all its buddies to | |
1096 // another group, so calling this function is not really necessary... | |
1097 if (roster_usr->type & ROSTER_TYPE_GROUP) return; | |
1098 | |
1099 if (roster_usr->name) { | |
1100 g_free((gchar*)roster_usr->name); | |
1101 roster_usr->name = NULL; | |
1102 } | |
1103 if (newname) | |
1104 roster_usr->name = g_strdup(newname); | |
209 | 1105 |
1106 // We need to resort the group list | |
1107 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; | |
1108 *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name); | |
1109 | |
1110 buddylist_build(); | |
72 | 1111 } |
1112 | |
1113 const char *buddy_getname(gpointer rosterdata) | |
1114 { | |
207 | 1115 roster *roster_usr = rosterdata; |
1116 return roster_usr->name; | |
1117 } | |
1118 | |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1119 // buddy_setnickname(buddy, newnickname) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1120 // Only for chatrooms |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1121 void buddy_setnickname(gpointer rosterdata, const char *newname) |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1122 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1123 roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1124 |
649
3ad6675caaf1
MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1125 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; // XXX Error message? |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1126 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1127 if (roster_usr->nickname) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1128 g_free((gchar*)roster_usr->nickname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1129 roster_usr->nickname = NULL; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1130 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1131 if (newname) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1132 roster_usr->nickname = g_strdup(newname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1133 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1134 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1135 const char *buddy_getnickname(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1136 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1137 roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1138 return roster_usr->nickname; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1139 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1140 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1141 // buddy_setinsideroom(buddy, inside) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1142 // Only for chatrooms |
952 | 1143 void buddy_setinsideroom(gpointer rosterdata, guint inside) |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1144 { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1145 roster *roster_usr = rosterdata; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1146 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1147 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1148 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1149 roster_usr->inside_room = inside; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1150 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1151 |
952 | 1152 guint buddy_getinsideroom(gpointer rosterdata) |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1153 { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1154 roster *roster_usr = rosterdata; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1155 return roster_usr->inside_room; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1156 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1157 |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1158 // buddy_settopic(buddy, newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1159 // Only for chatrooms |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1160 void buddy_settopic(gpointer rosterdata, const char *newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1161 { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1162 roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1163 |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1164 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1165 |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1166 if (roster_usr->topic) { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1167 g_free((gchar*)roster_usr->topic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1168 roster_usr->topic = NULL; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1169 } |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1170 if (newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1171 roster_usr->topic = g_strdup(newtopic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1172 } |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1173 |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1174 const char *buddy_gettopic(gpointer rosterdata) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1175 { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1176 roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1177 return roster_usr->topic; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1178 } |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1179 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1180 void buddy_setprintstatus(gpointer rosterdata, enum room_printstatus pstatus) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1181 { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1182 roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1183 roster_usr->print_status = pstatus; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1184 } |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1185 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1186 enum room_printstatus buddy_getprintstatus(gpointer rosterdata) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1187 { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1188 roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1189 return roster_usr->print_status; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1190 } |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1191 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1192 void buddy_setautowhois(gpointer rosterdata, enum room_autowhois awhois) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1193 { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1194 roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1195 roster_usr->auto_whois = awhois; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1196 } |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1197 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1198 enum room_autowhois buddy_getautowhois(gpointer rosterdata) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1199 { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1200 roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1201 return roster_usr->auto_whois; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1202 } |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1203 |
207 | 1204 // buddy_getgroupname() |
1205 // Returns a pointer on buddy's group name. | |
1206 const char *buddy_getgroupname(gpointer rosterdata) | |
1207 { | |
1208 roster *roster_usr = rosterdata; | |
1209 | |
1210 if (roster_usr->type & ROSTER_TYPE_GROUP) | |
1211 return roster_usr->name; | |
1212 | |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1213 if (roster_usr->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1214 return NULL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1215 |
207 | 1216 // This is a user |
1217 return ((roster*)((GSList*)roster_usr->list)->data)->name; | |
72 | 1218 } |
1219 | |
166 | 1220 // buddy_getgroup() |
1221 // Returns a pointer on buddy's group. | |
1222 gpointer buddy_getgroup(gpointer rosterdata) | |
1223 { | |
207 | 1224 roster *roster_usr = rosterdata; |
166 | 1225 |
207 | 1226 if (roster_usr->type & ROSTER_TYPE_GROUP) |
166 | 1227 return rosterdata; |
1228 | |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1229 if (roster_usr->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1230 return NULL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1231 |
166 | 1232 // This is a user |
207 | 1233 return (gpointer)((GSList*)roster_usr->list)->data; |
166 | 1234 } |
1235 | |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1236 void buddy_settype(gpointer rosterdata, guint type) |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1237 { |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1238 roster *roster_usr = rosterdata; |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1239 roster_usr->type = type; |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1240 } |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1241 |
72 | 1242 guint buddy_gettype(gpointer rosterdata) |
1243 { | |
207 | 1244 roster *roster_usr = rosterdata; |
1245 return roster_usr->type; | |
72 | 1246 } |
1247 | |
603 | 1248 guint buddy_getsubscription(gpointer rosterdata) |
1249 { | |
1250 roster *roster_usr = rosterdata; | |
1251 return roster_usr->subscription; | |
1252 } | |
1253 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1254 enum imstatus buddy_getstatus(gpointer rosterdata, const char *resname) |
72 | 1255 { |
207 | 1256 roster *roster_usr = rosterdata; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1257 res *p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1258 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1259 return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1260 return offline; |
72 | 1261 } |
1262 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1263 const char *buddy_getstatusmsg(gpointer rosterdata, const char *resname) |
221 | 1264 { |
1265 roster *roster_usr = rosterdata; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1266 res *p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1267 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1268 return p_res->status_msg; |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
1269 return roster_usr->offline_status_message; |
221 | 1270 } |
1271 | |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1272 time_t buddy_getstatustime(gpointer rosterdata, const char *resname) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1273 { |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1274 roster *roster_usr = rosterdata; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1275 res *p_res = get_resource(roster_usr, resname); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1276 if (p_res) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1277 return p_res->status_timestamp; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1278 return 0; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1279 } |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1280 |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1281 gchar buddy_getresourceprio(gpointer rosterdata, const char *resname) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1282 { |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1283 roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1284 res *p_res = get_resource(roster_usr, resname); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1285 if (p_res) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1286 return p_res->prio; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1287 return 0; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1288 } |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1289 |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1290 guint buddy_resource_getevents(gpointer rosterdata, const char *resname) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1291 { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1292 roster *roster_usr = rosterdata; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1293 res *p_res = get_resource(roster_usr, resname); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1294 if (p_res) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1295 return p_res->events; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1296 return ROSTER_EVENT_NONE; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1297 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1298 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1299 void buddy_resource_setevents(gpointer rosterdata, const char *resname, |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1300 guint events) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1301 { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1302 roster *roster_usr = rosterdata; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1303 res *p_res = get_resource(roster_usr, resname); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1304 if (p_res) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1305 p_res->events = events; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1306 } |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1307 |
1600 | 1308 char *buddy_resource_getcaps(gpointer rosterdata, const char *resname) |
1309 { | |
1310 roster *roster_usr = rosterdata; | |
1311 res *p_res = get_resource(roster_usr, resname); | |
1312 if (p_res) | |
1313 return p_res->caps; | |
1314 return NULL; | |
1315 } | |
1316 | |
1317 void buddy_resource_setcaps(gpointer rosterdata, const char *resname, | |
1318 const char *caps) | |
1319 { | |
1320 roster *roster_usr = rosterdata; | |
1321 res *p_res = get_resource(roster_usr, resname); | |
1322 if (p_res) { | |
1323 g_free(p_res->caps); | |
1324 p_res->caps = g_strdup(caps); | |
1325 } | |
1326 } | |
1327 | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1328 struct jep0022 *buddy_resource_jep22(gpointer rosterdata, const char *resname) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1329 { |
1691 | 1330 #ifdef XEP0022 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1331 roster *roster_usr = rosterdata; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1332 res *p_res = get_resource(roster_usr, resname); |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1333 if (p_res) |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1334 return &p_res->jep22; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1335 #endif |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1336 return NULL; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1337 } |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1338 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1339 struct jep0085 *buddy_resource_jep85(gpointer rosterdata, const char *resname) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1340 { |
1691 | 1341 #ifdef XEP0085 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1342 roster *roster_usr = rosterdata; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1343 res *p_res = get_resource(roster_usr, resname); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1344 if (p_res) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1345 return &p_res->jep85; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1346 #endif |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1347 return NULL; |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1348 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1349 |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1350 struct pgp_data *buddy_resource_pgp(gpointer rosterdata, const char *resname) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1351 { |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1352 #ifdef HAVE_GPGME |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1353 roster *roster_usr = rosterdata; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1354 res *p_res = get_resource(roster_usr, resname); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1355 if (p_res) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1356 return &p_res->pgpdata; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1357 #endif |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1358 return NULL; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1359 } |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1360 |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1361 enum imrole buddy_getrole(gpointer rosterdata, const char *resname) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1362 { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1363 roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1364 res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1365 if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1366 return p_res->role; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1367 return role_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1368 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1369 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1370 enum imaffiliation buddy_getaffil(gpointer rosterdata, const char *resname) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1371 { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1372 roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1373 res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1374 if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1375 return p_res->affil; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1376 return affil_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1377 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1378 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1379 const char *buddy_getrjid(gpointer rosterdata, const char *resname) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1380 { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1381 roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1382 res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1383 if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1384 return p_res->realjid; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1385 return NULL; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1386 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1387 |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1388 // buddy_getresources(roster_data) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1389 // Return a singly-linked-list of resource names |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1390 // Note: the caller should free the list (and data) after use |
501
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1391 // If roster_data is null, the current buddy is selected |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1392 GSList *buddy_getresources(gpointer rosterdata) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1393 { |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1394 roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1395 GSList *reslist = NULL, *lp; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1396 |
501
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1397 if (!roster_usr) { |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1398 if (!current_buddy) return NULL; |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1399 roster_usr = BUDDATA(current_buddy); |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1400 } |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1401 for (lp = roster_usr->resource; lp; lp = g_slist_next(lp)) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1402 reslist = g_slist_append(reslist, g_strdup(((res*)lp->data)->name)); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1403 |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1404 return reslist; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1405 } |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1406 |
792
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1407 // buddy_getresources_locale(roster_data) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1408 // Same as buddy_getresources() but names are converted to user's locale |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1409 // Note: the caller should free the list (and data) after use |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1410 GSList *buddy_getresources_locale(gpointer rosterdata) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1411 { |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1412 GSList *reslist, *lp; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1413 |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1414 reslist = buddy_getresources(rosterdata); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1415 // Convert each item to UI's locale |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1416 for (lp = reslist; lp; lp = g_slist_next(lp)) { |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1417 gchar *oldname = lp->data; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1418 lp->data = from_utf8(oldname); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1419 if (lp->data) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1420 g_free(oldname); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1421 else |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1422 lp->data = oldname; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1423 } |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1424 return reslist; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1425 } |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1426 |
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
649
diff
changeset
|
1427 /* |
539 | 1428 // buddy_isresource(roster_data) |
1429 // Return true if there is at least one resource | |
1430 // (which means, for a room, that it isn't empty) | |
1431 int buddy_isresource(gpointer rosterdata) | |
1432 { | |
1433 roster *roster_usr = rosterdata; | |
1434 if (!roster_usr) | |
1435 return FALSE; | |
1436 if (roster_usr->resource) | |
1437 return TRUE; | |
1438 return FALSE; | |
1439 } | |
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
649
diff
changeset
|
1440 */ |
539 | 1441 |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1442 // buddy_resource_setname(roster_data, oldname, newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1443 // Useful for nickname change in a MUC room |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1444 void buddy_resource_setname(gpointer rosterdata, const char *resname, |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1445 const char *newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1446 { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1447 roster *roster_usr = rosterdata; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1448 res *p_res = get_resource(roster_usr, resname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1449 if (p_res) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1450 if (p_res->name) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1451 g_free((gchar*)p_res->name); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1452 p_res->name = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1453 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1454 if (newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1455 p_res->name = g_strdup(newname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1456 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1457 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1458 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1459 // buddy_del_all_resources() |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1460 // Remove all resources from the specified buddy |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1461 void buddy_del_all_resources(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1462 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1463 roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1464 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1465 while (roster_usr->resource) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1466 res *r = roster_usr->resource->data; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1467 del_resource(roster_usr, r->name); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1468 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1469 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1470 |
119 | 1471 // buddy_setflags() |
1472 // Set one or several flags to value (TRUE/FALSE) | |
1473 void buddy_setflags(gpointer rosterdata, guint flags, guint value) | |
1474 { | |
207 | 1475 roster *roster_usr = rosterdata; |
119 | 1476 if (value) |
207 | 1477 roster_usr->flags |= flags; |
119 | 1478 else |
207 | 1479 roster_usr->flags &= ~flags; |
119 | 1480 } |
1481 | |
72 | 1482 guint buddy_getflags(gpointer rosterdata) |
1483 { | |
207 | 1484 roster *roster_usr = rosterdata; |
1485 return roster_usr->flags; | |
72 | 1486 } |
1487 | |
1802
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
1488 guint buddy_getuiprio(gpointer rosterdata) |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
1489 { |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
1490 roster *roster_usr = rosterdata; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
1491 return roster_usr->ui_prio; |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
1492 } |
b135572fcd26
Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
1493 |
1355 | 1494 // buddy_setonserverflag() |
1495 // Set the on_server flag | |
1496 void buddy_setonserverflag(gpointer rosterdata, guint onserver) | |
1497 { | |
1498 roster *roster_usr = rosterdata; | |
1499 roster_usr->on_server = onserver; | |
1500 } | |
1501 | |
1502 guint buddy_getonserverflag(gpointer rosterdata) | |
1503 { | |
1504 roster *roster_usr = rosterdata; | |
1505 return roster_usr->on_server; | |
1506 } | |
1507 | |
480 | 1508 // buddy_search_jid(jid) |
1509 // Look for a buddy with specified jid. | |
1510 // Search begins at buddylist; if no match is found in the the buddylist, | |
1511 // return NULL; | |
1292
382ec54b584e
Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1205
diff
changeset
|
1512 GList *buddy_search_jid(const char *jid) |
480 | 1513 { |
1514 GList *buddy; | |
1515 roster *roster_usr; | |
1516 | |
1517 if (!buddylist) return NULL; | |
1518 | |
1519 for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) { | |
1520 roster_usr = (roster*)buddy->data; | |
1521 if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid)) | |
1522 return buddy; | |
1523 } | |
1524 return NULL; | |
1525 } | |
1526 | |
265 | 1527 // buddy_search(string) |
1528 // Look for a buddy whose name or jid contains string. | |
1529 // Search begins at current_buddy; if no match is found in the the buddylist, | |
1530 // return NULL; | |
1531 GList *buddy_search(char *string) | |
1532 { | |
1533 GList *buddy = current_buddy; | |
1534 roster *roster_usr; | |
1535 if (!buddylist || !current_buddy) return NULL; | |
1536 for (;;) { | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1537 gchar *jid_locale, *name_locale; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1538 char *found = NULL; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1539 |
265 | 1540 buddy = g_list_next(buddy); |
1541 if (!buddy) | |
1542 buddy = buddylist; | |
1543 | |
1544 roster_usr = (roster*)buddy->data; | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1545 |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1546 jid_locale = from_utf8(roster_usr->jid); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1547 if (jid_locale) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1548 found = strcasestr(jid_locale, string); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1549 g_free(jid_locale); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1550 if (found) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1551 return buddy; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1552 } |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1553 name_locale = from_utf8(roster_usr->name); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1554 if (name_locale) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1555 found = strcasestr(name_locale, string); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1556 g_free(name_locale); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1557 if (found) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1558 return buddy; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1559 } |
265 | 1560 |
1561 if (buddy == current_buddy) | |
1562 return NULL; // Back to the beginning, and no match found | |
1563 } | |
1564 } | |
1565 | |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1566 // foreach_buddy(roster_type, pfunction, param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1567 // Call pfunction(buddy, param) for each buddy from the roster with |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1568 // type matching roster_type. |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1569 void foreach_buddy(guint roster_type, |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1570 void (*pfunc)(gpointer rosterdata, void *param), |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1571 void *param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1572 { |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1573 GSList *sl_roster_elt = groups; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1574 roster *roster_elt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1575 GSList *sl_roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1576 roster *roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1577 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1578 while (sl_roster_elt) { // group list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1579 roster_elt = (roster*) sl_roster_elt->data; |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1580 if (roster_elt->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1581 continue; // Skip special items |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1582 sl_roster_usrelt = roster_elt->list; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1583 while (sl_roster_usrelt) { // user list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1584 roster_usrelt = (roster*) sl_roster_usrelt->data; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1585 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1586 if (roster_usrelt->type & roster_type) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1587 pfunc(roster_usrelt, param); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1588 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1589 sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1590 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1591 sl_roster_elt = g_slist_next(sl_roster_elt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1592 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1593 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1594 |
885
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1595 // foreach_group_member(group, pfunction, param) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1596 // Call pfunction(buddy, param) for each buddy in the specified group. |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1597 void foreach_group_member(gpointer groupdata, |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1598 void (*pfunc)(gpointer rosterdata, void *param), |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1599 void *param) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1600 { |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1601 roster *roster_elt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1602 GSList *sl_roster_usrelt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1603 roster *roster_usrelt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1604 |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1605 roster_elt = groupdata; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1606 |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1607 if (!(roster_elt->type & ROSTER_TYPE_GROUP)) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1608 return; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1609 |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1610 sl_roster_usrelt = roster_elt->list; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1611 while (sl_roster_usrelt) { // user list loop |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1612 roster_usrelt = (roster*) sl_roster_usrelt->data; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1613 |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1614 pfunc(roster_usrelt, param); |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1615 sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1616 } |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1617 } |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1618 |
225 | 1619 // compl_list(type) |
1620 // Returns a list of jid's or groups. (For commands completion) | |
1621 // type: ROSTER_TYPE_USER (jid's) or ROSTER_TYPE_GROUP (group names) | |
1622 // The list should be freed by the caller after use. | |
1623 GSList *compl_list(guint type) | |
1624 { | |
1625 GSList *list = NULL; | |
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1626 GSList *sl_roster_elt = groups; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1627 roster *roster_elt; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1628 GSList *sl_roster_usrelt; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1629 roster *roster_usrelt; |
225 | 1630 |
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1631 while (sl_roster_elt) { // group list loop |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1632 roster_elt = (roster*) sl_roster_elt->data; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1633 |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1634 if (roster_elt->type & ROSTER_TYPE_SPECIAL) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1635 continue; // Skip special items |
225 | 1636 |
1637 if (type == ROSTER_TYPE_GROUP) { // (group names) | |
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1638 if (roster_elt->name && *(roster_elt->name)) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1639 list = g_slist_append(list, from_utf8(roster_elt->name)); |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1640 } else { // ROSTER_TYPE_USER (jid) (or agent, or chatroom...) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1641 sl_roster_usrelt = roster_elt->list; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1642 while (sl_roster_usrelt) { // user list loop |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1643 roster_usrelt = (roster*) sl_roster_usrelt->data; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1644 |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1645 if (roster_usrelt->jid) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1646 list = g_slist_append(list, from_utf8(roster_usrelt->jid)); |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1647 |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1648 sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
225 | 1649 } |
1650 } | |
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1651 sl_roster_elt = g_slist_next(sl_roster_elt); |
225 | 1652 } |
1653 | |
1654 return list; | |
1655 } | |
1656 | |
236 | 1657 // unread_msg(rosterdata) |
1658 // Return the next buddy with an unread message. If the parameter is NULL, | |
1659 // return the first buddy with an unread message. | |
1660 gpointer unread_msg(gpointer rosterdata) | |
1661 { | |
1662 GSList *unread, *next_unread; | |
1663 | |
564 | 1664 if (!unread_list) |
1665 return NULL; | |
1666 | |
236 | 1667 // First unread message |
564 | 1668 if (!rosterdata) |
1669 return unread_list->data; | |
236 | 1670 |
1671 unread = g_slist_find(unread_list, rosterdata); | |
564 | 1672 if (!unread) |
1673 return unread_list->data; | |
236 | 1674 |
1675 next_unread = g_slist_next(unread); | |
564 | 1676 if (next_unread) |
1677 return next_unread->data; | |
236 | 1678 return unread_list->data; |
1679 } | |
576 | 1680 |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1681 |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1682 /* ### "unread_jids" functions ### |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1683 * |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1684 * The unread_jids hash table is used to keep track of the buddies with |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1685 * unread messages when a disconnection occurs. |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1686 * When removing a buddy with an unread message from the roster, the |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1687 * jid should be added to the unread_jids table. When adding a buddy to |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1688 * the roster, we check if (s)he had a pending unread message. |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1689 */ |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1690 |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1691 // unread_jid_add(jid) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1692 // Add jid to the unread_jids hash table |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1693 void unread_jid_add(const char *jid) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1694 { |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1695 if (!unread_jids) { |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1696 // Initialize unread_jids hash table |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1697 unread_jids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1698 } |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1699 // The 2nd unread_jids is an arbitrary non-null pointer: |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1700 g_hash_table_insert(unread_jids, g_strdup(jid), unread_jids); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1701 } |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1702 |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1703 // unread_jid_del(jid) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1704 // Return TRUE if jid is found in the table (and remove it), FALSE if not |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1705 static int unread_jid_del(const char *jid) |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1706 { |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1707 if (!unread_jids) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1708 return FALSE; |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1709 return g_hash_table_remove(unread_jids, jid); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1710 } |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1711 |
1438
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1712 // Helper function for unread_jid_get_list() |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1713 static void add_to_unreadjids(gpointer key, gpointer value, gpointer udata) |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1714 { |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1715 GList **listp = udata; |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1716 *listp = g_list_append(*listp, key); |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1717 } |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1718 |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1719 // unread_jid_get_list() |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1720 // Return the JID list. |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1721 // The content of the list should not be modified or freed. |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1722 // The caller should call g_list_free() after use. |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1723 GList *unread_jid_get_list(void) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1724 { |
1438
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1725 GList *list = NULL; |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1726 |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1727 if (!unread_jids) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1728 return NULL; |
1438
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1729 |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1730 // g_hash_table_get_keys() is only in glib >= 2.14 |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1731 //return g_hash_table_get_keys(unread_jids); |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1732 |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1733 g_hash_table_foreach(unread_jids, add_to_unreadjids, &list); |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1734 return list; |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1735 } |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1736 |
1811 | 1737 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */ |