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