Add option to add bookmark name

`/bookmark add|update` got `name` field.
By default localpart of JID is used (like before) but now we can set the
name ourselves.

Regards https://github.com/profanity-im/profanity/issues/697
This commit is contained in:
Michael Vetter
2020-05-22 14:18:20 +02:00
parent fad296b79e
commit 88c36745fe
6 changed files with 33 additions and 15 deletions

View File

@@ -615,6 +615,7 @@ cmd_ac_init(void)
autocomplete_add(bookmark_property_ac, "nick");
autocomplete_add(bookmark_property_ac, "password");
autocomplete_add(bookmark_property_ac, "autojoin");
autocomplete_add(bookmark_property_ac, "name");
#ifdef HAVE_LIBOTR
otr_ac = autocomplete_new();

View File

@@ -802,8 +802,8 @@ static struct cmd_t command_defs[] =
CMD_SYN(
"/bookmark",
"/bookmark list",
"/bookmark add [<room>] [nick <nick>] [password <password>] [autojoin on|off]",
"/bookmark update <room> [nick <nick>] [password <password>] [autojoin on|off]",
"/bookmark add [<room>] [nick <nick>] [password <password>] [name <roomname>] [autojoin on|off]",
"/bookmark update <room> [nick <nick>] [password <password>] [name <roomname>] autojoin on|off]",
"/bookmark remove [<room>]",
"/bookmark join <room>",
"/bookmark invites on|off")
@@ -817,6 +817,7 @@ static struct cmd_t command_defs[] =
{ "update <room>", "Update the properties associated with a bookmark." },
{ "nick <nick>", "Nickname used in the chat room." },
{ "password <password>", "Password if required, may be stored in plaintext on your server." },
{ "name <roomname>", "Optional name for the bookmark. By default localpart of the JID will be used." },
{ "autojoin on|off", "Whether to join the room automatically on login." },
{ "join <room>", "Join room using the properties associated with the bookmark." },
{ "invites on|off", "Whether or not to bookmark accepted room invites, defaults to 'on'."})

View File

@@ -4625,7 +4625,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
char *nick = muc_nick(mucwin->roomjid);
char *password = muc_password(mucwin->roomjid);
gboolean added = bookmark_add(mucwin->roomjid, nick, password, "on");
gboolean added = bookmark_add(mucwin->roomjid, nick, password, "on", NULL);
if (added) {
win_println(window, THEME_DEFAULT, "!", "Bookmark added for %s.", mucwin->roomjid);
} else {
@@ -4710,7 +4710,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
return TRUE;
}
gchar *opt_keys[] = { "autojoin", "nick", "password", NULL };
gchar *opt_keys[] = { "autojoin", "nick", "password", "name", NULL };
gboolean parsed;
GHashTable *options = parse_options(&args[2], opt_keys, &parsed);
@@ -4733,9 +4733,10 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
char *nick = g_hash_table_lookup(options, "nick");
char *password = g_hash_table_lookup(options, "password");
char *name = g_hash_table_lookup(options, "name");
if (strcmp(cmd, "add") == 0) {
gboolean added = bookmark_add(jid, nick, password, autojoin);
gboolean added = bookmark_add(jid, nick, password, autojoin, name);
if (added) {
cons_show("Bookmark added for %s.", jid);
} else {
@@ -4747,7 +4748,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
}
if (strcmp(cmd, "update") == 0) {
gboolean updated = bookmark_update(jid, nick, password, autojoin);
gboolean updated = bookmark_update(jid, nick, password, autojoin, name);
if (updated) {
cons_show("Bookmark updated.");
} else {