From a847b9eb6ee260eaa6f91916544ae3f94640e895 Mon Sep 17 00:00:00 2001 From: Jacki Date: Thu, 1 Feb 2024 21:36:06 +0100 Subject: Adjust regarding update and delete flags for messages Signed-off-by: Jacki --- include/gnunet/gnunet_chat_lib.h | 7 +------ src/gnunet_chat_handle_intern.c | 38 +++++++++++++++++++------------------- src/gnunet_chat_message.c | 18 ++++++++++++++++++ src/gnunet_chat_message.h | 13 +++++++++++++ src/gnunet_chat_util.c | 2 -- 5 files changed, 51 insertions(+), 27 deletions(-) diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h index b8a5956..cf55456 100644 --- a/include/gnunet/gnunet_chat_lib.h +++ b/include/gnunet/gnunet_chat_lib.h @@ -106,15 +106,10 @@ enum GNUNET_CHAT_MessageKind */ GNUNET_CHAT_KIND_FILE = 10, /**< GNUNET_CHAT_KIND_FILE */ - /** - * The kind to describe a whispered message. - */ - GNUNET_CHAT_KIND_WHISPER = 11, /**< GNUNET_CHAT_KIND_WHISPER */ - /** * The kind to inform about a deletion of a previous message. */ - GNUNET_CHAT_KIND_DELETION = 12, /**< GNUNET_CHAT_KIND_DELETION */ + GNUNET_CHAT_KIND_DELETION = 11, /**< GNUNET_CHAT_KIND_DELETION */ /** * An unknown kind of message. diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index dee178a..8f45d71 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c @@ -762,23 +762,6 @@ on_handle_message_callback(void *cls) message->task = NULL; struct GNUNET_CHAT_Context *context = message->context; - - switch (message->msg->header.kind) - { - case GNUNET_MESSENGER_KIND_DELETE: - { - struct GNUNET_CHAT_Message *target = GNUNET_CONTAINER_multihashmap_get( - context->messages, &(message->msg->body.deletion.hash) - ); - - if (target) - target->msg = NULL; - break; - } - default: - break; - } - struct GNUNET_CHAT_Handle *handle = context->handle; if (!(handle->msg_cb)) @@ -881,10 +864,26 @@ on_handle_message (void *cls, ); if (message) - return; + { + message_update_msg (message, flags, msg); - struct GNUNET_SCHEDULER_Task* task = NULL; + if (message->flags & GNUNET_MESSENGER_FLAG_UPDATE) + goto handle_callback; + else + return; + } + else if (msg->header.kind == GNUNET_MESSENGER_KIND_DELETE) + { + message = GNUNET_CONTAINER_multihashmap_get( + context->messages, &(msg->body.deletion.hash) + ); + if ((!message) || (message->msg) || + (0 == (message->flags & GNUNET_MESSENGER_FLAG_DELETE))) + return; + } + + struct GNUNET_SCHEDULER_Task* task = NULL; message = message_create_from_msg(context, hash, flags, msg); switch (msg->header.kind) @@ -987,6 +986,7 @@ on_handle_message (void *cls, return; } +handle_callback: if (!task) on_handle_message_callback(message); else diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c index 49260f9..f5c18f7 100644 --- a/src/gnunet_chat_message.c +++ b/src/gnunet_chat_message.c @@ -23,6 +23,7 @@ */ #include "gnunet_chat_message.h" +#include struct GNUNET_CHAT_Message* message_create_from_msg (struct GNUNET_CHAT_Context *context, @@ -65,6 +66,23 @@ message_create_internally (struct GNUNET_CHAT_Context *context, return message; } +void +message_update_msg (struct GNUNET_CHAT_Message* message, + enum GNUNET_MESSENGER_MessageFlags flags, + const struct GNUNET_MESSENGER_Message *msg) +{ + GNUNET_assert(message); + + if (flags & GNUNET_MESSENGER_FLAG_UPDATE) + message->msg = msg; + else if (flags & GNUNET_MESSENGER_FLAG_DELETE) + message->msg = NULL; + else + return; + + message->flags = flags | GNUNET_MESSENGER_FLAG_UPDATE; +} + void message_destroy (struct GNUNET_CHAT_Message* message) { diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h index 5775856..f35a60a 100644 --- a/src/gnunet_chat_message.h +++ b/src/gnunet_chat_message.h @@ -95,6 +95,19 @@ message_create_internally (struct GNUNET_CHAT_Context *context, enum GNUNET_CHAT_MessageFlag flag, const char *warning); +/** + * Updates a chat message representing an actual message + * from the messenger service. + * + * @param[in,out] message Chat message + * @param[in] flags Message flags + * @param[in] msg Messenger message + */ +void +message_update_msg (struct GNUNET_CHAT_Message* message, + enum GNUNET_MESSENGER_MessageFlags flags, + const struct GNUNET_MESSENGER_Message *msg); + /** * Destroys a chat message and frees its memory. * diff --git a/src/gnunet_chat_util.c b/src/gnunet_chat_util.c index bce5dae..bcf29c9 100644 --- a/src/gnunet_chat_util.c +++ b/src/gnunet_chat_util.c @@ -417,8 +417,6 @@ util_message_kind_from_kind (enum GNUNET_MESSENGER_MessageKind kind) return GNUNET_CHAT_KIND_TEXT; case GNUNET_MESSENGER_KIND_FILE: return GNUNET_CHAT_KIND_FILE; - case GNUNET_MESSENGER_KIND_PRIVATE: - return GNUNET_CHAT_KIND_WHISPER; case GNUNET_MESSENGER_KIND_DELETE: return GNUNET_CHAT_KIND_DELETION; case GNUNET_MESSENGER_KIND_TICKET: -- cgit v1.2.3