commit b98c7a5f62717b666d9bdaee812d2baf25d63d55
parent e184cc4fe544273d5490c314ee6724916deeba0a
Author: Jacki <jacki@thejackimonster.de>
Date: Wed, 17 Apr 2024 16:42:36 +0200
Add function to check whether a file is ready to preview
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -1402,6 +1402,16 @@ enum GNUNET_GenericReturnValue
GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file);
/**
+ * Returns if a given <i>file</i> handle is currently ready
+ * for previewing its content.
+ *
+ * @param[in] file File handle
+ * @return #GNUNET_YES when ready, #GNUNET_NO otherwise
+ */
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_file_is_ready (const struct GNUNET_CHAT_File *file);
+
+/**
* Returns the temporary file name of the decrypted file preview
* of a given <i>file</i> handle.
*
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -31,6 +31,7 @@
#include <gnunet/gnunet_scheduler_lib.h>
#include <gnunet/gnunet_time_lib.h>
#include <libgen.h>
+#include <stdint.h>
#include <string.h>
#include <strings.h>
@@ -2227,6 +2228,24 @@ GNUNET_CHAT_file_is_uploading (const struct GNUNET_CHAT_File *file)
}
+enum GNUNET_GenericReturnValue
+GNUNET_CHAT_file_is_ready (const struct GNUNET_CHAT_File *file)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if ((!file) || (file->status & GNUNET_CHAT_FILE_STATUS_MASK))
+ return GNUNET_NO;
+
+ const uint64_t size = GNUNET_CHAT_file_get_size(file);
+ const uint64_t local_size = GNUNET_CHAT_file_get_local_size(file);
+
+ if (size != local_size)
+ return GNUNET_NO;
+ else
+ return GNUNET_YES;
+}
+
+
const char*
GNUNET_CHAT_file_open_preview (struct GNUNET_CHAT_File *file)
{