commit 0b6678f50cbed14b5ff6159845f6ee1289cb8f90
parent 6248987bdc93db47fc80737254231359d49e0131
Author: Jacki <jacki@thejackimonster.de>
Date: Fri, 26 Apr 2024 13:54:49 +0200
Add function to query account responsible for a chat message
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
11 files changed, 81 insertions(+), 10 deletions(-)
diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h
@@ -1410,6 +1410,16 @@ GNUNET_CHAT_message_get_read_receipt (const struct GNUNET_CHAT_Message *message,
const char*
GNUNET_CHAT_message_get_text (const struct GNUNET_CHAT_Message *message);
+/**
+ * Returns the account of a given <i>message</i> which is either
+ * its sender or target of the message depending on the kind of
+ * the message, otherwise it returns NULL.
+ *
+ * @param[in] message Message
+ * @return The account of message or NULL
+ */
+const struct GNUNET_CHAT_Account*
+GNUNET_CHAT_message_get_account (const struct GNUNET_CHAT_Message *message);
/**
* Returns the file handle of a given <i>message</i> if its kind is
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
@@ -241,6 +241,7 @@ context_update_nick (struct GNUNET_CHAT_Context *context,
handle_send_internal_message(
context->handle,
+ NULL,
context,
GNUNET_CHAT_FLAG_UPDATE,
NULL
diff --git a/src/gnunet_chat_context_intern.c b/src/gnunet_chat_context_intern.c
@@ -136,6 +136,7 @@ cont_context_write_records (void *cls,
if (GNUNET_EC_NONE != ec)
handle_send_internal_message(
context->handle,
+ NULL,
context,
GNUNET_CHAT_FLAG_WARNING,
GNUNET_ErrorCode_get_hint(ec)
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -283,6 +283,7 @@ handle_update_identity(struct GNUNET_CHAT_Handle *handle)
{
GNUNET_assert(
(handle) &&
+ (handle->current) &&
(handle->contexts) &&
(handle->groups) &&
(handle->contacts)
@@ -299,6 +300,7 @@ handle_update_identity(struct GNUNET_CHAT_Handle *handle)
handle_send_internal_message(
handle,
+ handle->current,
NULL,
GNUNET_CHAT_FLAG_LOGIN,
NULL
@@ -378,6 +380,7 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle)
handle_send_internal_message(
handle,
+ handle->current,
NULL,
GNUNET_CHAT_FLAG_LOGOUT,
NULL
@@ -777,6 +780,7 @@ handle_get_key (const struct GNUNET_CHAT_Handle *handle)
void
handle_send_internal_message (struct GNUNET_CHAT_Handle *handle,
+ const struct GNUNET_CHAT_Account *account,
struct GNUNET_CHAT_Context *context,
enum GNUNET_CHAT_MessageFlag flag,
const char *warning)
@@ -791,7 +795,7 @@ handle_send_internal_message (struct GNUNET_CHAT_Handle *handle,
);
internal->msg = message_create_internally(
- context, flag, warning
+ account, context, flag, warning
);
if (!(internal->msg))
@@ -938,6 +942,7 @@ setup_group:
{
handle_send_internal_message(
handle,
+ NULL,
context,
GNUNET_CHAT_FLAG_UPDATE,
NULL
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
@@ -95,7 +95,7 @@ struct GNUNET_CHAT_UriLookups
struct GNUNET_CHAT_AttributeProcess
{
const struct GNUNET_CHAT_Account *account;
-
+
struct GNUNET_CHAT_Handle *handle;
struct GNUNET_CHAT_Contact *contact;
@@ -325,16 +325,19 @@ handle_get_key (const struct GNUNET_CHAT_Handle *handle);
/**
* Sends an internal chat message from a given chat
- * <i>handle</i> with an optional chat <i>context</i>,
- * a custom <i>flag</i> and an optional <i>warning</i> text.
+ * <i>handle</i> with an optional chat <i>account</i> or
+ * <i>context</i>, a custom <i>flag</i> and an optional
+ * <i>warning</i> text.
*
* @param[in,out] handle Chat handle
+ * @param[in] account Chat account or NULL
* @param[in,out] context Chat context or NULL
* @param[in] flag Chat message flag
* @param[in] warning Warning text
*/
void
handle_send_internal_message (struct GNUNET_CHAT_Handle *handle,
+ const struct GNUNET_CHAT_Account *account,
struct GNUNET_CHAT_Context *context,
enum GNUNET_CHAT_MessageFlag flag,
const char *warning);
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -307,6 +307,7 @@ on_handle_gnunet_identity (void *cls,
if (handle->current == accounts->account)
handle_send_internal_message(
handle,
+ accounts->account,
NULL,
GNUNET_CHAT_FLAG_LOGIN,
NULL
@@ -372,7 +373,13 @@ skip_account:
);
send_refresh:
- handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL);
+ handle_send_internal_message(
+ handle,
+ NULL,
+ NULL,
+ GNUNET_CHAT_FLAG_REFRESH,
+ NULL
+ );
}
void
@@ -387,6 +394,7 @@ cb_account_creation (void *cls,
);
struct GNUNET_CHAT_Handle *handle = accounts->handle;
+ struct GNUNET_CHAT_Account *account = accounts->account;
GNUNET_CONTAINER_DLL_remove(
handle->accounts_head,
@@ -403,6 +411,7 @@ cb_account_creation (void *cls,
{
handle_send_internal_message(
handle,
+ account,
NULL,
GNUNET_CHAT_FLAG_WARNING,
GNUNET_ErrorCode_get_hint(ec)
@@ -411,7 +420,13 @@ cb_account_creation (void *cls,
return;
}
else if (key)
- handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL);
+ handle_send_internal_message(
+ handle,
+ NULL,
+ NULL,
+ GNUNET_CHAT_FLAG_REFRESH,
+ NULL
+ );
}
void
@@ -425,6 +440,7 @@ cb_account_deletion (void *cls,
);
struct GNUNET_CHAT_Handle *handle = accounts->handle;
+ struct GNUNET_CHAT_Account *account = accounts->account;
GNUNET_CONTAINER_DLL_remove(
handle->accounts_head,
@@ -441,6 +457,7 @@ cb_account_deletion (void *cls,
{
handle_send_internal_message(
handle,
+ account,
NULL,
GNUNET_CHAT_FLAG_WARNING,
GNUNET_ErrorCode_get_hint(ec)
@@ -461,6 +478,7 @@ cb_account_rename (void *cls,
);
struct GNUNET_CHAT_Handle *handle = accounts->handle;
+ struct GNUNET_CHAT_Account *account = accounts->account;
GNUNET_CONTAINER_DLL_remove(
handle->accounts_head,
@@ -477,6 +495,7 @@ cb_account_rename (void *cls,
{
handle_send_internal_message(
handle,
+ account,
NULL,
GNUNET_CHAT_FLAG_WARNING,
GNUNET_ErrorCode_get_hint(ec)
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -2253,6 +2253,21 @@ GNUNET_CHAT_message_get_text (const struct GNUNET_CHAT_Message *message)
}
+const struct GNUNET_CHAT_Account*
+GNUNET_CHAT_message_get_account (const struct GNUNET_CHAT_Message *message)
+{
+ GNUNET_CHAT_VERSION_ASSERT();
+
+ if (!message)
+ return NULL;
+
+ if ((message->context) && (message->context->handle))
+ return message->context->handle->current;
+ else
+ return message->account;
+}
+
+
struct GNUNET_CHAT_File*
GNUNET_CHAT_message_get_file (const struct GNUNET_CHAT_Message *message)
{
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
@@ -444,7 +444,9 @@ cont_update_attribute_with_status (void *cls,
attributes->op = NULL;
+ const struct GNUNET_CHAT_Account *account = attributes->account;
struct GNUNET_CHAT_Handle *handle = attributes->handle;
+
const char *attribute_name = NULL;
if (attributes->attribute)
@@ -453,6 +455,7 @@ cont_update_attribute_with_status (void *cls,
if (GNUNET_SYSERR == success)
handle_send_internal_message(
handle,
+ account,
NULL,
GNUNET_CHAT_KIND_WARNING,
emsg
@@ -460,6 +463,7 @@ cont_update_attribute_with_status (void *cls,
else
handle_send_internal_message(
handle,
+ account,
NULL,
GNUNET_CHAT_FLAG_ATTRIBUTES,
attribute_name
@@ -544,6 +548,7 @@ cb_task_error_iterate_attribute (void *cls)
handle_send_internal_message(
attributes->handle,
+ attributes->account,
NULL,
GNUNET_CHAT_FLAG_WARNING,
"Attribute iteration failed!"
@@ -897,6 +902,7 @@ cb_task_error_iterate_ticket (void *cls)
handle_send_internal_message(
tickets->handle,
NULL,
+ NULL,
GNUNET_CHAT_FLAG_WARNING,
"Ticket iteration failed!"
);
@@ -921,6 +927,7 @@ cont_revoke_ticket (void *cls,
handle_send_internal_message(
handle,
NULL,
+ NULL,
GNUNET_CHAT_FLAG_WARNING,
emsg
);
@@ -928,6 +935,7 @@ cont_revoke_ticket (void *cls,
handle_send_internal_message(
handle,
NULL,
+ NULL,
GNUNET_CHAT_FLAG_SHARED_ATTRIBUTES,
NULL
);
diff --git a/src/gnunet_chat_lobby_intern.c b/src/gnunet_chat_lobby_intern.c
@@ -53,6 +53,7 @@ cont_lobby_write_records (void *cls,
handle_send_internal_message(
lobby->handle,
+ NULL,
lobby->context,
GNUNET_CHAT_FLAG_WARNING,
GNUNET_ErrorCode_get_hint(ec)
@@ -83,6 +84,7 @@ cont_lobby_identity_create (void *cls,
{
handle_send_internal_message(
lobby->handle,
+ NULL,
lobby->context,
GNUNET_CHAT_FLAG_WARNING,
GNUNET_ErrorCode_get_hint(ec)
diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c
@@ -37,6 +37,7 @@ message_create_from_msg (struct GNUNET_CHAT_Context *context,
struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message);
+ message->account = NULL;
message->context = context;
message->task = NULL;
@@ -50,12 +51,14 @@ message_create_from_msg (struct GNUNET_CHAT_Context *context,
}
struct GNUNET_CHAT_Message*
-message_create_internally (struct GNUNET_CHAT_Context *context,
+message_create_internally (const struct GNUNET_CHAT_Account *account,
+ struct GNUNET_CHAT_Context *context,
enum GNUNET_CHAT_MessageFlag flag,
const char *warning)
{
struct GNUNET_CHAT_Message *message = GNUNET_new(struct GNUNET_CHAT_Message);
+ message->account = account;
message->context = context;
message->task = NULL;
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h
@@ -54,6 +54,8 @@ enum GNUNET_CHAT_MessageFlag
struct GNUNET_CHAT_Message
{
+ const struct GNUNET_CHAT_Account *account;
+
struct GNUNET_CHAT_Context *context;
struct GNUNET_SCHEDULER_Task *task;
@@ -87,16 +89,18 @@ message_create_from_msg (struct GNUNET_CHAT_Context *context,
/**
* Creates an internal chat message with an optional chat
- * <i>context</i>, a custom <i>flag</i> and an optional
- * <i>warning</i> text.
+ * <i>account</i> or <i>context</i>, a custom <i>flag</i>
+ * and an optional <i>warning</i> text.
*
+ * @param[in] account Chat account or NULL
* @param[in,out] context Chat context or NULL
* @param[in] flag Chat message flag
* @param[in] warning Warning text
* @return New internal chat message
*/
struct GNUNET_CHAT_Message*
-message_create_internally (struct GNUNET_CHAT_Context *context,
+message_create_internally (const struct GNUNET_CHAT_Account *account,
+ struct GNUNET_CHAT_Context *context,
enum GNUNET_CHAT_MessageFlag flag,
const char *warning);