From f121554088a6bffd2721b94c46a40d8ec61e0b46 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Sun, 24 May 2020 17:17:20 +0200 Subject: [PATCH] List ignored bookmarks `/bookmarl ignore` lists the ignored bookmarks. Regards https://github.com/profanity-im/profanity/issues/1115 --- src/command/cmd_defs.c | 7 +++++-- src/command/cmd_funcs.c | 25 +++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + src/tools/bookmark_ignore.c | 6 ++++++ src/tools/bookmark_ignore.h | 1 + src/ui/console.c | 15 +++++++++++++++ src/ui/ui.h | 1 + 7 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 485c8324..d8a06bf2 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -795,7 +795,9 @@ static struct cmd_t command_defs[] = { "/bookmark", parse_args, 0, 8, NULL, - CMD_NOSUBFUNCS + CMD_SUBFUNCS( + { "ignore", cmd_bookmark_ignore } + ) CMD_MAINFUNC(cmd_bookmark) CMD_TAGS( CMD_TAG_GROUPCHAT) @@ -806,7 +808,8 @@ static struct cmd_t command_defs[] = "/bookmark update [nick ] [password ] [name ] autojoin on|off]", "/bookmark remove []", "/bookmark join ", - "/bookmark invites on|off") + "/bookmark invites on|off", + "/bookmark ignore") CMD_DESC( "Manage bookmarks and join bookmarked rooms. " "In a chat room, no arguments will bookmark the current room, setting autojoin to \"on\".") diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 8e02a822..171a3e52 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -68,6 +68,7 @@ #include "tools/autocomplete.h" #include "tools/parser.h" #include "tools/tinyurl.h" +#include "tools/bookmark_ignore.h" #include "plugins/plugins.h" #include "ui/ui.h" #include "ui/window_list.h" @@ -4766,6 +4767,30 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) return TRUE; } +gboolean +cmd_bookmark_ignore(ProfWin *window, const char *const command, gchar **args) +{ + jabber_conn_status_t conn_status = connection_get_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currently connected."); + cons_alert(); + return TRUE; + } + + // `/bookmark ignore` lists them + if (args[1] == NULL) { + gsize len; + gchar **list = bookmark_ignore_list(&len); + cons_show_bookmarks_ignore(list, len); + g_strfreev(list); + return TRUE; + } + + cons_bad_cmd_usage(command); + return TRUE; +} + gboolean cmd_disco(ProfWin *window, const char *const command, gchar **args) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index b87cc22f..d0d37efa 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -115,6 +115,7 @@ gboolean cmd_reconnect(ProfWin *window, const char *const command, gchar **args) gboolean cmd_room(ProfWin *window, const char *const command, gchar **args); gboolean cmd_rooms(ProfWin *window, const char *const command, gchar **args); gboolean cmd_bookmark(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_bookmark_ignore(ProfWin *window, const char *const command, gchar **args); gboolean cmd_roster(ProfWin *window, const char *const command, gchar **args); gboolean cmd_software(ProfWin *window, const char *const command, gchar **args); gboolean cmd_splash(ProfWin *window, const char *const command, gchar **args); diff --git a/src/tools/bookmark_ignore.c b/src/tools/bookmark_ignore.c index 3a3d0787..018c5b5b 100644 --- a/src/tools/bookmark_ignore.c +++ b/src/tools/bookmark_ignore.c @@ -85,3 +85,9 @@ bookmark_ignored(Bookmark *bookmark) { return g_key_file_get_boolean(bookmark_ignore_keyfile, account_jid, bookmark->barejid, NULL); } + +gchar ** +bookmark_ignore_list(gsize *len) +{ + return g_key_file_get_keys(bookmark_ignore_keyfile, account_jid, len, NULL); +} diff --git a/src/tools/bookmark_ignore.h b/src/tools/bookmark_ignore.h index 62c0458a..3eb0ccff 100644 --- a/src/tools/bookmark_ignore.h +++ b/src/tools/bookmark_ignore.h @@ -39,5 +39,6 @@ void bookmark_ignore_on_connect(); void bookmark_ignore_on_disconnect(); gboolean bookmark_ignored(Bookmark *bookmark); +gchar ** bookmark_ignore_list(gsize *len); #endif diff --git a/src/ui/console.c b/src/ui/console.c index 337679e0..3129c773 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2683,3 +2683,18 @@ _show_roster_contacts(GSList *list, gboolean show_groups) curr = g_slist_next(curr); } } + +void +cons_show_bookmarks_ignore(gchar **list, gsize len) +{ + int i; + ProfWin *console = wins_get_console(); + + cons_show(""); + cons_show("Ignored bookmarks:"); + + for(i=0; i