libgnunetchat

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

commit c024d2357a996afbaa6f0efa7fa6b6675212065a
parent 02f4a275a04968a889c6bae1a18caaf35cca9168
Author: Jacki <jacki@thejackimonster.de>
Date:   Mon,  6 May 2024 00:11:44 +0200

Fix message test case and leaving groups

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

Diffstat:
Msrc/gnunet_chat_context.c | 25++++++++++++++++++++++---
Msrc/gnunet_chat_context.h | 15++++++++++++++-
Msrc/gnunet_chat_handle.c | 14+++++++++-----
Msrc/gnunet_chat_lib.c | 9+++------
Msrc/gnunet_chat_lib_intern.c | 6++----
5 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c @@ -189,7 +189,8 @@ context_request_message (struct GNUNET_CHAT_Context* context, void context_update_room (struct GNUNET_CHAT_Context *context, - struct GNUNET_MESSENGER_Room *room) + struct GNUNET_MESSENGER_Room *room, + enum GNUNET_GenericReturnValue record) { GNUNET_assert(context); @@ -217,9 +218,12 @@ context_update_room (struct GNUNET_CHAT_Context *context, GNUNET_CONTAINER_multihashmap_clear(context->invites); GNUNET_CONTAINER_multihashmap_clear(context->files); + if (context->room) + context_delete(context, GNUNET_YES); + context->room = room; - if (!(context->room)) + if ((!(context->room)) || (GNUNET_YES != record)) return; context_write_records(context); @@ -227,7 +231,7 @@ context_update_room (struct GNUNET_CHAT_Context *context, void context_update_nick (struct GNUNET_CHAT_Context *context, - const char *nick) + const char *nick) { GNUNET_assert(context); @@ -484,3 +488,18 @@ skip_record_data: GNUNET_free(label); } + +void +context_delete (struct GNUNET_CHAT_Context *context, + enum GNUNET_GenericReturnValue exit) +{ + GNUNET_assert((context) && (context->room)); + + context->deleted = GNUNET_YES; + context_write_records(context); + + if (GNUNET_YES != exit) + return; + + GNUNET_MESSENGER_close_room(context->room); +} diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h @@ -115,10 +115,12 @@ context_request_message (struct GNUNET_CHAT_Context* context, * * @param[in,out] context Chat context * @param[in,out] room Messenger room + * @param[in] record Write changes to records */ void context_update_room (struct GNUNET_CHAT_Context *context, - struct GNUNET_MESSENGER_Room *room); + struct GNUNET_MESSENGER_Room *room, + enum GNUNET_GenericReturnValue record); /** * Updates the <i>nick</i> of a selected chat <i>context</i>. @@ -165,4 +167,15 @@ context_read_records (struct GNUNET_CHAT_Context *context, void context_write_records (struct GNUNET_CHAT_Context *context); +/** + * Removes the data from a selected chat <i>context</i> from + * the namestore and closes its room optionally. + * + * @param[in,out] context Chat context + * @param[in] exit Closing its room + */ +void +context_delete (struct GNUNET_CHAT_Context *context, + enum GNUNET_GenericReturnValue exit); + #endif /* GNUNET_CHAT_CONTEXT_H_ */ diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -900,8 +900,7 @@ check_type: check.contact, context))) { - context->deleted = GNUNET_YES; - context_write_records(context); + context_delete(context, GNUNET_NO); context->type = GNUNET_CHAT_CONTEXT_TYPE_CONTACT; context->deleted = GNUNET_NO; @@ -910,8 +909,7 @@ check_type: } else if (checks >= minimum_amount_of_other_members_in_group) { - context->deleted = GNUNET_YES; - context_write_records(context); + context_delete(context, GNUNET_NO); context->type = GNUNET_CHAT_CONTEXT_TYPE_GROUP; context->deleted = GNUNET_NO; @@ -1033,7 +1031,7 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, &key ); - if (context) + if ((context) && (context->room)) { context_read_records(context, label, count, data); return NULL; @@ -1047,6 +1045,12 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, if (!room) return NULL; + else if (context) + { + context_update_room(context, room, GNUNET_NO); + context_read_records(context, label, count, data); + return NULL; + } context = context_create_from_room(handle, room); context_read_records(context, label, count, data); diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -1080,11 +1080,8 @@ GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact) contact->handle->contexts, key, contact->context ); - GNUNET_MESSENGER_close_room(contact->context->room); - - contact->context->deleted = GNUNET_YES; - context_write_records(contact->context); - + context_delete(contact->context, GNUNET_YES); + context_destroy(contact->context); contact_destroy(contact); return GNUNET_OK; @@ -1567,7 +1564,7 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) if (!room) goto cleanup_contact; - context_update_room(context, room); + context_update_room(context, room, GNUNET_YES); if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( handle->contexts, &key, context, diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -294,14 +294,12 @@ task_group_destruction (void *cls) group->context->room ), sizeof(key)); - GNUNET_MESSENGER_close_room(group->context->room); - group->context->room = NULL; - GNUNET_CONTAINER_multihashmap_remove( group->handle->groups, &key, group ); - context_write_records(group->context); + context_delete(group->context, GNUNET_YES); + group->destruction = NULL; group_destroy(group);