From 36f2569e53e67fda6023c5ec5f6a7714cbce1946 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Fri, 22 May 2020 16:18:28 +0200 Subject: Preserve Gajims minimize flag in bookmarks Implement https://github.com/profanity-im/profanity/issues/1326 --- src/xmpp/bookmark.c | 35 ++++++++++++++++++++++++++++++++++- src/xmpp/stanza.h | 2 ++ src/xmpp/xmpp.h | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src/xmpp') diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index e546ef18..a4ca6309 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -301,11 +301,23 @@ _bookmark_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) } const char *autojoin = xmpp_stanza_get_attribute(child, "autojoin"); - gboolean autojoin_val = FALSE;; + gboolean autojoin_val = FALSE; if (autojoin && (strcmp(autojoin, "1") == 0 || strcmp(autojoin, "true") == 0)) { autojoin_val = TRUE; } + // we save minimize, which is not standard, so that we don't remove it if it was set by gajim + int minimize = 0; + xmpp_stanza_t *minimize_st = stanza_get_child_by_name_and_ns(child, STANZA_NAME_MINIMIZE, STANZA_NS_EXT_GAJIM_BOOKMARKS); + if (minimize_st) { + char *min_str = xmpp_stanza_get_text(minimize_st); + if (strcmp(min_str, "true") == 0) { + minimize = 1; + } else if (strcmp(min_str, "false") == 0) { + minimize = 2; + } + } + autocomplete_add(bookmark_ac, barejid); Bookmark *bookmark = malloc(sizeof(Bookmark)); bookmark->barejid = strdup(barejid); @@ -313,6 +325,7 @@ _bookmark_result_id_handler(xmpp_stanza_t *const stanza, void *const userdata) bookmark->password = password; bookmark->name = room_name ? strdup(room_name) : NULL; bookmark->autojoin = autojoin_val; + bookmark->ext_gajim_minimize = minimize; g_hash_table_insert(bookmarks, strdup(barejid), bookmark); if (autojoin_val) { @@ -410,6 +423,26 @@ _send_bookmarks(void) xmpp_stanza_release(password_st); } + if (bookmark->ext_gajim_minimize == 1 || + bookmark->ext_gajim_minimize == 2) { + xmpp_stanza_t *minimize_st = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(minimize_st, STANZA_NAME_MINIMIZE); + xmpp_stanza_set_ns(minimize_st, STANZA_NS_EXT_GAJIM_BOOKMARKS); + + xmpp_stanza_t *minimize_text = xmpp_stanza_new(ctx); + if (bookmark->ext_gajim_minimize == 1) { + xmpp_stanza_set_text(minimize_text, "true"); + } else { + xmpp_stanza_set_text(minimize_text, "false"); + } + + xmpp_stanza_add_child(minimize_st, minimize_text); + xmpp_stanza_add_child(conference, minimize_st); + + xmpp_stanza_release(minimize_text); + xmpp_stanza_release(minimize_st); + } + xmpp_stanza_add_child(storage, conference); xmpp_stanza_release(conference); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index 80bebba5..b20af1cd 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -104,6 +104,7 @@ #define STANZA_NAME_COMMAND "command" #define STANZA_NAME_CONFIGURE "configure" #define STANZA_NAME_ORIGIN_ID "origin-id" +#define STANZA_NAME_MINIMIZE "minimize" // error conditions #define STANZA_NAME_BAD_REQUEST "bad-request" @@ -203,6 +204,7 @@ #define STANZA_NS_USER_AVATAR_METADATA "urn:xmpp:avatar:metadata" #define STANZA_NS_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0" #define STANZA_NS_MAM2 "urn:xmpp:mam:2" +#define STANZA_NS_EXT_GAJIM_BOOKMARKS "xmpp:gajim.org/bookmarks" #define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo" diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 9254ac6b..235df25d 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -95,6 +95,7 @@ typedef struct bookmark_t { char *password; char *name; gboolean autojoin; + int ext_gajim_minimize; //0 - non existant, 1 - true, 2 - false } Bookmark; typedef struct disco_identity_t { -- cgit 1.4.1-2-gfad0