libgnunetchat

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

commit a847b9eb6ee260eaa6f91916544ae3f94640e895
parent cfe27d65f14f2e59d70144280db2d98972418ba2
Author: Jacki <jacki@thejackimonster.de>
Date:   Thu,  1 Feb 2024 21:36:06 +0100

Adjust regarding update and delete flags for messages

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

Diffstat:
Minclude/gnunet/gnunet_chat_lib.h | 7+------
Msrc/gnunet_chat_handle_intern.c | 38+++++++++++++++++++-------------------
Msrc/gnunet_chat_message.c | 18++++++++++++++++++
Msrc/gnunet_chat_message.h | 13+++++++++++++
Msrc/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 @@ -107,14 +107,9 @@ 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 @@ -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 @@ -23,6 +23,7 @@ */ #include "gnunet_chat_message.h" +#include <gnunet/gnunet_messenger_service.h> struct GNUNET_CHAT_Message* message_create_from_msg (struct GNUNET_CHAT_Context *context, @@ -66,6 +67,23 @@ message_create_internally (struct GNUNET_CHAT_Context *context, } 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) { GNUNET_assert(message); diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h @@ -96,6 +96,19 @@ message_create_internally (struct GNUNET_CHAT_Context *context, 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 <i>message</i> and frees its memory. * * @param[in,out] message Chat message diff --git 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: