about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-05-24 17:17:20 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-05-24 17:55:08 +0200
commitf121554088a6bffd2721b94c46a40d8ec61e0b46 (patch)
tree3f641f76d7c35dedb6930cd56023056335b12f9c
parentca3972b3ca85a8ba50da46e679832dcedfadcce7 (diff)
downloadprofani-tty-f121554088a6bffd2721b94c46a40d8ec61e0b46.tar.gz
List ignored bookmarks
`/bookmarl ignore` lists the ignored bookmarks.

Regards https://github.com/profanity-im/profanity/issues/1115
-rw-r--r--src/command/cmd_defs.c7
-rw-r--r--src/command/cmd_funcs.c25
-rw-r--r--src/command/cmd_funcs.h1
-rw-r--r--src/tools/bookmark_ignore.c6
-rw-r--r--src/tools/bookmark_ignore.h1
-rw-r--r--src/ui/console.c15
-rw-r--r--src/ui/ui.h1
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 <room> [nick <nick>] [password <password>] [name <roomname>] autojoin on|off]",
             "/bookmark remove [<room>]",
             "/bookmark join <room>",
-            "/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"
@@ -4767,6 +4768,30 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
 }
 
 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)
 {
     jabber_conn_status_t conn_status = connection_get_status();
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<len; i++) {
+        win_print(console, THEME_DEFAULT, "-", "  %s", list[i]);
+        win_newline(console);
+    }
+}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 6e8083da..b91ea8b4 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -268,6 +268,7 @@ void cons_show_login_success(ProfAccount *account, gboolean secured);
 void cons_show_account_list(gchar **accounts);
 void cons_show_room_list(GSList *room, const char *const conference_node);
 void cons_show_bookmarks(const GList *list);
+void cons_show_bookmarks_ignore(gchar **list, gsize len);
 void cons_show_disco_items(GSList *items, const char *const jid);
 void cons_show_disco_info(const char *from, GSList *identities, GSList *features);
 void cons_show_room_invite(const char *const invitor, const char *const room, const char *const reason);