From 69176480c5ff9faad872d2aad68a5780c2f364b5 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Sat, 19 Mar 2022 17:25:29 +0100 Subject: Add private messages as whispering Signed-off-by: TheJackiMonster --- include/gnunet_chat_lib.h | 7 ++++++- src/gnunet_chat_lib.c | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 91cd9b6..6610f59 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h @@ -96,10 +96,15 @@ 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 = 11, /**< GNUNET_CHAT_KIND_DELETION */ + GNUNET_CHAT_KIND_DELETION = 12, /**< GNUNET_CHAT_KIND_DELETION */ /** * An unknown kind of message. diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index fd82ba3..2632fb5 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c @@ -1169,6 +1169,8 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) 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; default: -- cgit v1.2.3 From eec5d26ea19d234de7abe167ab42785620f1bd55 Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Sat, 19 Mar 2022 19:59:53 +0100 Subject: Add sending read receipts Signed-off-by: TheJackiMonster --- include/gnunet_chat_lib.h | 12 ++++++++++++ src/gnunet_chat_lib.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 6610f59..a434381 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h @@ -813,6 +813,18 @@ int GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, const char *text); +/** + * Sends a read receipt depending on a selected message into a given + * chat context. + * + * @param[in,out] context Chat context + * @param[in] message Message (optional) + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure + */ +int +GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message); + /** * Uploads a local file specified via its path using symmetric encryption * and shares the regarding information to download and decrypt it in a given diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 2632fb5..e11c92d 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c @@ -925,6 +925,51 @@ GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, } +int +GNUNET_CHAT_context_send_read_receipt (struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + if ((!context) || (!(context->room))) + return GNUNET_SYSERR; + + char zero = '\0'; + struct GNUNET_MESSENGER_Message msg; + msg.header.kind = GNUNET_MESSENGER_KIND_TEXT; + msg.body.text.text = &zero; + + const struct GNUNET_MESSENGER_Contact *receiver = NULL; + + if (!message) + goto skip_filter; + + if (GNUNET_CHAT_FLAG_NONE != message->flag) + return GNUNET_SYSERR; + + if (message->flags & GNUNET_MESSENGER_FLAG_SENT) + return GNUNET_OK; + + if (message->flags & GNUNET_MESSENGER_FLAG_PRIVATE) + { + receiver = GNUNET_MESSENGER_get_sender(context->room, &(message->hash)); + + if (!receiver) + return GNUNET_SYSERR; + } + + if ((!(message->msg)) || + (GNUNET_MESSENGER_KIND_TEXT != message->msg->header.kind)) + goto skip_filter; + + if ((!(message->msg->body.text.text)) || + (!(message->msg->body.text.text[0]))) + return GNUNET_SYSERR; + +skip_filter: + GNUNET_MESSENGER_send_message(context->room, &msg, receiver); + return GNUNET_OK; +} + + struct GNUNET_CHAT_File* GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, const char *path, -- cgit v1.2.3