aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-02-01 21:36:06 +0100
committerJacki <jacki@thejackimonster.de>2024-02-01 21:36:06 +0100
commita847b9eb6ee260eaa6f91916544ae3f94640e895 (patch)
tree29bdf7052305a21e50d59b789a65a738e76db937
parentcfe27d65f14f2e59d70144280db2d98972418ba2 (diff)
downloadlibgnunetchat-a847b9eb6ee260eaa6f91916544ae3f94640e895.tar.gz
libgnunetchat-a847b9eb6ee260eaa6f91916544ae3f94640e895.zip
Adjust regarding update and delete flags for messages
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--include/gnunet/gnunet_chat_lib.h7
-rw-r--r--src/gnunet_chat_handle_intern.c38
-rw-r--r--src/gnunet_chat_message.c18
-rw-r--r--src/gnunet_chat_message.h13
-rw-r--r--src/gnunet_chat_util.c2
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
@@ -107,14 +107,9 @@ enum GNUNET_CHAT_MessageKind
107 GNUNET_CHAT_KIND_FILE = 10, /**< GNUNET_CHAT_KIND_FILE */ 107 GNUNET_CHAT_KIND_FILE = 10, /**< GNUNET_CHAT_KIND_FILE */
108 108
109 /** 109 /**
110 * The kind to describe a whispered message.
111 */
112 GNUNET_CHAT_KIND_WHISPER = 11, /**< GNUNET_CHAT_KIND_WHISPER */
113
114 /**
115 * The kind to inform about a deletion of a previous message. 110 * The kind to inform about a deletion of a previous message.
116 */ 111 */
117 GNUNET_CHAT_KIND_DELETION = 12, /**< GNUNET_CHAT_KIND_DELETION */ 112 GNUNET_CHAT_KIND_DELETION = 11, /**< GNUNET_CHAT_KIND_DELETION */
118 113
119 /** 114 /**
120 * An unknown kind of message. 115 * 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)
762 message->task = NULL; 762 message->task = NULL;
763 763
764 struct GNUNET_CHAT_Context *context = message->context; 764 struct GNUNET_CHAT_Context *context = message->context;
765
766 switch (message->msg->header.kind)
767 {
768 case GNUNET_MESSENGER_KIND_DELETE:
769 {
770 struct GNUNET_CHAT_Message *target = GNUNET_CONTAINER_multihashmap_get(
771 context->messages, &(message->msg->body.deletion.hash)
772 );
773
774 if (target)
775 target->msg = NULL;
776 break;
777 }
778 default:
779 break;
780 }
781
782 struct GNUNET_CHAT_Handle *handle = context->handle; 765 struct GNUNET_CHAT_Handle *handle = context->handle;
783 766
784 if (!(handle->msg_cb)) 767 if (!(handle->msg_cb))
@@ -881,10 +864,26 @@ on_handle_message (void *cls,
881 ); 864 );
882 865
883 if (message) 866 if (message)
884 return; 867 {
868 message_update_msg (message, flags, msg);
885 869
886 struct GNUNET_SCHEDULER_Task* task = NULL; 870 if (message->flags & GNUNET_MESSENGER_FLAG_UPDATE)
871 goto handle_callback;
872 else
873 return;
874 }
875 else if (msg->header.kind == GNUNET_MESSENGER_KIND_DELETE)
876 {
877 message = GNUNET_CONTAINER_multihashmap_get(
878 context->messages, &(msg->body.deletion.hash)
879 );
887 880
881 if ((!message) || (message->msg) ||
882 (0 == (message->flags & GNUNET_MESSENGER_FLAG_DELETE)))
883 return;
884 }
885
886 struct GNUNET_SCHEDULER_Task* task = NULL;
888 message = message_create_from_msg(context, hash, flags, msg); 887 message = message_create_from_msg(context, hash, flags, msg);
889 888
890 switch (msg->header.kind) 889 switch (msg->header.kind)
@@ -987,6 +986,7 @@ on_handle_message (void *cls,
987 return; 986 return;
988 } 987 }
989 988
989handle_callback:
990 if (!task) 990 if (!task)
991 on_handle_message_callback(message); 991 on_handle_message_callback(message);
992 else 992 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 @@
23 */ 23 */
24 24
25#include "gnunet_chat_message.h" 25#include "gnunet_chat_message.h"
26#include <gnunet/gnunet_messenger_service.h>
26 27
27struct GNUNET_CHAT_Message* 28struct GNUNET_CHAT_Message*
28message_create_from_msg (struct GNUNET_CHAT_Context *context, 29message_create_from_msg (struct GNUNET_CHAT_Context *context,
@@ -66,6 +67,23 @@ message_create_internally (struct GNUNET_CHAT_Context *context,
66} 67}
67 68
68void 69void
70message_update_msg (struct GNUNET_CHAT_Message* message,
71 enum GNUNET_MESSENGER_MessageFlags flags,
72 const struct GNUNET_MESSENGER_Message *msg)
73{
74 GNUNET_assert(message);
75
76 if (flags & GNUNET_MESSENGER_FLAG_UPDATE)
77 message->msg = msg;
78 else if (flags & GNUNET_MESSENGER_FLAG_DELETE)
79 message->msg = NULL;
80 else
81 return;
82
83 message->flags = flags | GNUNET_MESSENGER_FLAG_UPDATE;
84}
85
86void
69message_destroy (struct GNUNET_CHAT_Message* message) 87message_destroy (struct GNUNET_CHAT_Message* message)
70{ 88{
71 GNUNET_assert(message); 89 GNUNET_assert(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
@@ -96,6 +96,19 @@ message_create_internally (struct GNUNET_CHAT_Context *context,
96 const char *warning); 96 const char *warning);
97 97
98/** 98/**
99 * Updates a chat message representing an actual message
100 * from the messenger service.
101 *
102 * @param[in,out] message Chat message
103 * @param[in] flags Message flags
104 * @param[in] msg Messenger message
105 */
106void
107message_update_msg (struct GNUNET_CHAT_Message* message,
108 enum GNUNET_MESSENGER_MessageFlags flags,
109 const struct GNUNET_MESSENGER_Message *msg);
110
111/**
99 * Destroys a chat <i>message</i> and frees its memory. 112 * Destroys a chat <i>message</i> and frees its memory.
100 * 113 *
101 * @param[in,out] message Chat message 114 * @param[in,out] message Chat message
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)
417 return GNUNET_CHAT_KIND_TEXT; 417 return GNUNET_CHAT_KIND_TEXT;
418 case GNUNET_MESSENGER_KIND_FILE: 418 case GNUNET_MESSENGER_KIND_FILE:
419 return GNUNET_CHAT_KIND_FILE; 419 return GNUNET_CHAT_KIND_FILE;
420 case GNUNET_MESSENGER_KIND_PRIVATE:
421 return GNUNET_CHAT_KIND_WHISPER;
422 case GNUNET_MESSENGER_KIND_DELETE: 420 case GNUNET_MESSENGER_KIND_DELETE:
423 return GNUNET_CHAT_KIND_DELETION; 421 return GNUNET_CHAT_KIND_DELETION;
424 case GNUNET_MESSENGER_KIND_TICKET: 422 case GNUNET_MESSENGER_KIND_TICKET: