libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 33f758bfaa9776a34e582c2d713675b9d0f230e7
parent e7fb68155e1333c7af024ebec8f270b111dadf1c
Author: Jacki <jacki@thejackimonster.de>
Date:   Wed,  8 Jul 2026 03:07:34 +0200

Fix getting proper context of individual contact

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/gnunet_chat_contact.c | 31+++++++++++++++++++++----------
Msrc/gnunet_chat_contact_intern.c | 26+++++++++++++++++++-------
Msrc/gnunet_chat_context.c | 14+++++++-------
3 files changed, 47 insertions(+), 24 deletions(-)

diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2025 GNUnet e.V. + Copyright (C) 2021--2026 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -26,6 +26,7 @@ #include "gnunet_chat_context.h" #include "gnunet_chat_handle.h" #include "gnunet_chat_ticket.h" +#include "gnunet_chat_util.h" #include "internal/gnunet_chat_tagging.h" @@ -107,7 +108,7 @@ contact_update_join (struct GNUNET_CHAT_Contact *contact, return; } - GNUNET_memcpy(current, hash, + GNUNET_memcpy(current, hash, sizeof(struct GNUNET_HashCode)); return; } @@ -117,9 +118,9 @@ contact_update_join (struct GNUNET_CHAT_Contact *contact, if (GNUNET_YES == blocked) contact_untag(contact, context, NULL); - GNUNET_memcpy(current, hash, + GNUNET_memcpy(current, hash, sizeof(struct GNUNET_HashCode)); - + if (GNUNET_YES == blocked) contact_tag(contact, context, NULL); } @@ -192,8 +193,9 @@ contact_find_context (const struct GNUNET_CHAT_Contact *contact, return contact->context; struct GNUNET_CHAT_ContactFindRoom find; - find.member_count = 0; + find.contexts = contact->handle->contexts; find.room = NULL; + find.member_count = 0; GNUNET_MESSENGER_find_rooms( contact->handle->messenger, @@ -210,9 +212,18 @@ contact_find_context (const struct GNUNET_CHAT_Contact *contact, GNUNET_MESSENGER_room_get_key(find.room) ); - if ((GNUNET_YES == room_required) && (!(context->room))) + if ((context->room) && (context->room != find.room)) return NULL; + if (!context->room) + context->room = find.room; + if ((!context->contact) && + (GNUNET_CHAT_CONTEXT_TYPE_GROUP != context->type)) + { + context->contact = contact->member; + context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; + } + return context; } @@ -279,11 +290,11 @@ skip_context_search: contact, context); if (! hash) - return (general == GNUNET_YES? - GNUNET_NO : + return (general == GNUNET_YES? + GNUNET_NO : contact_is_tagged(contact, NULL, tag) ); - + const struct GNUNET_CHAT_InternalTagging *tagging = GNUNET_CONTAINER_multihashmap_get( context->taggings, hash @@ -458,7 +469,7 @@ contact_iterate_tags (struct GNUNET_CHAT_Contact *contact, context = GNUNET_CONTAINER_multihashmap_get( contact->handle->contexts, &key); - + if (context) result = contact_iterate_tags( contact, diff --git a/src/gnunet_chat_contact_intern.c b/src/gnunet_chat_contact_intern.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021--2024 GNUnet e.V. + Copyright (C) 2021--2024, 2026 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -24,6 +24,7 @@ #include "gnunet_chat_context.h" #include "gnunet_chat_message.h" +#include "gnunet_chat_util.h" #include <gnunet/gnunet_common.h> #include <gnunet/gnunet_messenger_service.h> @@ -34,8 +35,9 @@ struct GNUNET_CHAT_ContactFindRoom { - int member_count; + struct GNUNET_CONTAINER_MultiHashMap *contexts; struct GNUNET_MESSENGER_Room *room; + int member_count; }; enum GNUNET_GenericReturnValue @@ -48,12 +50,22 @@ it_contact_find_room (void *cls, const int member_count = GNUNET_MESSENGER_iterate_members(room, NULL, NULL); struct GNUNET_CHAT_ContactFindRoom *find = cls; + struct GNUNET_CHAT_Context *context; + + if ((member_count == 1) && (find->member_count == 1)) + context = GNUNET_CONTAINER_multihashmap_get( + find->contexts, + GNUNET_MESSENGER_room_get_key(room) + ); + else + context = NULL; if ((find->member_count <= 0) || - ((member_count >= 1) && (member_count < find->member_count))) + ((member_count >= 1) && (member_count < find->member_count)) || + ((context) && (context->type == GNUNET_CHAT_CONTEXT_TYPE_CONTACT))) { - find->member_count = member_count; find->room = room; + find->member_count = member_count; } return GNUNET_YES; @@ -107,10 +119,10 @@ it_contact_iterate_unique_tag (void *cls, if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(it->tags, &hash)) return GNUNET_YES; - if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(it->tags, + if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(it->tags, &hash, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) return GNUNET_YES; - + if (it->callback) return it->callback(it->cls, contact, tag); else @@ -135,7 +147,7 @@ it_contact_iterate_tag (void *cls, if ((GNUNET_YES != message_has_msg(message)) || (message->flags & GNUNET_MESSENGER_FLAG_DELETE)) return GNUNET_YES; - + if ((message->flags & GNUNET_MESSENGER_FLAG_SENT) && (it->callback) && (message->msg->body.tag.tag)) return it->callback( diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c @@ -68,7 +68,7 @@ init_new_context (struct GNUNET_CHAT_Context *context, initial_map_size, GNUNET_NO); context->discourses = GNUNET_CONTAINER_multishortmap_create( initial_map_size, GNUNET_NO); - + context->user_pointer = NULL; context->member_pointers = GNUNET_CONTAINER_multishortmap_create( @@ -87,7 +87,7 @@ context_create_from_room (struct GNUNET_CHAT_Handle *handle, context->handle = handle; context->type = GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN; - + init_new_context(context, initial_map_size_of_room); context->room = room; @@ -197,14 +197,14 @@ context_request_message (struct GNUNET_CHAT_Context* context, if ((!(context->room)) || (GNUNET_YES == context->deleted)) return; - if ((GNUNET_is_zero(hash)) || + if ((GNUNET_is_zero(hash)) || (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(context->messages, hash))) return; if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(context->requests, hash, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)) return; - + if (context->request_task) return; @@ -223,7 +223,7 @@ context_update_message (struct GNUNET_CHAT_Context* context, struct GNUNET_CHAT_Message *message = GNUNET_CONTAINER_multihashmap_get( context->messages, hash); - + if (!message) return; @@ -418,7 +418,7 @@ context_delete_message (struct GNUNET_CHAT_Context *context, if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove( context->invites, &(message->hash), invite)) invitation_destroy(invite); - + break; } case GNUNET_MESSENGER_KIND_FILE: @@ -478,7 +478,7 @@ context_write_records (struct GNUNET_CHAT_Context *context) struct GNUNET_MESSENGER_RoomDetailsRecord room_details; memset(room_details.name, 0, sizeof(room_details.name)); - + const char *topic = context->topic; if (topic)