libgnunetchat

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

commit db0dfd2c550c50eb2934b1db0bc1658033bb46e9
parent 725c988a77ae5418296a38b4ab0e870786927b30
Author: Jacki <jacki@thejackimonster.de>
Date:   Mon, 14 Jul 2025 22:38:26 +0200

Fix leaving direct chat with contact

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

Diffstat:
Msrc/gnunet_chat_contact.c | 29+++++++++++++++++++++++++++++
Msrc/gnunet_chat_contact.h | 11+++++++++++
Msrc/gnunet_chat_lib_intern.c | 20++++++++++----------
3 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c @@ -125,6 +125,35 @@ contact_update_join (struct GNUNET_CHAT_Contact *contact, } void +contact_leave (struct GNUNET_CHAT_Contact *contact, + struct GNUNET_CHAT_Context *context) +{ + GNUNET_assert( + (contact) && + (contact->joined) && + (context) + ); + + if (!(context->room)) + return; + + const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( + context->room + ); + + struct GNUNET_HashCode *current = GNUNET_CONTAINER_multihashmap_get( + contact->joined, + key + ); + + if ((! current) || + (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(contact->joined, key, current))) + return; + + GNUNET_free(current); +} + +void contact_update_key (struct GNUNET_CHAT_Contact *contact) { GNUNET_assert(contact); diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h @@ -91,6 +91,17 @@ contact_update_join (struct GNUNET_CHAT_Contact *contact, enum GNUNET_MESSENGER_MessageFlags flags); /** + * Removes local chat <i>contact</i> from a given chat + * <i>context</i>. + * + * @param[in,out] contact Chat contact + * @param[in,out] context Chat context + */ +void +contact_leave (struct GNUNET_CHAT_Contact *contact, + struct GNUNET_CHAT_Context *context); + +/** * Updates the string representation of the public key from * a given chat <i>contact</i>. * diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -31,6 +31,7 @@ #include <gnunet/gnunet_reclaim_lib.h> #include <gnunet/gnunet_reclaim_service.h> #include <gnunet/gnunet_time_lib.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -341,24 +342,23 @@ task_contact_destruction (void *cls) util_shorthash_from_member(contact->member, &shorthash); - GNUNET_CONTAINER_multishortmap_remove( - contact->handle->contacts, &shorthash, contact - ); + contact_leave (contact, contact->context); - const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( - contact->context->room + const uint32_t other_contexts = GNUNET_CONTAINER_multihashmap_size( + contact->joined ); - GNUNET_CONTAINER_multihashmap_remove( - contact->handle->contexts, key, contact->context - ); + if (0 >= other_contexts) + GNUNET_CONTAINER_multishortmap_remove( + contact->handle->contacts, &shorthash, contact + ); context_delete(contact->context, GNUNET_YES); - context_destroy(contact->context); contact->destruction = NULL; - contact_destroy(contact); + if (0 >= other_contexts) + contact_destroy(contact); } void