commit 9f5f98ea13aafc08c3444585b788789ade61bb1f
parent 5dc6434881b15973742d403cd7ca0cd11f2ade28
Author: Jacki <jacki@thejackimonster.de>
Date: Sat, 10 Feb 2024 05:04:49 +0100
Handle logout of account
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
4 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
@@ -24,20 +24,9 @@
#include "messenger.h"
-#include "../contact.h"
#include "../event.h"
#include <gnunet/gnunet_chat_lib.h>
-int
-_chat_messenger_destroy_contacts(UNUSED void *cls,
- UNUSED struct GNUNET_CHAT_Handle *handle,
- struct GNUNET_CHAT_Contact *contact)
-{
- if (contact)
- contact_destroy_info(contact);
- return GNUNET_YES;
-}
-
static void
_chat_messenger_quit(void *cls)
{
@@ -52,13 +41,7 @@ _chat_messenger_quit(void *cls)
if (received < 0)
signal = MESSENGER_FAIL;
- // Free contact infos
- GNUNET_CHAT_iterate_contacts(
- app->chat.messenger.handle,
- _chat_messenger_destroy_contacts,
- NULL
- );
-
+ GNUNET_CHAT_disconnect(app->chat.messenger.handle);
GNUNET_CHAT_stop(app->chat.messenger.handle);
app->chat.messenger.handle = NULL;
@@ -111,6 +94,11 @@ _chat_messenger_message(void *cls,
application_call_event(app, event_update_profile);
break;
}
+ case GNUNET_CHAT_KIND_LOGOUT:
+ {
+ application_call_event(app, event_cleanup_profile);
+ break;
+ }
case GNUNET_CHAT_KIND_UPDATE:
{
application_call_message_event(
diff --git a/src/event.c b/src/event.c
@@ -332,6 +332,24 @@ event_update_profile(MESSENGER_Application *app)
GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app);
}
+static int
+_cleanup_profile_contacts(void *cls,
+ UNUSED struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_CHAT_Contact *contact)
+{
+ if (contact)
+ contact_destroy_info(contact);
+ return GNUNET_YES;
+}
+
+void
+event_cleanup_profile(MESSENGER_Application *app)
+{
+ CHAT_MESSENGER_Handle *chat = &(app->chat.messenger);
+
+ GNUNET_CHAT_iterate_contacts(chat->handle, _cleanup_profile_contacts, NULL);
+}
+
gboolean
_delayed_context_drop(gpointer user_data)
{
diff --git a/src/event.h b/src/event.h
@@ -61,6 +61,15 @@ void
event_update_profile(MESSENGER_Application *app);
/**
+ * Event for the UI to be called whenever the user
+ * disconnects the current account.
+ *
+ * @param app Messenger application
+ */
+void
+event_cleanup_profile(MESSENGER_Application *app);
+
+/**
* Event for the UI to be called whenever a the user
* joins or leaves a chat (context) via message.
*
diff --git a/src/ui/messenger.c b/src/ui/messenger.c
@@ -138,6 +138,13 @@ handle_accounts_listbox_row_activated(UNUSED GtkListBox* listbox,
if (!account)
return;
+ const struct GNUNET_CHAT_Account *current = GNUNET_CHAT_get_connected(
+ app->chat.messenger.handle
+ );
+
+ if (account == current)
+ return;
+
_switch_details_revealer_visibility(&(app->ui.messenger), FALSE);
hdy_flap_set_reveal_flap(HDY_FLAP(app->ui.messenger.flap_user_details), FALSE);