about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-05 23:54:29 +0000
committerJames Booth <boothj5@gmail.com>2014-01-05 23:54:29 +0000
commitdb973457d0b3548f767f9849ce8ca7816dcbd36e (patch)
treee42ad22ded31e086b714bd64080818bdedaee8f3 /src
parent76484665fd0df4e559f7a6732819130dc98b68a7 (diff)
downloadprofani-tty-db973457d0b3548f767f9849ce8ca7816dcbd36e.tar.gz
Refactored roster add/update
Diffstat (limited to 'src')
-rw-r--r--src/profanity.c7
-rw-r--r--src/profanity.h1
-rw-r--r--src/roster_list.c70
-rw-r--r--src/roster_list.h2
-rw-r--r--src/server_events.c7
-rw-r--r--src/server_events.h1
-rw-r--r--src/xmpp/roster.c12
7 files changed, 49 insertions, 51 deletions
diff --git a/src/profanity.c b/src/profanity.c
index 9178d056..dae91aea 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -118,13 +118,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
 }
 
 void
-prof_handle_roster_add(const char * const barejid, const char * const name)
-{
-    ui_roster_add(barejid, name);
-    ui_current_page_off();
-}
-
-void
 prof_handle_idle(void)
 {
     jabber_conn_status_t status = jabber_get_connection_status();
diff --git a/src/profanity.h b/src/profanity.h
index 5e826fc4..c55e6c47 100644
--- a/src/profanity.h
+++ b/src/profanity.h
@@ -30,6 +30,5 @@ void prof_run(const int disable_tls, char *log_level, char *account_name);
 
 void prof_handle_idle(void);
 void prof_handle_activity(void);
-void prof_handle_roster_add(const char * const barejid, const char * const name);
 
 #endif
diff --git a/src/roster_list.c b/src/roster_list.c
index 7945101a..1341320f 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -30,7 +30,6 @@
 #include "contact.h"
 #include "jid.h"
 #include "tools/autocomplete.h"
-#include "profanity.h"
 
 // nicknames
 static Autocomplete name_ac;
@@ -201,60 +200,51 @@ roster_update(const char * const barejid, const char * const name,
     GSList *groups, const char * const subscription, gboolean pending_out)
 {
     PContact contact = g_hash_table_lookup(contacts, barejid);
+    assert(contact != NULL);
 
-    if (contact == NULL) {
-        roster_add(barejid, name, groups, subscription, pending_out, FALSE);
-    } else {
-        p_contact_set_subscription(contact, subscription);
-        p_contact_set_pending_out(contact, pending_out);
+    p_contact_set_subscription(contact, subscription);
+    p_contact_set_pending_out(contact, pending_out);
 
-        const char * const new_name = name;
-        const char * current_name = NULL;
-        if (p_contact_name(contact) != NULL) {
-            current_name = strdup(p_contact_name(contact));
-        }
+    const char * const new_name = name;
+    const char * current_name = NULL;
+    if (p_contact_name(contact) != NULL) {
+        current_name = strdup(p_contact_name(contact));
+    }
 
-        p_contact_set_name(contact, new_name);
-        p_contact_set_groups(contact, groups);
-        _replace_name(current_name, new_name, barejid);
+    p_contact_set_name(contact, new_name);
+    p_contact_set_groups(contact, groups);
+    _replace_name(current_name, new_name, barejid);
 
-        // add groups
-        while (groups != NULL) {
-            autocomplete_add(groups_ac, groups->data);
-            groups = g_slist_next(groups);
-        }
+    // add groups
+    while (groups != NULL) {
+        autocomplete_add(groups_ac, groups->data);
+        groups = g_slist_next(groups);
     }
 }
 
 gboolean
 roster_add(const char * const barejid, const char * const name, GSList *groups,
-    const char * const subscription, gboolean pending_out, gboolean from_initial)
+    const char * const subscription, gboolean pending_out)
 {
-    gboolean added = FALSE;
     PContact contact = g_hash_table_lookup(contacts, barejid);
+    if (contact != NULL) {
+        return FALSE;
+    }
 
-    if (contact == NULL) {
-        contact = p_contact_new(barejid, name, groups, subscription, NULL,
-            pending_out);
-
-        // add groups
-        while (groups != NULL) {
-            autocomplete_add(groups_ac, groups->data);
-            groups = g_slist_next(groups);
-        }
-
-        g_hash_table_insert(contacts, strdup(barejid), contact);
-        autocomplete_add(barejid_ac, barejid);
-        _add_name_and_barejid(name, barejid);
-
-        if (!from_initial) {
-            prof_handle_roster_add(barejid, name);
-        }
+    contact = p_contact_new(barejid, name, groups, subscription, NULL,
+        pending_out);
 
-        added = TRUE;
+    // add groups
+    while (groups != NULL) {
+        autocomplete_add(groups_ac, groups->data);
+        groups = g_slist_next(groups);
     }
 
-    return added;
+    g_hash_table_insert(contacts, strdup(barejid), contact);
+    autocomplete_add(barejid_ac, barejid);
+    _add_name_and_barejid(name, barejid);
+
+    return TRUE;
 }
 
 char *
diff --git a/src/roster_list.h b/src/roster_list.h
index a7198e5c..58490609 100644
--- a/src/roster_list.h
+++ b/src/roster_list.h
@@ -42,7 +42,7 @@ void roster_remove(const char * const name, const char * const barejid);
 void roster_update(const char * const barejid, const char * const name,
     GSList *groups, const char * const subscription, gboolean pending_out);
 gboolean roster_add(const char * const barejid, const char * const name, GSList *groups,
-    const char * const subscription, gboolean pending_out, gboolean from_initial);
+    const char * const subscription, gboolean pending_out);
 char * roster_barejid_from_name(const char * const name);
 GSList * roster_get_contacts(void);
 gboolean roster_has_pending_subscriptions(void);
diff --git a/src/server_events.c b/src/server_events.c
index cbf2de3c..ac940c86 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -366,3 +366,10 @@ handle_roster_remove(const char * const barejid)
     ui_roster_remove(barejid);
     ui_current_page_off();
 }
