diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-29 22:24:45 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-07-29 22:24:45 +0200 |
commit | ecccdbe89ad906f5d995e45ec1ff40117d642b18 (patch) | |
tree | cca01251849b7343413c6d24b153cf1dd9828c7e /src/gnunet_chat_handle_intern.c | |
parent | 62d9bd1120633b094b813b66c49f94db8f2f8abb (diff) | |
download | libgnunetchat-ecccdbe89ad906f5d995e45ec1ff40117d642b18.tar.gz libgnunetchat-ecccdbe89ad906f5d995e45ec1ff40117d642b18.zip |
Added creating chat contacts for each known messenger contact
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/gnunet_chat_handle_intern.c')
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index 17bff20..a6342a9 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -190,21 +190,24 @@ struct GNUNET_CHAT_CheckHandleRoomMembers | |||
190 | int | 190 | int |
191 | check_handle_room_members (void* cls, | 191 | check_handle_room_members (void* cls, |
192 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, | 192 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, |
193 | const struct GNUNET_MESSENGER_Contact *contact) | 193 | const struct GNUNET_MESSENGER_Contact *member) |
194 | { | 194 | { |
195 | struct GNUNET_CHAT_CheckHandleRoomMembers *check = cls; | 195 | struct GNUNET_CHAT_CheckHandleRoomMembers *check = cls; |
196 | 196 | ||
197 | const struct GNUNET_IDENTITY_PublicKey *contact_key = ( | 197 | const struct GNUNET_IDENTITY_PublicKey *member_key = ( |
198 | GNUNET_MESSENGER_contact_get_key(contact) | 198 | GNUNET_MESSENGER_contact_get_key(member) |
199 | ); | 199 | ); |
200 | 200 | ||
201 | if (0 == GNUNET_memcmp(contact_key, check->ignore_key)) | 201 | if (0 == GNUNET_memcmp(member_key, check->ignore_key)) |
202 | return GNUNET_YES; | 202 | return GNUNET_YES; |
203 | 203 | ||
204 | if (check->contact) | 204 | if (check->contact) |
205 | { | ||
206 | check->contact = NULL; | ||
205 | return GNUNET_NO; | 207 | return GNUNET_NO; |
208 | } | ||
206 | 209 | ||
207 | check->contact = contact; | 210 | check->contact = member; |
208 | return GNUNET_YES; | 211 | return GNUNET_YES; |
209 | } | 212 | } |
210 | 213 | ||
@@ -246,6 +249,8 @@ request_handle_context_by_room (struct GNUNET_CHAT_Handle *handle, | |||
246 | handle, check.contact | 249 | handle, check.contact |
247 | ); | 250 | ); |
248 | 251 | ||
252 | contact->context = context; | ||
253 | |||
249 | struct GNUNET_ShortHashCode shorthash; | 254 | struct GNUNET_ShortHashCode shorthash; |
250 | util_shorthash_from_member(check.contact, &shorthash); | 255 | util_shorthash_from_member(check.contact, &shorthash); |
251 | 256 | ||
@@ -295,15 +300,70 @@ find_handle_rooms (void *cls, struct GNUNET_MESSENGER_Room *room, | |||
295 | return GNUNET_YES; | 300 | return GNUNET_YES; |
296 | } | 301 | } |
297 | 302 | ||
303 | int | ||
304 | scan_handle_room_members (void* cls, | ||
305 | GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room, | ||
306 | const struct GNUNET_MESSENGER_Contact *member) | ||
307 | { | ||
308 | struct GNUNET_CHAT_Handle *handle = cls; | ||
309 | |||
310 | struct GNUNET_ShortHashCode shorthash; | ||
311 | util_shorthash_from_member(member, &shorthash); | ||
312 | |||
313 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains( | ||
314 | handle->contacts, &shorthash)) | ||
315 | return GNUNET_YES; | ||
316 | |||
317 | struct GNUNET_CHAT_Contact *contact = contact_create_from_member( | ||
318 | handle, member | ||
319 | ); | ||
320 | |||
321 | if (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put( | ||
322 | handle->contacts, &shorthash, contact, | ||
323 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
324 | return GNUNET_YES; | ||
325 | |||
326 | contact_destroy(contact); | ||
327 | return GNUNET_NO; | ||
328 | } | ||
329 | |||
330 | int | ||
331 | scan_handle_rooms (void *cls, struct GNUNET_MESSENGER_Room *room, | ||
332 | GNUNET_UNUSED const struct GNUNET_MESSENGER_Contact *member) | ||
333 | { | ||
334 | struct GNUNET_CHAT_Handle *handle = cls; | ||
335 | |||
336 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(room); | ||
337 | |||
338 | struct GNUNET_CHAT_Group *group = GNUNET_CONTAINER_multihashmap_get( | ||
339 | handle->groups, key | ||
340 | ); | ||
341 | |||
342 | if (!group) | ||
343 | return GNUNET_YES; | ||
344 | |||
345 | GNUNET_MESSENGER_iterate_members(room, scan_handle_room_members, handle); | ||
346 | return GNUNET_YES; | ||
347 | } | ||
348 | |||
298 | void | 349 | void |
299 | on_handle_identity(void *cls, | 350 | on_handle_identity(void *cls, |
300 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) | 351 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) |
301 | { | 352 | { |
302 | struct GNUNET_CHAT_Handle *handle = cls; | 353 | struct GNUNET_CHAT_Handle *handle = cls; |
303 | 354 | ||
355 | if ((0 < GNUNET_CONTAINER_multihashmap_size(handle->contexts)) || | ||
356 | (0 < GNUNET_CONTAINER_multihashmap_size(handle->groups)) || | ||
357 | (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts))) | ||
358 | return; | ||
359 | |||
304 | GNUNET_MESSENGER_find_rooms( | 360 | GNUNET_MESSENGER_find_rooms( |
305 | handle->messenger, NULL, find_handle_rooms, handle | 361 | handle->messenger, NULL, find_handle_rooms, handle |
306 | ); | 362 | ); |
363 | |||
364 | GNUNET_MESSENGER_find_rooms( | ||
365 | handle->messenger, NULL, scan_handle_rooms, handle | ||
366 | ); | ||
307 | } | 367 | } |
308 | 368 | ||
309 | void | 369 | void |