mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 06:56:20 +00:00
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
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
#include "xmpp/muc.h"
|
#include "xmpp/muc.h"
|
||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "tools/bookmark_ignore.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBGPGME
|
#ifdef HAVE_LIBGPGME
|
||||||
#include "pgp/gpg.h"
|
#include "pgp/gpg.h"
|
||||||
@@ -69,6 +70,7 @@ ev_disconnect_cleanup(void)
|
|||||||
omemo_on_disconnect();
|
omemo_on_disconnect();
|
||||||
#endif
|
#endif
|
||||||
log_database_close();
|
log_database_close();
|
||||||
|
bookmark_ignore_on_disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ sv_ev_login_account_success(char *account_name, gboolean secured)
|
|||||||
{
|
{
|
||||||
ProfAccount *account = accounts_get_account(account_name);
|
ProfAccount *account = accounts_get_account(account_name);
|
||||||
|
|
||||||
|
bookmark_ignore_on_connect(account->jid);
|
||||||
|
|
||||||
roster_create();
|
roster_create();
|
||||||
|
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
|
|||||||
@@ -43,11 +43,13 @@
|
|||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
static gchar**
|
static GKeyFile *bookmark_ignore_keyfile = NULL;
|
||||||
bookmark_ignore_get_list(gsize *len)
|
static char *account_jid = NULL;
|
||||||
|
|
||||||
|
static void
|
||||||
|
_bookmark_ignore_load()
|
||||||
{
|
{
|
||||||
char *bi_loc;
|
char *bi_loc;
|
||||||
GKeyFile *bi;
|
|
||||||
|
|
||||||
bi_loc = files_get_data_path(FILE_BOOKMARK_AUTOJOIN_IGNORE);
|
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);
|
g_chmod(bi_loc, S_IRUSR | S_IWUSR);
|
||||||
}
|
}
|
||||||
|
|
||||||
bi = g_key_file_new();
|
bookmark_ignore_keyfile = g_key_file_new();
|
||||||
g_key_file_load_from_file(bi, bi_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
|
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")) {
|
free(bi_loc);
|
||||||
return NULL;
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bookmark_ignore_on_connect(const char *const barejid)
|
||||||
|
{
|
||||||
|
if(bookmark_ignore_keyfile == NULL) {
|
||||||
|
_bookmark_ignore_load();
|
||||||
|
account_jid = strdup(barejid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gchar **keys = g_key_file_get_keys(bi, "ignore"/*PREF_GROUP_ALIAS*/, len, NULL);
|
void
|
||||||
|
bookmark_ignore_on_disconnect()
|
||||||
return keys;
|
{
|
||||||
|
g_key_file_free(bookmark_ignore_keyfile);
|
||||||
|
bookmark_ignore_keyfile = NULL;
|
||||||
|
free(account_jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
bookmark_ignored(Bookmark *bookmark)
|
bookmark_ignored(Bookmark *bookmark)
|
||||||
{
|
{
|
||||||
gsize len;
|
return g_key_file_get_boolean(bookmark_ignore_keyfile, account_jid, bookmark->barejid, NULL);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
#ifndef BOOKMARK_IGNORE_H
|
#ifndef BOOKMARK_IGNORE_H
|
||||||
#define BOOKMARK_IGNORE_H
|
#define BOOKMARK_IGNORE_H
|
||||||
|
|
||||||
|
void bookmark_ignore_on_connect();
|
||||||
|
void bookmark_ignore_on_disconnect();
|
||||||
gboolean bookmark_ignored(Bookmark *bookmark);
|
gboolean bookmark_ignored(Bookmark *bookmark);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user