annotate mcabber/mcabber/roster.c @ 2074:e04b6dfbb054

Some whitespace cleanup
author Mikael Berthe <mikael@lilotux.net>
date Sun, 29 Sep 2013 11:07:06 +0200
parents 8dc418af3e72
children db6ca1e1e082
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1 /*
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
2 * roster.c -- Local roster implementation
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
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
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
5 *
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
9 * your option) any later version.
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
10 *
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
14 * General Public License for more details.
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
15 *
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
19 * USA
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
20 */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
21
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
22 #include <string.h>
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
23
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
24 #include "roster.h"
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
25 #include "utils.h"
1444
3bf11085c6a5 New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents: 1438
diff changeset
26 #include "hooks.h"
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
27
1437
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1431
diff changeset
28 extern void hlog_save_state(void);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
29
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
30 char *strrole[] = { /* Should match enum in roster.h */
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
31 "none",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
32 "moderator",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
33 "participant",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
34 "visitor"
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
35 };
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
36
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
37 char *straffil[] = { /* Should match enum in roster.h */
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
38 "none",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
39 "owner",
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
40 "admin",
1331
a97701d8d735 Fix typo in the straffil structure (reported by gst)
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
41 "member",
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
42 "outcast"
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
43 };
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
44
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
45 char *strprintstatus[] = { /* Should match enum in roster.h */
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
46 "default",
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
47 "none",
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
48 "in_and_out",
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
49 "all"
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
50 };
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
51
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
52 char *strautowhois[] = { /* Should match enum in roster.h */
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
53 "default",
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
54 "off",
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
55 "on",
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
56 };
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
57
1979
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
58 char *strflagjoins[] = { /* Should match enum in roster.h */
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
59 "default",
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
60 "none",
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
61 "joins",
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
62 "all"
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
63 };
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
64
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
65 /* Resource structure */
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
66
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
67 typedef struct {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
68 gchar *name;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
69 gchar prio;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
70 enum imstatus status;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
71 gchar *status_msg;
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
72 time_t status_timestamp;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
73 enum imrole role;
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
74 enum imaffiliation affil;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
75 gchar *realjid; /* for chatrooms, if buddy's real jid is known */
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
76 guint events;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents: 1599
diff changeset
77 char *caps;
1691
b2e0083891cc Replace JEP with XEP
Mikael Berthe <mikael@lilotux.net>
parents: 1668
diff changeset
78 #ifdef XEP0022
1866
e45d13074721 s/jep/xep/
Mikael Berthe <mikael@lilotux.net>
parents: 1839
diff changeset
79 struct xep0022 xep22;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
80 #endif
1691
b2e0083891cc Replace JEP with XEP
Mikael Berthe <mikael@lilotux.net>
parents: 1668
diff changeset
81 #ifdef XEP0085
1866
e45d13074721 s/jep/xep/
Mikael Berthe <mikael@lilotux.net>
parents: 1839
diff changeset
82 struct xep0085 xep85;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
83 #endif
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
84 #ifdef HAVE_GPGME
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
85 struct pgp_data pgpdata;
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
86 #endif
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
87 } res;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
88
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
89 /* This is a private structure type for the roster */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
90
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
91 typedef struct {
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
92 gchar *name;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
93 gchar *jid;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
94 guint type;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
95 enum subscr subscription;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
96 GSList *resource;
2013
8dc418af3e72 Allow to select to which buddy resource messages go. Closes issue #55
Hermitifier
parents: 1996
diff changeset
97 res *active_resource;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
98
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
99 /* For groupchats */
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
100 gchar *nickname;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
101 gchar *topic;
952
527d6f234924 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
102 guint inside_room;
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
103 guint print_status;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
104 guint auto_whois;
1979
6febc7d1f760 Add /room setopt flag_joins (Hermitifier)
Mikael Berthe <mikael@lilotux.net>
parents: 1978
diff changeset
105 guint flag_joins;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
106
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
107 /* on_server is TRUE if the item is present on the server roster */
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
108 guint on_server;
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
109
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
110 /* 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
111 gchar *offline_status_message;
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
112
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
113 /* Flag used for the UI */
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
114 guint flags;
1802
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
115 guint ui_prio; // Boolean, positive if "attention" is requested
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
116
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
117 // list: user -> points to his group; group -> points to its users list
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
118 GSList *list;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
119 } roster;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
120
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
121
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
122 /* ### Variables ### */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
123
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
124 static guchar display_filter;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
125 static GSList *groups;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
126 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
127 static GHashTable *unread_jids;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
128 GList *buddylist;
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
129 GList *current_buddy;
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
130 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
131 GList *last_activity_buddy;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
132
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
133 static roster roster_special;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
134
1437
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1431
diff changeset
135 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
136
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
137 #define DFILTER_ALL 63
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
138 #define DFILTER_ONLINE 62
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
139
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
140
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
141 /* ### Initialization ### */
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
142
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
143 void roster_init(void)
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
144 {
889
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
145 roster_special.name = SPECIAL_BUFFER_STATUS_ID;
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
146 roster_special.type = ROSTER_TYPE_SPECIAL;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
147 }
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
148
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
149 /* ### Resources functions ### */
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
150
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
151 static inline void free_resource_data(res *p_res)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
152 {
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
153 if (!p_res)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
154 return;
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
155 g_free((gchar*)p_res->status_msg);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
156 g_free((gchar*)p_res->name);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
157 g_free((gchar*)p_res->realjid);
1691
b2e0083891cc Replace JEP with XEP
Mikael Berthe <mikael@lilotux.net>
parents: 1668
diff changeset
158 #ifdef XEP0022
1866
e45d13074721 s/jep/xep/
Mikael Berthe <mikael@lilotux.net>
parents: 1839
diff changeset
159 g_free(p_res->xep22.last_msgid_sent);
e45d13074721 s/jep/xep/
Mikael Berthe <mikael@lilotux.net>
parents: 1839
diff changeset
160 g_free(p_res->xep22.last_msgid_rcvd);
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
161 #endif
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
162 #ifdef HAVE_GPGME
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
163 g_free(p_res->pgpdata.sign_keyid);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
164 #endif
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents: 1599
diff changeset
165 g_free(p_res->caps);
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
166 g_free(p_res);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
167 }
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
168
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
169 static void free_all_resources(GSList **reslist)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
170 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
171 GSList *lip;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
172
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
173 for (lip = *reslist; lip ; lip = g_slist_next(lip))
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
174 free_resource_data((res*)lip->data);
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
175 // 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
176 g_slist_free(*reslist);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
177 *reslist = NULL;
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
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
180 // Resources are sorted in ascending order
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
181 static gint resource_compare_prio(res *a, res *b) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
182 if (a->prio < b->prio) return -1;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
183 else return 1;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
184 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
185
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
186 // get_resource(rost, resname)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
187 // 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
188 // - if rost has no resources, return NULL
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
189 // - 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
190 // - 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
191 // 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
192 // (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
193 //
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
194 static res *get_resource(roster *rost, const char *resname)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
195 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
196 GSList *p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
197 res *r = NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
198
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
199 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
200 r = p->data;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
201 if (resname && !strcmp(r->name, resname))
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
202 return r;
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
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
205 // 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
206 // 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
207 if (!resname) return r;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
208 return NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
209 }
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 // get_or_add_resource(rost, resname, priority)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
212 // - 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
213 // on this resource
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
214 // - 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
215 // new resource
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
216 static res *get_or_add_resource(roster *rost, const char *resname, gchar prio)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
217 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
218 GSList *p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
219 res *nres;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
220
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
221 if (!resname) return NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
222
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
223 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
224 res *r = p->data;
1092
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
225 if (!strcmp(r->name, resname)) {
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
226 if (prio != r->prio) {
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
227 r->prio = prio;
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
228 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
229 (GCompareFunc)&resource_compare_prio);
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
230 }
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
231 return r;
1092
1ef7572c3096 Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents: 1088
diff changeset
232 }
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
233 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
234
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
235 // Resource not found
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
236 nres = g_new0(res, 1);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
237 nres->name = g_strdup(resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
238 nres->prio = prio;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
239 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
240 (GCompareFunc)&resource_compare_prio);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
241 return nres;
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
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
244 static void del_resource(roster *rost, const char *resname)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
245 {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
246 GSList *p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
247 GSList *p_res_elt = NULL;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
248 res *p_res;
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 if (!resname) return;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
251
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
252 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
253 res *r = p->data;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
254 if (!strcmp(r->name, resname))
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
255 p_res_elt = p;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
256 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
257
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
258 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
259
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
260 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
261
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
262 // 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
263 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
264 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
265 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
266 p_res->status_msg = NULL;
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
267 }
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
268
2013
8dc418af3e72 Allow to select to which buddy resource messages go. Closes issue #55
Hermitifier
parents: 1996
diff changeset
269 if (rost->active_resource == p_res)
8dc418af3e72 Allow to select to which buddy resource messages go. Closes issue #55
Hermitifier
parents: 1996
diff changeset
270 rost->active_resource = NULL;
8dc418af3e72 Allow to select to which buddy resource messages go. Closes issue #55
Hermitifier
parents: 1996
diff changeset
271
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
272 // Free allocations and delete resource node
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
273 free_resource_data(p_res);
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
274 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
275 return;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
276 }
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
277
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
278
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
279 /* ### Roster functions ### */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
280
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
281 static inline void free_roster_user_data(roster *roster_usr)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
282 {
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
283 if (!roster_usr)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
284 return;
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
285 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
286 //g_free((gchar*)roster_usr->active_resource);
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
287 g_free((gchar*)roster_usr->name);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
288 g_free((gchar*)roster_usr->nickname);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
289 g_free((gchar*)roster_usr->topic);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
290 g_free((gchar*)roster_usr->offline_status_message);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
291 free_all_resources(&roster_usr->resource);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
292 g_free(roster_usr);
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
293 }
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
294
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
295 // Comparison function used to search in the roster (compares jids and types)
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 331
diff changeset
296 static gint roster_compare_jid_type(roster *a, roster *b) {
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
297 if (! (a->type & b->type))
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
298 return -1; // arbitrary (but should be != 0, of course)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
299 return strcasecmp(a->jid, b->jid);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
300 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
301
670
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
302 // Comparison function used to search in the roster (compares names and types)
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
303 static gint roster_compare_name_type(roster *a, roster *b) {
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
304 if (! (a->type & b->type))
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
305 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
306 return strcmp(a->name, b->name);
670
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
307 }
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
308
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
309 // Comparison function used to sort the roster (by name)
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 331
diff changeset
310 static gint roster_compare_name(roster *a, roster *b) {
783
25022410f80f Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
311 return strcmp(a->name, b->name);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
312 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
313
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
314 // Finds a roster element (user, group, agent...), by jid or name
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
315 // If roster_type is 0, returns match of any type.
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
316 // Returns the roster GSList element, or NULL if jid/name not found
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
317 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
318 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
319 GSList *sl_roster_elt = groups;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
320 GSList *resource;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
321 roster sample;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
322 GCompareFunc comp;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
323
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 166
diff changeset
324 if (!jidname) return NULL;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
325
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
326 if (!roster_type)
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
327 roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM |
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
328 ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP;
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
329
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
330 sample.type = roster_type;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
331 if (type == jidsearch) {
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
332 sample.jid = (gchar*)jidname;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
333 comp = (GCompareFunc)&roster_compare_jid_type;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
334 } else if (type == namesearch) {
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
335 sample.name = (gchar*)jidname;
670
2cd0805515a4 Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents: 669
diff changeset
336 comp = (GCompareFunc)&roster_compare_name_type;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
337 } else
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 863
diff changeset
338 return NULL; // Should not happen...
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
339
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
340 while (sl_roster_elt) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
341 roster *roster_elt = (roster*)sl_roster_elt->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
342 if (roster_type & ROSTER_TYPE_GROUP) {
783
25022410f80f Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
343 if ((type == namesearch) && !strcmp(jidname, roster_elt->name))
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
344 return sl_roster_elt;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
345 }
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
346 resource = g_slist_find_custom(roster_elt->list, &sample, comp);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
347 if (resource) return resource;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
348 sl_roster_elt = g_slist_next(sl_roster_elt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
349 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
350 return NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
351 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
352
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
353 // Returns pointer to new group, or existing group with that name
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
354 GSList *roster_add_group(const char *name)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
355 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
356 roster *roster_grp;
669
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
357 GSList *p_group;
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
358
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
359 // #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
360 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
361 if (!p_group) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
362 // #2 Create the group node
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
363 roster_grp = g_new0(roster, 1);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
364 roster_grp->name = g_strdup(name);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
365 roster_grp->type = ROSTER_TYPE_GROUP;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
366 // #3 Insert (sorted)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
367 groups = g_slist_insert_sorted(groups, roster_grp,
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
368 (GCompareFunc)&roster_compare_name);
669
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
369 p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
370 }
669
2b87065270f3 roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents: 662
diff changeset
371 return p_group;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
372 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
373
1803
7d3060070d10 Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents: 1802
diff changeset
374 // Comparison function used to sort the unread list by ui (attn) priority
7d3060070d10 Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents: 1802
diff changeset
375 static gint _roster_compare_uiprio(roster *a, roster *b) {
7d3060070d10 Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents: 1802
diff changeset
376 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
377 }
7d3060070d10 Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents: 1802
diff changeset
378
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
379 // Returns a pointer to the new user, or existing user with that name
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
380 // Note: if onserver is -1, the flag won't be changed.
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
381 GSList *roster_add_user(const char *jid, const char *name, const char *group,
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
382 guint type, enum subscr esub, gint onserver)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
383 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
384 roster *roster_usr;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
385 roster *my_group;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
386 GSList *slist;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
387
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
388 if ((type != ROSTER_TYPE_USER) &&
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
389 (type != ROSTER_TYPE_ROOM) &&
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
390 (type != ROSTER_TYPE_AGENT)) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
391 // XXX Error message?
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
392 return NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
393 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
394
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
395 // Let's be arbitrary: default group has an empty name ("").
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
396 if (!group) group = "";
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
397
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
398 // #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
399 slist = roster_find(jid, jidsearch, 0);
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
400 if (slist) {
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
401 char *oldgroupname;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
402 // That's an update
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
403 roster_usr = slist->data;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
404 roster_usr->subscription = esub;
1366
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
405 if (onserver >= 0)
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
406 buddy_setonserverflag(slist->data, onserver);
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
407 if (name)
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
408 buddy_setname(slist->data, (char*)name);
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
409 // Let's check if the group name has changed
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
410 oldgroupname = ((roster*)((GSList*)roster_usr->list)->data)->name;
1366
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
411 if (group && strcmp(oldgroupname, group)) {
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
412 buddy_setgroup(slist->data, (char*)group);
1366
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
413 // 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
414 // use slist anymore.
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
415 return roster_find(jid, jidsearch, 0);
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
416 }
607
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
417 return slist;
cf722bff6579 Improve IQ management
Mikael Berthe <mikael@lilotux.net>
parents: 603
diff changeset
418 }
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
419 // #2 add group if necessary
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
420 slist = roster_add_group(group);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
421 if (!slist) return NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
422 my_group = (roster*)slist->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
423 // #3 Create user node
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
424 roster_usr = g_new0(roster, 1);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
425 roster_usr->jid = g_strdup(jid);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
426 if (name) {
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
427 roster_usr->name = g_strdup(name);
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
428 } else {
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
429 gchar *p, *str = g_strdup(jid);
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 974
diff changeset
430 p = strchr(str, JID_RESOURCE_SEPARATOR);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
431 if (p) *p = '\0';
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
432 roster_usr->name = g_strdup(str);
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
433 g_free(str);
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
434 }
662
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
435 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
436 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
437 // 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
438 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
439 (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
440 }
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
441 roster_usr->type = type;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
442 roster_usr->subscription = esub;
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
443 roster_usr->list = slist; // (my_group SList element)
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
444 if (onserver == 1)
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
445 roster_usr->on_server = TRUE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
446 // #4 Insert node (sorted)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
447 my_group->list = g_slist_insert_sorted(my_group->list, roster_usr,
564
95d6297a9654 Cosmetic changes
Mikael Berthe <mikael@lilotux.net>
parents: 563
diff changeset
448 (GCompareFunc)&roster_compare_name);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
449 return roster_find(jid, jidsearch, type);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
450 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
451
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
452 // Removes user (jid) from roster, frees allocated memory
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
453 void roster_del_user(const char *jid)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
454 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
455 GSList *sl_user, *sl_group;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
456 GSList **sl_group_listptr;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
457 roster *roster_usr;
246
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
458 GSList *node;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
459
1431
486809ccffc0 Let /del remove a MUC entry from the roster
Mikael Berthe <mikael@lilotux.net>
parents: 1414
diff changeset
460 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
461 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM);
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
462 if (sl_user == NULL)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
463 return;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
464 roster_usr = (roster*)sl_user->data;
246
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
465
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
466 // Remove (if present) from unread messages list
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
467 node = g_slist_find(unread_list, roster_usr);
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
468 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
469 // 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
470 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
471 unread_jid_add(roster_usr->jid);
246
57f9005b8844 [/trunk] Changeset 259 by mikael
mikael
parents: 236
diff changeset
472
1389
cefda9174d62 Fix an old bug in roster_del_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
473 sl_group = roster_usr->list;
cefda9174d62 Fix an old bug in roster_del_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
474
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
475 // 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
476 free_roster_user_data(roster_usr);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
477
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
478 // That's a little complex, we need to dereference twice
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
479 sl_group_listptr = &((roster*)(sl_group->data))->list;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
480 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
481
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
482 // We need to rebuild the list
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
483 if (current_buddy)
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
484 buddylist_build();
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
485 // TODO What we could do, too, is to check if the deleted node is
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
486 // current_buddy, in which case we could move current_buddy to the
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
487 // previous (or next) node.
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
488 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
489
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
490 // Free all roster data and call buddylist_build() to free the buddylist.
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
491 void roster_free(void)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
492 {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
493 GSList *sl_grp = groups;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
494
301
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
495 // Free unread_list
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
496 if (unread_list) {
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
497 g_slist_free(unread_list);
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
498 unread_list = NULL;
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
499 }
efcbd3c1ad15 Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents: 265
diff changeset
500
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
501 // Walk through groups
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
502 while (sl_grp) {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
503 roster *roster_grp = (roster*)sl_grp->data;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
504 GSList *sl_usr = roster_grp->list;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
505 // Walk through this group users
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
506 while (sl_usr) {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
507 roster *roster_usr = (roster*)sl_usr->data;
662
4111ff4cdd15 Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 652
diff changeset
508 // 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
509 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
510 unread_jid_add(roster_usr->jid);
1063
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
511 // Free roster_usr data (jid, name, status message...)
4e62941df777 roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
512 free_roster_user_data(roster_usr);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
513 sl_usr = g_slist_next(sl_usr);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
514 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
515 // Free group's users list
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
516 if (roster_grp->list)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
517 g_slist_free(roster_grp->list);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
518 // Free group's name and jid
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
519 g_free((gchar*)roster_grp->jid);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
520 g_free((gchar*)roster_grp->name);
214
9484ba81ec53 [/trunk] Changeset 226 by mikael
mikael
parents: 212
diff changeset
521 g_free(roster_grp);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
522 sl_grp = g_slist_next(sl_grp);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
523 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
524 // Free groups list
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
525 if (groups) {
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
526 g_slist_free(groups);
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
527 groups = NULL;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
528 // Update (i.e. free) buddylist
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
529 if (buddylist)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
530 buddylist_build();
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
531 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
532 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 148
diff changeset
533
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
534 // roster_setstatus()
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
535 // 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
536 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
537 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
538 time_t status_time,
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
539 enum imrole role, enum imaffiliation affil,
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
540 const char *realjid)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
541 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
542 GSList *sl_user;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
543 roster *roster_usr;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
544 res *p_res;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
545
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
546 sl_user = roster_find(jid, jidsearch,
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
547 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
92
c6270994fb6e [/trunk] Changeset 106 by mikael
mikael
parents: 90
diff changeset
548 // If we can't find it, we add it
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
549 if (sl_user == NULL)
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
550 sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER,
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
551 sub_none, -1);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
552
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
553 // 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
554 if (!resname) return;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
555
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
556 roster_usr = (roster*)sl_user->data;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
557
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
558 // New or updated resource
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
559 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
560 p_res->status = bstat;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
561 if (p_res->status_msg) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
562 g_free((gchar*)p_res->status_msg);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
563 p_res->status_msg = NULL;
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
564 }
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 214
diff changeset
565 if (status_msg)
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
566 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
567 if (!status_time)
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
568 time(&status_time);
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 621
diff changeset
569 p_res->status_timestamp = status_time;
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
570
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
571 p_res->role = role;
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 564
diff changeset
572 p_res->affil = affil;
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
573
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
574 if (p_res->realjid) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
575 g_free((gchar*)p_res->realjid);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
576 p_res->realjid = NULL;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
577 }
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
578 if (realjid)
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
579 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
580
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
581 // 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
582 if (bstat == offline) {
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
583 del_resource(roster_usr, resname);
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
584 return;
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 819
diff changeset
585 }
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
586 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
587
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
588 // roster_setflags()
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
589 // Set one or several flags to value (TRUE/FALSE)
80
7fb661f19a77 [/trunk] Changeset 94 by mikael
mikael
parents: 78
diff changeset
590 void roster_setflags(const char *jid, guint flags, guint value)
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
591 {
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
592 GSList *sl_user;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
593 roster *roster_usr;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
594
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
595 sl_user = roster_find(jid, jidsearch,
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
596 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
597 if (sl_user == NULL)
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
598 return;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
599
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
600 roster_usr = (roster*)sl_user->data;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
601 if (value)
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
602 roster_usr->flags |= flags;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
603 else
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
604 roster_usr->flags &= ~flags;
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
605 }
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
606
1839
f0a07658e009 Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents: 1812
diff changeset
607 // roster_unread_check()
f0a07658e009 Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents: 1812
diff changeset
608 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
609 {
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
610 guint unread_count = 0;
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
611 gpointer unread_ptr, first_unread;
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
612 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
613 guint attention_count = 0;
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
614
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
615 unread_ptr = first_unread = unread_msg(NULL);
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
616 if (first_unread) {
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
617 do {
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
618 guint type = buddy_gettype(unread_ptr);
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
619 unread_count++;
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
620
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
621 if (type & ROSTER_TYPE_ROOM) {
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
622 muc_unread++;
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
623 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
624 muc_attention++;
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
625 } else {
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
626 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
627 attention_count++;
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
628 }
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
629 unread_ptr = unread_msg(unread_ptr);
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
630 } 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
631 }
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
632
1812
5dbb3ebbc466 Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
633 hk_unread_list_change(unread_count, attention_count,
5dbb3ebbc466 Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
634 muc_unread, muc_attention);
1809
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
635 }
eef8c9fff727 Hopefully fix issue with hook-unread-list-change
Mikael Berthe <mikael@lilotux.net>
parents: 1806
diff changeset
636
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
637 // roster_msg_setflag()
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
638 // Set the ROSTER_FLAG_MSG to the given value for the given jid.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
639 // It will update the buddy's group message flag.
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
640 // 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
641 void roster_msg_setflag(const char *jid, guint special, guint value)
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
642 {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
643 GSList *sl_user;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
644 roster *roster_usr, *roster_grp;
860
a8fadbd97858 Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
645 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
646 guint unread_list_modified = FALSE;
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
647
889
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
648 if (special) {
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
649 //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
650 //if (!sl_user) return;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
651 //roster_usr = (roster*)sl_user->data;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
652 roster_usr = &roster_special;
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
653 if (value) {
1581
b29ac1f171ea Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents: 1504
diff changeset
654 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
655 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
656 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
657 // 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
658 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
659 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
660 (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
661 } else {
1581
b29ac1f171ea Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents: 1504
diff changeset
662 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
663 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
664 roster_usr->flags &= ~ROSTER_FLAG_MSG;
1802
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
665 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
666 if (unread_list) {
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
667 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
668 if (node)
b29ac1f171ea Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents: 1504
diff changeset
669 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
670 }
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
671 }
1581
b29ac1f171ea Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents: 1504
diff changeset
672 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
673 }
ae93e69aaaaf Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
674
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
675 sl_user = roster_find(jid, jidsearch,
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
676 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
677 // 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
678 if (sl_user == NULL) {
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1331
diff changeset
679 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
680 new_roster_item = TRUE;
678
e175f5d96f04 Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents: 670
diff changeset
681 }
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
682
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
683 roster_usr = (roster*)sl_user->data;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
684 roster_grp = (roster*)roster_usr->list->data;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
685 if (value) {
1437
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1431
diff changeset
686 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
687 unread_list_modified = TRUE;
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
688 // Message flag is TRUE. This is easy, we just have to set both flags
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
689 // to TRUE...
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
690 roster_usr->flags |= ROSTER_FLAG_MSG;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
691 roster_grp->flags |= ROSTER_FLAG_MSG; // group
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
692 // Append the roster_usr to unread_list, but avoid duplicates
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
693 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
694 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
695 (GCompareFunc)&_roster_compare_uiprio);
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
696 } else {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
697 // Message flag is FALSE.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
698 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
699 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
700 unread_list_modified = TRUE;
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
701 roster_usr->flags &= ~ROSTER_FLAG_MSG;
1802
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
702 roster_usr->ui_prio = 0;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
703 if (unread_list) {
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
704 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
705 if (node)
b29ac1f171ea Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents: 1504
diff changeset
706 unread_list = g_slist_delete_link(unread_list, node);
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 225
diff changeset
707 }
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
708 // For the group value we need to watch all buddies in this group;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
709 // if one is flagged, then the group will be flagged.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
710 // I will re-use sl_user and roster_usr here, as they aren't used
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
711 // anymore.
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
712 sl_user = roster_grp->list;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
713 while (sl_user) {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
714 roster_usr = (roster*)sl_user->data;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
715 if (roster_usr->flags & ROSTER_FLAG_MSG) {
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
716 msg = TRUE;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
717 break;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
718 }
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
719 sl_user = g_slist_next(sl_user);
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
720 }
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
721 if (!msg)
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
722 roster_grp->flags &= ~ROSTER_FLAG_MSG;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
723 else
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
724 roster_grp->flags |= ROSTER_FLAG_MSG;
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
725 // Actually the "else" part is useless, because the group
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
726 // ROSTER_FLAG_MSG should already be set...
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
727 }
860
a8fadbd97858 Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
728
1010
54405d09b15a Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
729 if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr)))
860
a8fadbd97858 Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
730 buddylist_build();
1437
071c8170b7de Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents: 1431
diff changeset
731
1581
b29ac1f171ea Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents: 1504
diff changeset
732 roster_msg_setflag_return:
1444
3bf11085c6a5 New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents: 1438
diff changeset
733 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
734 hlog_save_state();
1839
f0a07658e009 Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents: 1812
diff changeset
735 roster_unread_check();
1444
3bf11085c6a5 New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents: 1438
diff changeset
736 }
148
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
737 }
c3624b2a7059 [/trunk] Changeset 160 by mikael
mikael
parents: 147
diff changeset
738
1802
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
739 // roster_setuiprio(jid, special, prio_value, action)
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
740 // 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
741 // 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
742 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
743 enum setuiprio_ops action)
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
744 {
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
745 guint oldval, newval;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
746 roster *roster_usr;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
747
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
748 if (special) {
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
749 roster_usr = &roster_special;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
750 } else {
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
751 GSList *sl_user = roster_find(jid, jidsearch,
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
752 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
753 if (!sl_user)
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
754 return;
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 roster_usr = (roster*)sl_user->data;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
757 }
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
758 oldval = roster_usr->ui_prio;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
759
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
760 if (action == prio_max)
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
761 newval = MAX(oldval, value);
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
762 else if (action == prio_inc)
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
763 newval = oldval + value;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
764 else // prio_set
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
765 newval = value;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
766
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
767 roster_usr->ui_prio = newval;
1803
7d3060070d10 Sort roster unread list by UI (attention) priority
Mikael Berthe <mikael@lilotux.net>
parents: 1802
diff changeset
768 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
769 (GCompareFunc)&_roster_compare_uiprio);
1839
f0a07658e009 Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents: 1812
diff changeset
770 roster_unread_check();
1802
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
771 }
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
772
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
773 guint roster_getuiprio(const char *jid, guint special)
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
774 {
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
775 roster *roster_usr;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
776 GSList *sl_user;
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 if (special) {
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
779 roster_usr = &roster_special;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
780 return roster_usr->ui_prio;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
781 }
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 sl_user = roster_find(jid, jidsearch,
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
784 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
785 if (!sl_user)
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
786 return 0;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
787 roster_usr = (roster*)sl_user->data;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
788 return roster_usr->ui_prio;
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
789 }
b135572fcd26 Add urgent flag per screen buffer
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
790
510
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
791 const char *roster_getname(const char *jid)
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
792 {
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
793 GSList *sl_user;
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
794 roster *roster_usr;
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
795
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
796 sl_user = roster_find(jid, jidsearch,
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
797 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
798 if (sl_user == NULL)
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
799 return NULL; // Not in the roster...
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
800
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
801 roster_usr = (roster*)sl_user->data;
6c3cd3aa4a91 New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents: 509
diff changeset
802 return roster_usr->name;
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
863
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
805 const char *roster_getnickname(const char *jid)
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
806 {
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
807 GSList *sl_user;
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
808 roster *roster_usr;
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
809
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
810 sl_user = roster_find(jid, jidsearch,
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
811 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
812 if (sl_user == NULL)
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
813 return NULL; // Not in the roster...
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
814
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
815 roster_usr = (roster*)sl_user->data;
4f1a93faffea Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents: 860
diff changeset
816 return roster_usr->nickname;
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
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
819 void roster_settype(const char *jid, guint type)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
820 {
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
821 GSList *sl_user;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
822 roster *roster_usr;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
823
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
824 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
825 return;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
826
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
827 roster_usr = (roster*)sl_user->data;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
828 roster_usr->type = type;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
829 }
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
830
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
831 enum imstatus roster_getstatus(const char *jid, const char *resname)
90
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
832 {
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
833 GSList *sl_user;
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
834 roster *roster_usr;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
835 res *p_res;
90
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
836
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
837 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
838 if (sl_user == NULL)
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
839 return offline; // Not in the roster, anyway...
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
840
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
841 roster_usr = (roster*)sl_user->data;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
842 p_res = get_resource(roster_usr, resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
843 if (p_res)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
844 return p_res->status;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
845 return offline;
90
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
846 }
ac48ace7ee19 [/trunk] Changeset 104 by mikael
mikael
parents: 89
diff changeset
847
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
848 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
849 {
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
850 GSList *sl_user;
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
851 roster *roster_usr;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
852 res *p_res;
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
853
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
854 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
855 if (sl_user == NULL)
425
03f1e37759a6 roster_getstatusmsg() should return a pointer
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
856 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
857
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
858 roster_usr = (roster*)sl_user->data;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
859 p_res = get_resource(roster_usr, resname);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
860 if (p_res)
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 425
diff changeset
861 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
862 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
863 }
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 301
diff changeset
864
1727
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
865 char roster_getprio(const char *jid, const char *resname)
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
866 {
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
867 GSList *sl_user;
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
868 roster *roster_usr;
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
869 res *p_res;
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
870
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
871 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
872 if (sl_user == NULL)
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
873 return offline; // Not in the roster, anyway...
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
874
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
875 roster_usr = (roster*)sl_user->data;
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
876 p_res = get_resource(roster_usr, resname);
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
877 if (p_res)
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
878 return p_res->prio;
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
879 return 0;
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
880 }
15e6b21df606 Add helper function roster_getprio()
Mikael Berthe <mikael@lilotux.net>
parents: 1691
diff changeset
881
89
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
882 guint roster_gettype(const char *jid)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
883 {
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
884 GSList *sl_user;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
885 roster *roster_usr;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
886
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
887 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
888 return 0;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
889
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
890 roster_usr = (roster*)sl_user->data;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
891 return roster_usr->type;
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
892 }
d39f15683c34 [/trunk] Changeset 103 by mikael
mikael
parents: 81
diff changeset
893
819
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
894 guint roster_getsubscription(const char *jid)
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
895 {
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
896 GSList *sl_user;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
897 roster *roster_usr;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
898
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
899 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
900 return 0;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
901
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
902 roster_usr = (roster*)sl_user->data;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
903 return roster_usr->subscription;
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
904 }
c2d7d9dd4193 New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents: 792
diff changeset
905
610
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
906 // roster_unsubscribed()
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
907 // 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
908 // 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
909 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
910 {
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
911 GSList *sl_user;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
912 roster *roster_usr;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
913
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
914 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
915 if (sl_user == NULL)
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
916 return;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
917
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
918 roster_usr = (roster*)sl_user->data;
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
919 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
920 }
0e8247cf2bd1 Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents: 607
diff changeset
921
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
922
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
923 /* ### BuddyList functions ### */
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
924
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
925 // buddylist_set_hide_offline_buddies(hide)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
926 // "hide" values: 1=hide 0=show_all -1=invert
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
927 void buddylist_set_hide_offline_buddies(int hide)
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
928 {
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
929 if (hide < 0) { // NEG (invert)
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
930 if (display_filter == DFILTER_ALL)
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
931 display_filter = DFILTER_ONLINE;
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
932 else
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
933 display_filter = DFILTER_ALL;
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
934 } else if (hide == 0) { // FALSE (don't hide -- andfo_)
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
935 display_filter = DFILTER_ALL;
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
936 } else { // TRUE (hide -- andfo)
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
937 display_filter = DFILTER_ONLINE;
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
938 }
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
939 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
940
1413
f89844a0448a Remove useless inlines
Mikael Berthe <mikael@lilotux.net>
parents: 1389
diff changeset
941 int buddylist_isset_filter(void)
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
942 {
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
943 return (display_filter != DFILTER_ALL);
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
944 }
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
945
1504
9fafea381eb8 Show the number of unfiltered contacts in folded groups
franky
parents: 1476
diff changeset
946 int buddylist_is_status_filtered(enum imstatus status)
9fafea381eb8 Show the number of unfiltered contacts in folded groups
franky
parents: 1476
diff changeset
947 {
9fafea381eb8 Show the number of unfiltered contacts in folded groups
franky
parents: 1476
diff changeset
948 return display_filter & (1 << status);
9fafea381eb8 Show the number of unfiltered contacts in folded groups
franky
parents: 1476
diff changeset
949 }
9fafea381eb8 Show the number of unfiltered contacts in folded groups
franky
parents: 1476
diff changeset
950
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
951 void buddylist_set_filter(guchar filter)
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
952 {
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
953 display_filter = filter;
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
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
956 guchar buddylist_get_filter(void)
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
957 {
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
958 return display_filter;
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
959 }
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 119
diff changeset
960
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
961 // buddylist_build()
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
962 // Creates the buddylist from the roster entries.
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
963 void buddylist_build(void)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
964 {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
965 GSList *sl_roster_elt = groups;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
966 roster *roster_elt;
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
967 roster *roster_current_buddy = NULL;
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
968 roster *roster_alternate_buddy = NULL;
1996
7837d5a3f509 Going back to the first buddy with /roster next_unread when there is no more unread messages.
Simon Jacquin
parents: 1979
diff changeset
969 roster *roster_last_activity_buddy = NULL;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
970 int shrunk_group;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
971
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
972 // We need to remember which buddy is selected.
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
973 if (current_buddy)
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
974 roster_current_buddy = BUDDATA(current_buddy);
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
975 current_buddy = NULL;
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
976 if (alternate_buddy)
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
977 roster_alternate_buddy = BUDDATA(alternate_buddy);
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
978 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
979 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
980 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
981 last_activity_buddy = NULL;
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
982
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
983 // Destroy old buddylist
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
984 if (buddylist) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
985 g_list_free(buddylist);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
986 buddylist = NULL;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
987 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
988
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
989 buddylist = g_list_append(buddylist, &roster_special);
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
990
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
991 // Create the new list
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
992 while (sl_roster_elt) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
993 GSList *sl_roster_usrelt;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
994 roster *roster_usrelt;
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
995 guint pending_group = TRUE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
996 roster_elt = (roster*) sl_roster_elt->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
997
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
998 shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
999
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1000 sl_roster_usrelt = roster_elt->list;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1001 while (sl_roster_usrelt) {
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1002 roster_usrelt = (roster*) sl_roster_usrelt->data;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1003
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1004 // Buddy will be added if either:
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
1005 // - buddy's status matches the display_filter
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1006 // - buddy has a lock (for example the buddy window is currently open)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1007 // - buddy has a pending (non-read) message
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
1008 // - group isn't hidden (shrunk)
147
7571de4aed73 [/trunk] Changeset 159 by mikael
mikael
parents: 141
diff changeset
1009 // - this is the current_buddy
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1292
diff changeset
1010 if (roster_usrelt == roster_current_buddy ||
1504
9fafea381eb8 Show the number of unfiltered contacts in folded groups
franky
parents: 1476
diff changeset
1011 buddylist_is_status_filtered(buddy_getstatus((gpointer)roster_usrelt,
9fafea381eb8 Show the number of unfiltered contacts in folded groups
franky
parents: 1476
diff changeset
1012 NULL)) ||
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1013 (buddy_getflags((gpointer)roster_usrelt) &
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 952
diff changeset
1014 (ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1015 // 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
1016 if (pending_group) {
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1017 // It hasn't been done yet
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1018 buddylist = g_list_append(buddylist, roster_elt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1019 pending_group = FALSE;
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1020 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1021 // Add user
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
1022 // XXX Should we add the user if there is a message and
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
1023 // the group is shrunk? If so, we'd need to check LOCK flag too,
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
1024 // perhaps...
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
1025 if (!shrunk_group)
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 120
diff changeset
1026 buddylist = g_list_append(buddylist, roster_usrelt);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1027 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1028
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1029 sl_roster_usrelt = g_slist_next(sl_roster_usrelt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1030 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1031 sl_roster_elt = g_slist_next(sl_roster_elt);
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1032 }
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
1033
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
1034 // Check if we can find our saved current_buddy...
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
1035 if (roster_current_buddy)
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
1036 current_buddy = g_list_find(buddylist, roster_current_buddy);
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
1037 if (roster_alternate_buddy)
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
1038 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
1039 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
1040 last_activity_buddy = g_list_find(buddylist, roster_last_activity_buddy);
78
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
1041 // current_buddy initialization
d001d8fb876d [/trunk] Changeset 92 by mikael
mikael
parents: 72
diff changeset
1042 if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1))
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 80
diff changeset
1043 current_buddy = g_list_first(buddylist);
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1044 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1045
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1046 // buddy_hide_group(roster, hide)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1047 // "hide" values: 1=hide 0=show_all -1=invert
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1048 void buddy_hide_group(gpointer rosterdata, int hide)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1049 {
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1050 roster *roster_usr = rosterdata;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1051 if (hide > 0) // TRUE (hide)
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1052 roster_usr->flags |= ROSTER_FLAG_HIDE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1053 else if (hide < 0) // NEG (invert)
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1054 roster_usr->flags ^= ROSTER_FLAG_HIDE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1055 else // FALSE (don't hide)
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1056 roster_usr->flags &= ~ROSTER_FLAG_HIDE;
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1057 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1058
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1059 const char *buddy_getjid(gpointer rosterdata)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1060 {
1475
ef09de538e8f Fix compilation error (reported by H. D. Oezbilen)
Mikael Berthe <mikael@lilotux.net>
parents: 1444
diff changeset
1061 roster *roster_usr = rosterdata;
1292
382ec54b584e Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1205
diff changeset
1062 if (!rosterdata)
382ec54b584e Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1205
diff changeset
1063 return NULL;
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1064 return roster_usr->jid;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1065 }
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1066
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1067 // buddy_setgroup()
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1068 // Change the group of current buddy
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1069 //
1366
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
1070 // Note: buddy_setgroup() updates the user lists.
01e558748379 Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
1071 //
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1072 void buddy_setgroup(gpointer rosterdata, char *newgroupname)
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1073 {
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1074 roster *roster_usr = rosterdata;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1075 GSList **sl_group;
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1076 GSList *sl_newgroup;
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1077 roster *my_newgroup;
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1078
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1079 // A group has no group :)
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1080 if (roster_usr->type & ROSTER_TYPE_GROUP) return;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1081
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1082 // Add newgroup if necessary
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1083 if (!newgroupname) newgroupname = "";
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1084 sl_newgroup = roster_add_group(newgroupname);
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1085 if (!sl_newgroup) return;
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1086 my_newgroup = (roster*)sl_newgroup->data;
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1087
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1088 // Remove the buddy from current group
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1089 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1090 *sl_group = g_slist_remove(*sl_group, rosterdata);
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1091
621
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
1092 // 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
1093 if (!*sl_group) {
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
1094 roster *roster_grp = (roster*)((GSList*)roster_usr->list)->data;
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
1095 g_free((gchar*)roster_grp->jid);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
1096 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
1097 g_free(roster_grp);
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
1098 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
1099 }
f20c1934a8a7 "/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
1100
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1101 // Add the buddy to its new group
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1102 roster_usr->list = sl_newgroup; // (my_newgroup SList element)
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1103 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
1104 (GCompareFunc)&roster_compare_name);
212
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
1105
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1106 buddylist_build();
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1107 }
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 209
diff changeset
1108
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1109 void buddy_setname(gpointer rosterdata, char *newname)
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1110 {
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1111 roster *roster_usr = rosterdata;
209
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
1112 GSList **sl_group;
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1113
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1114 // TODO For groups, we need to check for unicity
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1115 // However, renaming a group boils down to moving all its buddies to
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1116 // another group, so calling this function is not really necessary...
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1117 if (roster_usr->type & ROSTER_TYPE_GROUP) return;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1118
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1119 if (roster_usr->name) {
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1120 g_free((gchar*)roster_usr->name);
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1121 roster_usr->name = NULL;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1122 }
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1123 if (newname)
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1124 roster_usr->name = g_strdup(newname);
209
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
1125
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
1126 // We need to resort the group list
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
1127 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list;
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
1128 *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name);
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
1129
353a4f8a3f61 [/trunk] Changeset 221 by mikael
mikael
parents: 207
diff changeset
1130 buddylist_build();
72
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1131 }
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1132
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1133 const char *buddy_getname(gpointer rosterdata)
9b7f0d313e33 [/trunk] Changeset 86 by mikael
mikael
parents:
diff changeset
1134 {
207
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1135 roster *roster_usr = rosterdata;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1136 return roster_usr->name;
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1137 }
41fafa0ecfd8 [/trunk] Changeset 219 by mikael
mikael
parents: 192
diff changeset
1138
548
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1139 // buddy_setnickname(buddy, newnickname)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1140 // Only for chatrooms
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1141 void buddy_setnickname(gpointer rosterdata, const char *newname)
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1142 {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1143 roster *roster_usr = rosterdata;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1144
649
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1145 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
1146
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1147 if (roster_usr->nickname) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1148 g_free((gchar*)roster_usr->nickname);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1149 roster_usr->nickname = NULL;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1150 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1151 if (newname)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1152 roster_usr->nickname = g_strdup(newname);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1153 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1154
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1155 const char *buddy_getnickname(gpointer rosterdata)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1156 {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1157 roster *roster_usr = rosterdata;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1158 return roster_usr->nickname;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1159 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
1160
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1161 // buddy_setinsideroom(buddy, inside)
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1162 // Only for chatrooms
952
527d6f234924 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
1163 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
1164 {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1165 roster *roster_usr = rosterdata;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1166
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1167 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
1168
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1169 roster_usr->inside_room = inside;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1170 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1171
952
527d6f234924 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
1172 guint buddy_getinsideroom(gpointer rosterdata)
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1173 {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1174 roster *roster_usr = rosterdata;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1175 return roster_usr->inside_room;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1176 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1177
548
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1178 // buddy_settopic(buddy, newtopic)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1179 // Only for chatrooms
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1180 void buddy_settopic(gpointer rosterdata, const char *newtopic)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1181 {
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1182 roster *roster_usr = rosterdata;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1183
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1184 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1185
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1186 if (roster_usr->topic) {
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1187 g_free((gchar*)roster_usr->topic);
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1188 roster_usr->topic = NULL;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1189 }
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1190 if (newtopic)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1191 roster_usr->topic = g_strdup(newtopic);
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1192 }
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1193
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1194 const char *buddy_gettopic(gpointer rosterdata)
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1195 {
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1196 roster *roster_usr = rosterdata;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1197 return roster_usr->topic;
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1198 }
265c50238a48 Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
1199
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1200 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
1201 {
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1202 roster *roster_usr = rosterdata;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1203 roster_usr->print_status = pstatus;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1204 }
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1205
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1206 enum room_printstatus buddy_getprintstatus(gpointer rosterdata)
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1207 {
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1208 roster *roster_usr = rosterdata;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1209 return roster_usr->print_status;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1210 }
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1211
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1212 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
1213 {
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1214 roster *roster_usr = rosterdata;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1215 roster_usr->auto_whois = awhois;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1216 }
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1217
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1366
diff changeset
1218 enum room_autowhois buddy_getautowhois(gpointer rosterdata)