about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-05-24 13:31:24 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-05-24 13:31:24 +0200
commit242ffbcf7033649534d0acdf250cee90b08723e6 (patch)
tree0bc32a7a39076f2c50816ee5df0e746fe2f8685d /src/tools
parentd03c953d4a74501d32b9e080dddae96600a7a8a9 (diff)
downloadprofani-tty-242ffbcf7033649534d0acdf250cee90b08723e6.tar.gz
Add bookmark ignore functionality for multiple accounts
```
cat ~/.local/share/profanity/bookmark_ignore
[jubalh@iodoru.org]
profanity@rooms.dismail.de=true

[testuser@domain.org]
testr@rooms.domain.org=true
```

Regards https://github.com/profanity-im/profanity/issues/1115
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/bookmark_ignore.c47
-rw-r--r--src/tools/bookmark_ignore.h2
2 files changed, 26 insertions, 23 deletions
diff --git a/src/tools/bookmark_ignore.c b/src/tools/bookmark_ignore.c
index 18dfb869..3a3d0787 100644
--- a/src/tools/bookmark_ignore.c
+++ b/src/tools/bookmark_ignore.c
@@ -43,11 +43,13 @@
 
 #include "log.h"
 
-static gchar**
-bookmark_ignore_get_list(gsize *len)
+static GKeyFile *bookmark_ignore_keyfile = NULL;
+static char *account_jid = NULL;
+
+static void
+_bookmark_ignore_load()
 {
     char *bi_loc;
-    GKeyFile *bi;
 
     bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE);
 
@@ -55,32 +57,31 @@ bookmark_ignore_get_list(gsize *len)
         g_chmod(bi_loc, S_IRUSR | S_IWUSR);
     }
 
-    bi = g_key_file_new();
-    g_key_file_load_from_file(bi, bi_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
+    bookmark_ignore_keyfile = g_key_file_new();
+    g_key_file_load_from_file(bookmark_ignore_keyfile, bi_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
 
-    if (!g_key_file_has_group(bi, "ignore")) {
-        return NULL;
-    }
+    free(bi_loc);
+}
 
-    gchar **keys = g_key_file_get_keys(bi, "ignore"/*PREF_GROUP_ALIAS*/, len, NULL);
+void
+bookmark_ignore_on_connect(const char *const barejid)
+{
+    if(bookmark_ignore_keyfile == NULL) {
+        _bookmark_ignore_load();
+        account_jid = strdup(barejid);
+    }
+}
 
-    return keys;
+void
+bookmark_ignore_on_disconnect()
+{
+    g_key_file_free(bookmark_ignore_keyfile);
+    bookmark_ignore_keyfile = NULL;
+    free(account_jid);
 }
 
 gboolean
 bookmark_ignored(Bookmark *bookmark)
 {
-    gsize len;
-    gchar **ignored = bookmark_ignore_get_list(&len);
-    int i;
-
-    for (i=0; i<len; i++) {
-        if (g_strcmp0(bookmark->barejid, ignored[i]) == 0) {
-            g_strfreev(ignored);
-            return TRUE;
-        }
-    }
-
-    g_strfreev(ignored);
-    return FALSE;
+    return g_key_file_get_boolean(bookmark_ignore_keyfile, account_jid, bookmark->barejid, NULL);
 }
diff --git a/src/tools/bookmark_ignore.h b/src/tools/bookmark_ignore.h
index ea37f0c6..62c0458a 100644
--- a/src/tools/bookmark_ignore.h
+++ b/src/tools/bookmark_ignore.h
@@ -36,6 +36,8 @@
 #ifndef BOOKMARK_IGNORE_H
 #define BOOKMARK_IGNORE_H
 
+void bookmark_ignore_on_connect();
+void bookmark_ignore_on_disconnect();
 gboolean bookmark_ignored(Bookmark *bookmark);
 
 #endif