+
+void
+handle_roster_add(const char * const barejid, const char * const name)
+{
+    ui_roster_add(barejid, name);
+    ui_current_page_off();
+}
diff --git a/src/server_events.h b/src/server_events.h
index b79e9c7b..ce3c3b49 100644
--- a/src/server_events.h
+++ b/src/server_events.h
@@ -71,5 +71,6 @@ void handle_group_add(const char * const contact,
 void handle_group_remove(const char * const contact,
     const char * const group);
 void handle_roster_remove(const char * const barejid);
+void handle_roster_add(const char * const barejid, const char * const name);
 
 #endif
diff --git a/src/xmpp/roster.c b/src/xmpp/roster.c
index 3da8c7d3..a70436e7 100644
--- a/src/xmpp/roster.c
+++ b/src/xmpp/roster.c
@@ -255,7 +255,15 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
         GSList *groups = _get_groups_from_item(item);
 
         // update the local roster
-        roster_update(barejid, name, groups, sub, pending_out);
+        PContact contact = roster_get_contact(barejid);
+        if (contact == NULL) {
+            gboolean added = roster_add(barejid, name, groups, sub, pending_out);
+            if (added) {
+                handle_roster_add(barejid, name);
+            }
+        } else {
+            roster_update(barejid, name, groups, sub, pending_out);
+        }
     }
 
     return 1;
@@ -289,7 +297,7 @@ _roster_handle_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
 
             GSList *groups = _get_groups_from_item(item);
 
-            gboolean added = roster_add(barejid, name, groups, sub, pending_out, TRUE);
+            gboolean added = roster_add(barejid, name, groups, sub, pending_out);
 
             if (!added) {
                 log_warning("Attempt to add contact twice: %s", barejid);
'alt'>
0be5089 ^
50d75c5 ^
d0db566 ^
d0db566 ^
a3d03d9 ^

12eeddb ^
a3d03d9 ^






46fddc3 ^
0b8f3a2 ^

46fddc3 ^
0b8f3a2 ^
79d718e ^

d0db566 ^
9279094 ^
6b55b3a ^
d0db566 ^


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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152