aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-07-02 23:39:13 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-07-02 23:39:13 +0200
commit9edf21bd96a83a7e6c660e16c331b04e3b7add14 (patch)
treea713536a36e4437d393bd8a90a9a5d35291b5c03
parente30bd43c171922eab729d5c8e51f92d33bc8d9f5 (diff)
downloadmessenger-cli-9edf21bd96a83a7e6c660e16c331b04e3b7add14.tar.gz
messenger-cli-9edf21bd96a83a7e6c660e16c331b04e3b7add14.zip
Added contacts into chats list
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/ui/chats.c73
-rw-r--r--src/ui/chats.h2
2 files changed, 59 insertions, 16 deletions
diff --git a/src/ui/chats.c b/src/ui/chats.c
index fc7056c..f727a37 100644
--- a/src/ui/chats.c
+++ b/src/ui/chats.c
@@ -28,9 +28,9 @@
28#include "../util.h" 28#include "../util.h"
29 29
30static int 30static int
31_chats_iterate(void *cls, 31_chats_iterate_group(void *cls,
32 UNUSED struct GNUNET_CHAT_Handle *handle, 32 UNUSED struct GNUNET_CHAT_Handle *handle,
33 struct GNUNET_CHAT_Group *group) 33 struct GNUNET_CHAT_Group *group)
34{ 34{
35 UI_CHATS_Handle *chats = cls; 35 UI_CHATS_Handle *chats = cls;
36 36
@@ -39,7 +39,24 @@ _chats_iterate(void *cls,
39 chats->line_index++; 39 chats->line_index++;
40 40
41 if (selected) 41 if (selected)
42 chats->selected = group; 42 chats->selected = GNUNET_CHAT_group_get_context(group);
43
44 return GNUNET_YES;
45}
46
47static int
48_chats_iterate_contact(void *cls,
49 UNUSED struct GNUNET_CHAT_Handle *handle,
50 struct GNUNET_CHAT_Contact *contact)
51{
52 UI_CHATS_Handle *chats = cls;
53
54 const bool selected = (chats->line_selected == chats->line_index);
55
56 chats->line_index++;
57
58 if (selected)
59 chats->selected = GNUNET_CHAT_contact_get_context(contact);
43 60
44 return GNUNET_YES; 61 return GNUNET_YES;
45} 62}
@@ -68,11 +85,19 @@ chats_event(UI_CHATS_Handle *chats,
68 chats->line_index = 0; 85 chats->line_index = 0;
69 chats->selected = NULL; 86 chats->selected = NULL;
70 87
71 int count = GNUNET_CHAT_iterate_groups( 88 int count = 1;
89
90 count += GNUNET_CHAT_iterate_groups(
91 app->chat.handle,
92 &_chats_iterate_group,
93 chats
94 );
95
96 count += GNUNET_CHAT_iterate_contacts(
72 app->chat.handle, 97 app->chat.handle,
73 &_chats_iterate, 98 &_chats_iterate_contact,
74 chats 99 chats
75 ) + 1; 100 );
76 101
77 switch (key) 102 switch (key)
78 { 103 {
@@ -97,23 +122,23 @@ chats_event(UI_CHATS_Handle *chats,
97 { 122 {
98 if (chats->selected) 123 if (chats->selected)
99 { 124 {
100 struct GNUNET_CHAT_Context *context = GNUNET_CHAT_group_get_context(chats->selected); 125 GNUNET_CHAT_context_request(chats->selected);
101 126
102 members_clear(&(app->current.members)); 127 members_clear(&(app->current.members));
103 messages_clear(&(app->current.messages)); 128 messages_clear(&(app->current.messages));
104 129
105 GNUNET_CHAT_context_set_user_pointer( 130 GNUNET_CHAT_context_set_user_pointer(
106 context, 131 chats->selected,
107 &(app->current) 132 &(app->current)
108 ); 133 );
109 134
110 GNUNET_CHAT_context_iterate_messages( 135 GNUNET_CHAT_context_iterate_messages(
111 context, 136 chats->selected,
112 &_chats_iterate_messages, 137 &_chats_iterate_messages,
113 &(app->chat) 138 &(app->chat)
114 ); 139 );
115 140
116 app->chat.context = context; 141 app->chat.context = chats->selected;
117 } 142 }
118 else 143 else
119 chats->open_dialog.window = chats->window; 144 chats->open_dialog.window = chats->window;
@@ -181,9 +206,9 @@ _chats_print_entry(UI_CHATS_Handle *chats,
181} 206}
182 207
183int 208int
184_chats_iterate_print(void *cls, 209_chats_iterate_print_group(void *cls,
185 UNUSED struct GNUNET_CHAT_Handle *handle, 210 UNUSED struct GNUNET_CHAT_Handle *handle,
186 struct GNUNET_CHAT_Group *group) 211 struct GNUNET_CHAT_Group *group)
187{ 212{
188 UI_CHATS_Handle *chats = cls; 213 UI_CHATS_Handle *chats = cls;
189 214
@@ -192,6 +217,18 @@ _chats_iterate_print(void *cls,
192 return _chats_print_entry(chats, 'x', 'G', name); 217 return _chats_print_entry(chats, 'x', 'G', name);
193} 218}
194 219
220int
221_chats_iterate_print_contact(void *cls,
222 UNUSED struct GNUNET_CHAT_Handle *handle,
223 struct GNUNET_CHAT_Contact *contact)
224{
225 UI_CHATS_Handle *chats = cls;
226
227 const char *name = GNUNET_CHAT_contact_get_name(contact);
228
229 return _chats_print_entry(chats, 'x', 'C', name);
230}
231
195void 232void
196chats_print(UI_CHATS_Handle *chats, 233chats_print(UI_CHATS_Handle *chats,
197 MESSENGER_Application *app) 234 MESSENGER_Application *app)
@@ -210,7 +247,13 @@ chats_print(UI_CHATS_Handle *chats,
210 247
211 GNUNET_CHAT_iterate_groups( 248 GNUNET_CHAT_iterate_groups(
212 app->chat.handle, 249 app->chat.handle,
213 &_chats_iterate_print, 250 &_chats_iterate_print_group,
251 chats
252 );
253
254 GNUNET_CHAT_iterate_contacts(
255 app->chat.handle,
256 &_chats_iterate_print_contact,
214 chats 257 chats
215 ); 258 );
216 259
diff --git a/src/ui/chats.h b/src/ui/chats.h
index c4485ad..85a84eb 100644
--- a/src/ui/chats.h
+++ b/src/ui/chats.h
@@ -44,7 +44,7 @@ typedef struct UI_CHATS_Handle
44 int line_offset; 44 int line_offset;
45 int line_selected; 45 int line_selected;
46 46
47 struct GNUNET_CHAT_Group *selected; 47 struct GNUNET_CHAT_Context *selected;
48 48
49 UI_CHAT_OPEN_DIALOG_Handle open_dialog; 49 UI_CHAT_OPEN_DIALOG_Handle open_dialog;
50} UI_CHATS_Handle; 50} UI_CHATS_Handle;