aboutsummaryrefslogtreecommitdiffstats
path: root/src/xmpp
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-03-10 07:12:13 +0100
committerMichael Vetter <jubalh@iodoru.org>2020-03-10 07:12:13 +0100
commit52e7e596aa0e7ca8b8db11c7c47c584fc7a75be6 (patch)
treed7020dffd72bd991f4ee73158db8fec763587ca6 /src/xmpp
parent7e62d458ee22e9171bf5741cda5c8ce85b20bd6a (diff)
downloadprofani-tty-52e7e596aa0e7ca8b8db11c7c47c584fc7a75be6.tar.gz
xep-0084/avatar: add option to open avatar directly
Change: `/avatar me@somewhere.org` -> `/avatar get me@somewhere.org` New: `/avatar cmd feh` `/avatar open me@somewhere.org` Implement https://github.com/profanity-im/profanity/issues/1281
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/avatar.c29
-rw-r--r--src/xmpp/avatar.h2
2 files changed, 28 insertions, 3 deletions
diff --git a/src/xmpp/avatar.c b/src/xmpp/avatar.c
index 1a3a08b9..9d043cb3 100644
--- a/src/xmpp/avatar.c
+++ b/src/xmpp/avatar.c
@@ -48,13 +48,15 @@
#include "xmpp/stanza.h"
#include "ui/ui.h"
#include "config/files.h"
+#include "config/preferences.h"
typedef struct avatar_metadata {
char *type;
char *id;
} avatar_metadata;
-GHashTable *looking_for = NULL; // contains nicks/barejids from who we want to get the avatar
+static GHashTable *looking_for = NULL; // contains nicks/barejids from who we want to get the avatar
+static GHashTable *shall_open = NULL; // contains a list of nicks that shall not just downloaded but also opened
static void _avatar_request_item_by_id(const char *jid, avatar_metadata *data);
static int _avatar_metadata_handler(xmpp_stanza_t *const stanza, void *const userdata);
@@ -81,10 +83,15 @@ avatar_pep_subscribe(void)
g_hash_table_destroy(looking_for);
}
looking_for = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+ if (shall_open) {
+ g_hash_table_destroy(shall_open);
+ }
+ shall_open = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
}
gboolean
-avatar_get_by_nick(const char* nick)
+avatar_get_by_nick(const char* nick, gboolean open)
{
// in case we set the feature, remove it
caps_remove_feature(XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY);
@@ -95,6 +102,10 @@ avatar_get_by_nick(const char* nick)
// add the feature. this will trigger the _avatar_metadata_notfication_handler handler
caps_add_feature(XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY);
+ if (open) {
+ g_hash_table_insert(shall_open, strdup(nick), NULL);
+ }
+
return TRUE;
}
@@ -253,6 +264,20 @@ _avatar_request_item_result_handler(xmpp_stanza_t *const stanza, void *const use
cons_show("Avatar saved as %s", filename->str);
}
+ // if we shall open it
+ if (g_hash_table_contains(shall_open, from_attr)) {
+ GString *cmd = g_string_new("");
+
+ g_string_append_printf(cmd, "%s %s > /dev/null 2>&1", prefs_get_string(PREF_AVATAR_CMD), filename->str);
+ cons_show("Calling: %s", cmd->str);
+ FILE *stream = popen(cmd->str, "r");
+
+ pclose(stream);
+ g_string_free(cmd, TRUE);
+
+ g_hash_table_remove(shall_open, from_attr);
+ }
+
g_string_free(filename, TRUE);
free(de);
diff --git a/src/xmpp/avatar.h b/src/xmpp/avatar.h
index 707600b3..49c03750 100644
--- a/src/xmpp/avatar.h
+++ b/src/xmpp/avatar.h
@@ -39,6 +39,6 @@
#include <glib.h>
void avatar_pep_subscribe(void);
-gboolean avatar_get_by_nick(const char* nick);
+gboolean avatar_get_by_nick(const char* nick, gboolean open);
#endif