commit ec977be81531d3efffc0c4424ec00cb1c5313e6a
parent 35e3ee46594914fd651d82120772d051a8f5535a
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Sat, 17 Feb 2024 19:52:49 +0100
Handle message deletion with updated callback of original message
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
4 files changed, 71 insertions(+), 8 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -1178,6 +1178,29 @@ enum GNUNET_GenericReturnValue
GNUNET_CHAT_message_is_recent (const struct GNUNET_CHAT_Message *message);
/**
+ * Returns #GNUNET_YES if the message was received because of an update by
+ * related chat handle, otherwise it returns #GNUNET_NO.
+ *
+ * @param[in] message Message
+ * @return #GNUNET_YES if the message was received to update
+ * a previous message, otherwise #GNUNET_NO
+ */
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_message_is_update (const struct GNUNET_CHAT_Message *message);
+
+/**
+ * Returns #GNUNET_YES if the message was received because of a deletion by
+ * related chat handle or if it has been deleted internally, otherwise it
+ * returns #GNUNET_NO.
+ *
+ * @param[in] message Message
+ * @return #GNUNET_YES if the message was received to delete
+ * a previous message, otherwise #GNUNET_NO
+ */
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_message_is_deleted (const struct GNUNET_CHAT_Message *message);
+
+/**
* Iterates through the contacts of the context related to a given chat
* <i>message</i> to check whether it was received by each of the contacts.
*
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -839,6 +839,9 @@ on_handle_message_callback(void *cls)
struct GNUNET_CHAT_Context *context = message->context;
struct GNUNET_CHAT_Handle *handle = context->handle;
+ if (GNUNET_MESSENGER_FLAG_UPDATE & message->flags)
+ goto skip_msg_handing;
+
switch (message->msg->header.kind)
{
case GNUNET_MESSENGER_KIND_INVITE:
@@ -892,11 +895,9 @@ on_handle_message_callback(void *cls)
break;
}
- if (!(handle->msg_cb))
- goto clear_dependencies;
-
- const struct GNUNET_MESSENGER_Contact *sender;
- sender = GNUNET_MESSENGER_get_sender(context->room, &(message->hash));
+skip_msg_handing:
+ const struct GNUNET_MESSENGER_Contact *sender = GNUNET_MESSENGER_get_sender(
+ context->room, &(message->hash));
if (!sender)
goto clear_dependencies;
@@ -911,6 +912,9 @@ on_handle_message_callback(void *cls)
if (!contact)
goto clear_dependencies;
+ if (GNUNET_MESSENGER_FLAG_UPDATE & message->flags)
+ goto skip_sender_handing;
+
switch (message->msg->header.kind)
{
case GNUNET_MESSENGER_KIND_JOIN:
@@ -955,9 +959,16 @@ on_handle_message_callback(void *cls)
break;
}
+skip_sender_handing:
+ if (!(handle->msg_cb))
+ goto clear_dependencies;
+
handle->msg_cb(handle->msg_cls, context, message);
clear_dependencies:
+ if (GNUNET_MESSENGER_FLAG_DELETE & message->flags)
+ message->msg = NULL;
+
GNUNET_CONTAINER_multihashmap_get_multiple(context->dependencies,
&(message->hash),
it_context_iterate_dependencies,
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -1761,6 +1761,38 @@ GNUNET_CHAT_message_is_recent (const struct GNUNET_CHAT_Message *message)
}
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_message_is_update (const struct GNUNET_CHAT_Message *message)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if (!message)
+ return GNUNET_SYSERR;
+
+ if (message->flags & GNUNET_MESSENGER_FLAG_UPDATE)
+ return GNUNET_YES;
+ else
+ return GNUNET_NO;
+}
+
+
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_message_is_deleted (const struct GNUNET_CHAT_Message *message)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if (!message)
+ return GNUNET_SYSERR;
+
+ if ((GNUNET_CHAT_FLAG_NONE == message->flag) &&
+ ((message->flags & GNUNET_MESSENGER_FLAG_DELETE) ||
+ (!message->msg)))
+ return GNUNET_YES;
+ else
+ return GNUNET_NO;
+}
+
+
int
GNUNET_CHAT_message_get_read_receipt (const struct GNUNET_CHAT_Message *message,
GNUNET_CHAT_MessageReadReceiptCallback callback,
diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c
@@ -95,10 +95,7 @@ message_update_msg (struct GNUNET_CHAT_Message* message,
if (flags & GNUNET_MESSENGER_FLAG_UPDATE)
message->msg = msg;
else if (flags & GNUNET_MESSENGER_FLAG_DELETE)
- {
context_delete_message(message->context, message);
- message->msg = NULL;
- }
else
return;