aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-05-26 17:49:34 +0300
committerMarcoPolo-PasTonMolo <marcopolopastonmolo@protonmail.com>2022-05-26 17:49:34 +0300
commit6a44e188537ee2d70226ad9dba4ae89c15437e2b (patch)
tree3081b0af49199c6f5b3a8fdc1ff07eac64420476 /src/command
parentb4523d6c42825bda175663730001302adb21b95e (diff)
downloadprofani-tty-6a44e188537ee2d70226ad9dba4ae89c15437e2b.tar.gz
Add `/avatar set` command to publish avatar
Use `/avatar set <path>` where <path> is an image file to upload a new avatar for the current user. When the avatar is too big it gets scaled down. Scaling code copied from dino. Fixes https://github.com/profanity-im/profanity/issues/1687
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_ac.c6
-rw-r--r--src/command/cmd_defs.c4
-rw-r--r--src/command/cmd_funcs.c6
3 files changed, 15 insertions, 1 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index ec0e9c30..9fc70a1d 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -1057,6 +1057,7 @@ cmd_ac_init(void)
autocomplete_add(correction_ac, "char");
avatar_ac = autocomplete_new();
+ autocomplete_add(avatar_ac, "set");
autocomplete_add(avatar_ac, "get");
autocomplete_add(avatar_ac, "open");
@@ -4101,6 +4102,11 @@ _avatar_autocomplete(ProfWin* window, const char* const input, gboolean previous
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status == JABBER_CONNECTED) {
+ result = cmd_ac_complete_filepath(input, "/avatar set", previous);
+ if (result) {
+ return result;
+ }
+
result = autocomplete_param_with_func(input, "/avatar get", roster_barejid_autocomplete, previous, NULL);
if (result) {
return result;
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index e62e2d2d..ffc4ec83 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2443,16 +2443,20 @@ static struct cmd_t command_defs[] = {
CMD_TAGS(
CMD_TAG_CHAT)
CMD_SYN(
+ "/avatar set <path>",
"/avatar get <barejid>",
"/avatar open <barejid>")
CMD_DESC(
+ "Upload avatar for oneself (XEP-0084). "
"Download avatar (XEP-0084) for a certain contact. "
"If nothing happens after using this command the user either doesn't have an avatar set at all "
"or doesn't use XEP-0084 to publish it.")
CMD_ARGS(
+ { "set <path>", "Set avatar to the img at <path>." },
{ "get <barejid>", "Download the avatar. barejid is the JID to download avatar from." },
{ "open <barejid>", "Download avatar and open it with command." })
CMD_EXAMPLES(
+ "/avatar set ~/images/avatar.png",
"/avatar get thor@valhalla.edda",
"/avatar open freyja@vanaheimr.edda") },
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 9e821ede..26eb9c3e 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -9195,7 +9195,11 @@ cmd_avatar(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
- if (g_strcmp0(args[0], "get") == 0) {
+ if (g_strcmp0(args[0], "set") == 0) {
+ if (avatar_set(args[1])) {
+ cons_show("Avatar updated successfully");
+ }
+ } else if (g_strcmp0(args[0], "get") == 0) {
avatar_get_by_nick(args[1], false);
} else if (g_strcmp0(args[0], "open") == 0) {
avatar_get_by_nick(args[1], true);