libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 15e55e5dc11a3c0c4ae5c221607156a021a1fdce
parent e797c75d2f006090d123e6978a7fc2d3d1d29e89
Author: Jacki <jacki@thejackimonster.de>
Date:   Sat, 15 Jun 2024 22:21:55 +0200

Implement function to iterate discourses from chat context

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/gnunet_chat_lib.c | 23+++++++++++++++++++++++
Msrc/gnunet_chat_lib_intern.c | 23+++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -852,6 +852,29 @@ GNUNET_CHAT_iterate_files (struct GNUNET_CHAT_Handle *handle, } +int +GNUNET_CHAT_context_iterate_discourses (struct GNUNET_CHAT_Context *context, + GNUNET_CHAT_DiscourseCallback callback, + void *cls) +{ + GNUNET_CHAT_VERSION_ASSERT(); + + if ((!context) || (!(context->discourses))) + return GNUNET_SYSERR; + + struct GNUNET_CHAT_ContextIterateDiscourses it; + it.context = context; + it.cb = callback; + it.cls = cls; + + return GNUNET_CONTAINER_multishortmap_iterate( + context->discourses, + it_context_iterate_discourses, + &it + ); +} + + void GNUNET_CHAT_set_user_pointer (struct GNUNET_CHAT_Handle *handle, void *user_pointer) diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -389,6 +389,29 @@ it_context_iterate_files (void *cls, return it->cb(it->cls, it->context, file); } +struct GNUNET_CHAT_ContextIterateDiscourses +{ + struct GNUNET_CHAT_Context *context; + GNUNET_CHAT_DiscourseCallback cb; + void *cls; +}; + +enum GNUNET_GenericReturnValue +it_context_iterate_discourses (void *cls, + GNUNET_UNUSED const struct GNUNET_ShortHashCode *key, + void *value) +{ + GNUNET_assert((cls) && (value)); + + struct GNUNET_CHAT_ContextIterateDiscourses *it = cls; + struct GNUNET_CHAT_Discourse *discourse = value; + + if (!(it->cb)) + return GNUNET_YES; + + return it->cb(it->cls, it->context, discourse); +} + struct GNUNET_CHAT_MessageIterateReadReceipts { const struct GNUNET_CHAT_Message *message;