mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Use current room for /bookmark add and /bookmark remove
This commit is contained in:
parent
94fd116ef8
commit
c40660b0d8
@ -803,9 +803,9 @@ static struct cmd_t command_defs[] =
|
||||
CMD_SYN(
|
||||
"/bookmark",
|
||||
"/bookmark list",
|
||||
"/bookmark add <room> [nick <nick>] [password <password>] [autojoin on|off]",
|
||||
"/bookmark add [<room>] [nick <nick>] [password <password>] [autojoin on|off]",
|
||||
"/bookmark update <room> [nick <nick>] [password <password>] [autojoin on|off]",
|
||||
"/bookmark remove <room>",
|
||||
"/bookmark remove [<room>]",
|
||||
"/bookmark join <room>",
|
||||
"/bookmark invites on|off")
|
||||
CMD_DESC(
|
||||
@ -813,8 +813,8 @@ static struct cmd_t command_defs[] =
|
||||
"In a chat room, no arguments will bookmark the current room, setting autojoin to \"on\".")
|
||||
CMD_ARGS(
|
||||
{ "list", "List all bookmarks." },
|
||||
{ "add <room>", "Add a bookmark." },
|
||||
{ "remove <room>", "Remove a bookmark." },
|
||||
{ "add [<room>]", "Add a bookmark, passing no room will bookmark the current room, setting autojoin to \"on\"." },
|
||||
{ "remove [<room>]", "Remove a bookmark, passing no room will remove the bookmark for the current room, if one exists." },
|
||||
{ "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." },
|
||||
|
@ -4325,7 +4325,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
}
|
||||
|
||||
gchar *cmd = args[0];
|
||||
if (window->type == WIN_MUC && cmd == NULL) {
|
||||
if (window->type == WIN_MUC && (cmd == NULL || g_strcmp0(cmd, "add") == 0)) {
|
||||
// default to current nickname, password, and autojoin "on"
|
||||
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
@ -4338,8 +4338,20 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
ui_current_print_formatted_line('!', 0, "Bookmark already exists for %s.", mucwin->roomjid);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (window->type == WIN_MUC && g_strcmp0(cmd, "remove") == 0) {
|
||||
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
gboolean removed = bookmark_remove(mucwin->roomjid);
|
||||
if (removed) {
|
||||
ui_current_print_formatted_line('!', 0, "Bookmark removed for %s.", mucwin->roomjid);
|
||||
} else {
|
||||
ui_current_print_formatted_line('!', 0, "Bookmark does not exist for %s.", mucwin->roomjid);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (cmd == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
return TRUE;
|
||||
@ -4357,17 +4369,26 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
cons_show("");
|
||||
}
|
||||
return TRUE;
|
||||
} else if (strcmp(cmd, "list") == 0) {
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "list") == 0) {
|
||||
GList *bookmarks = bookmark_get_list();
|
||||
cons_show_bookmarks(bookmarks);
|
||||
g_list_free(bookmarks);
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *jid = args[1];
|
||||
if (jid == NULL) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
return TRUE;
|
||||
}
|
||||
if (strchr(jid, '@') == NULL) {
|
||||
cons_show("Invalid room, must be of the form room@domain.tld");
|
||||
cons_show("");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "remove") == 0) {
|
||||
gboolean removed = bookmark_remove(jid);
|
||||
@ -4397,43 +4418,42 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *nick = g_hash_table_lookup(options, "nick");
|
||||
char *password = g_hash_table_lookup(options, "password");
|
||||
char *autojoin = g_hash_table_lookup(options, "autojoin");
|
||||
|
||||
if (autojoin) {
|
||||
if ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0)) {
|
||||
if (autojoin && ((strcmp(autojoin, "on") != 0) && (strcmp(autojoin, "off") != 0))) {
|
||||
cons_bad_cmd_usage(command);
|
||||
cons_show("");
|
||||
options_destroy(options);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
char *nick = g_hash_table_lookup(options, "nick");
|
||||
char *password = g_hash_table_lookup(options, "password");
|
||||
|
||||
if (strcmp(cmd, "add") == 0) {
|
||||
if (strchr(jid, '@')==NULL) {
|
||||
cons_show("Can't add bookmark with JID '%s'; should be '%s@domain.tld'", jid, jid);
|
||||
} else {
|
||||
gboolean added = bookmark_add(jid, nick, password, autojoin);
|
||||
if (added) {
|
||||
cons_show("Bookmark added for %s.", jid);
|
||||
} else {
|
||||
cons_show("Bookmark already exists, use /bookmark update to edit.");
|
||||
}
|
||||
options_destroy(options);
|
||||
return TRUE;
|
||||
}
|
||||
} else if (strcmp(cmd, "update") == 0) {
|
||||
|
||||
if (strcmp(cmd, "update") == 0) {
|
||||
gboolean updated = bookmark_update(jid, nick, password, autojoin);
|
||||
if (updated) {
|
||||
cons_show("Bookmark updated.");
|
||||
} else {
|
||||
cons_show("No bookmark exists for %s.", jid);
|
||||
}
|
||||
} else {
|
||||
cons_bad_cmd_usage(command);
|
||||
options_destroy(options);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
cons_bad_cmd_usage(command);
|
||||
options_destroy(options);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -137,7 +137,8 @@ void cmd_bookmark_add_shows_message_when_invalid_jid(void **state)
|
||||
|
||||
will_return(connection_get_status, JABBER_CONNECTED);
|
||||
|
||||
expect_cons_show("Can't add bookmark with JID 'room'; should be 'room@domain.tld'");
|
||||
expect_cons_show("Invalid room, must be of the form room@domain.tld");
|
||||
expect_cons_show("");
|
||||
|
||||
gboolean result = cmd_bookmark(&window, CMD_BOOKMARK, args);
|
||||
assert_true(result);
|
||||
|
Loading…
Reference in New Issue
Block a user