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