forked from fchat-pidgin/fchat-pidgin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
f-list_autobuddy.c
110 lines (98 loc) · 3.96 KB
/
f-list_autobuddy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* F-List Pidgin - a libpurple protocol plugin for F-Chat
*
* Copyright 2011 F-List Pidgin developers.
*
* This file is part of F-List Pidgin.
*
* F-List Pidgin is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* F-List Pidgin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with F-List Pidgin. If not, see <http://www.gnu.org/licenses/>.
*/
#include "f-list_autobuddy.h"
void flist_apply_filter(FListAccount *fla, GSList *candidates) {
PurpleGroup *filter_group = NULL;
GSList *buddies, *cur;
GSList *removed = NULL;
filter_group = flist_get_filter_group(fla);
buddies = purple_find_buddies(fla->pa, NULL);
cur = buddies;
while(cur) {
PurpleBuddy *b = cur->data; cur = g_slist_next(cur);
const gchar *name = purple_buddy_get_name(b);
if(purple_buddy_get_group(b) == filter_group) {
if(!g_slist_find_custom(candidates, name, (GCompareFunc) purple_utf8_strcasecmp)) { //TODO: this is extremely inefficient, fix it!
removed = g_slist_prepend(removed, b);
}
}
}
g_slist_free(buddies);
cur = removed;
while(cur) {
PurpleBuddy *b = cur->data; cur = g_slist_next(cur);
purple_blist_remove_buddy(b);
}
g_slist_free(removed);
cur = candidates;
while(cur) {
const gchar *name = cur->data; cur = g_slist_next(cur);
purple_debug_info(FLIST_DEBUG, "adding %s\n", name);
PurpleBuddy *b = purple_find_buddy(fla->pa, name);
if(!b) { /* we're adding a new buddy */
b = purple_buddy_new(fla->pa, name, NULL);
purple_blist_add_buddy(b, NULL, filter_group, NULL);
purple_account_add_buddy(fla->pa, b);
} /* do nothing if this is already a buddy */
}
}
void flist_clear_temp_groups(FListAccount *fla) {
PurpleGroup *filter_group = NULL;
PurpleGroup *im_group = NULL;
GSList *buddies, *cur;
filter_group = flist_get_filter_group(fla);
im_group = flist_get_im_group(fla);
buddies = purple_find_buddies(fla->pa, NULL);
cur = buddies;
while(cur) {
PurpleBuddy *b = cur->data; cur = g_slist_next(cur);
if(purple_buddy_get_group(b) == filter_group || purple_buddy_get_group(b) == im_group) {
// When reconnecting, do not remove buddies who still have a conversation open
if (!purple_find_conversation_with_account(
PURPLE_CONV_TYPE_IM,
purple_buddy_get_name(b),
fla->pa)) {
purple_blist_remove_buddy(b);
}
}
}
g_slist_free(buddies);
}
void flist_convo_closed(PurpleConnection *pc, const char *who) {
FListAccount *fla = purple_connection_get_protocol_data(pc);
PurpleGroup *im_group = flist_get_im_group(fla);
/* Try to find if this was a temporary IM, and if it was, remove it */
PurpleBuddy *buddy = purple_find_buddy_in_group(fla->pa, who, im_group);
if (buddy) {
purple_debug_info(FLIST_DEBUG, "Removing temporary IM buddy %s\n", who);
purple_blist_remove_buddy(buddy);
}
}
void flist_temp_im_check(FListAccount *fla, const char *character) {
PurpleBuddy *buddy = purple_find_buddy(fla->pa, character);
if (!buddy) {
purple_debug_info(FLIST_DEBUG, "Adding temporary IM buddy %s\n", character);
PurpleGroup *im_group = flist_get_im_group(fla);
PurpleBuddy *b = purple_buddy_new(fla->pa, character, NULL);
purple_blist_add_buddy(b, NULL, im_group, NULL);
purple_account_add_buddy(fla->pa, b);
}
}