From 24ebc1a6e2ef727c1ceee2da47834c0737e1745e Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Sat, 20 Jan 2024 10:51:00 +0100 Subject: MESSENGER: Add function to delete messages Signed-off-by: TheJackiMonster --- src/include/gnunet_messenger_service.h | 16 ++++++++++++++++ src/service/messenger/messenger_api.c | 24 +++++++++++++++++++++++- src/service/messenger/messenger_api_message.c | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index e0ccea27a..8e1cd666d 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h @@ -956,6 +956,22 @@ GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_Contact *contact); +/** + * Delete a message identified by its hash from a room. A deletion will be propagated to all members + * of the room as with any other sent message. Notice that a deletion will only request other members of the room + * to delete the selected message. If you are not permitted to delete the message, the deletion will be ignored. + * + * Depending on the implementation other clients may also ignore your deletion request in other circumstances. + * + * @param[in,out] room Room handle + * @param[in] message Message to delete + * @param[in] delay Delay to delete the message + */ +void +GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash, + const struct GNUNET_TIME_Relative delay); + /** * Get the message in a room identified by its hash. * diff --git a/src/service/messenger/messenger_api.c b/src/service/messenger/messenger_api.c index 2981b1a71..1756ac91b 100644 --- a/src/service/messenger/messenger_api.c +++ b/src/service/messenger/messenger_api.c @@ -30,6 +30,7 @@ #include "gnunet-service-messenger.h" #include "gnunet_reclaim_service.h" +#include "gnunet_time_lib.h" #include "messenger_api_contact.h" #include "messenger_api_contact_store.h" #include "messenger_api_handle.h" @@ -1209,7 +1210,28 @@ GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, else public_key = NULL; - send_message_to_room_with_key (room, copy_message(message), public_key); + send_message_to_room_with_key (room, copy_message(message), NULL); +} + + +void +GNUNET_MESSENGER_delete_message (struct GNUNET_MESSENGER_Room *room, + const struct GNUNET_HashCode *hash, + const struct GNUNET_TIME_Relative delay) +{ + if ((! room) || (! hash)) + return; + + struct GNUNET_MESSENGER_Message *message = create_message_delete(hash, delay); + + if (! message) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Sending deletion aborted: Message creation failed!\n"); + return; + } + + send_message_to_room_with_key (room, message, NULL); } diff --git a/src/service/messenger/messenger_api_message.c b/src/service/messenger/messenger_api_message.c index 884adabed..f6d8c31f7 100644 --- a/src/service/messenger/messenger_api_message.c +++ b/src/service/messenger/messenger_api_message.c @@ -1312,7 +1312,7 @@ filter_message_sending (const struct GNUNET_MESSENGER_Message *message) case GNUNET_MESSENGER_KIND_PRIVATE: return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead! case GNUNET_MESSENGER_KIND_DELETE: - return GNUNET_YES; + return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead! case GNUNET_MESSENGER_KIND_CONNECTION: return GNUNET_SYSERR; // Reserved for connection handling only! case GNUNET_MESSENGER_KIND_TICKET: -- cgit v1.2.3