mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-27 12:26:21 +00:00
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:
@@ -615,6 +615,7 @@ cmd_ac_init(void)
|
|||||||
autocomplete_add(bookmark_property_ac, "nick");
|
autocomplete_add(bookmark_property_ac, "nick");
|
||||||
autocomplete_add(bookmark_property_ac, "password");
|
autocomplete_add(bookmark_property_ac, "password");
|
||||||
autocomplete_add(bookmark_property_ac, "autojoin");
|
autocomplete_add(bookmark_property_ac, "autojoin");
|
||||||
|
autocomplete_add(bookmark_property_ac, "name");
|
||||||
|
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
otr_ac = autocomplete_new();
|
otr_ac = autocomplete_new();
|
||||||
|
|||||||
@@ -802,8 +802,8 @@ static struct cmd_t command_defs[] =
|
|||||||
CMD_SYN(
|
CMD_SYN(
|
||||||
"/bookmark",
|
"/bookmark",
|
||||||
"/bookmark list",
|
"/bookmark list",
|
||||||
"/bookmark add [<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>] [autojoin on|off]",
|
"/bookmark update <room> [nick <nick>] [password <password>] [name <roomname>] autojoin on|off]",
|
||||||
"/bookmark remove [<room>]",
|
"/bookmark remove [<room>]",
|
||||||
"/bookmark join <room>",
|
"/bookmark join <room>",
|
||||||
"/bookmark invites on|off")
|
"/bookmark invites on|off")
|
||||||
@@ -817,6 +817,7 @@ static struct cmd_t command_defs[] =
|
|||||||
{ "update <room>", "Update the properties associated with a bookmark." },
|
{ "update <room>", "Update the properties associated with a bookmark." },
|
||||||
{ "nick <nick>", "Nickname used in the chat room." },
|
{ "nick <nick>", "Nickname used in the chat room." },
|
||||||
{ "password <password>", "Password if required, may be stored in plaintext on your server." },
|
{ "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." },
|
{ "autojoin on|off", "Whether to join the room automatically on login." },
|
||||||
{ "join <room>", "Join room using the properties associated with the bookmark." },
|
{ "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'."})
|
{ "invites on|off", "Whether or not to bookmark accepted room invites, defaults to 'on'."})
|
||||||
|
|||||||
@@ -4625,7 +4625,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
|||||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||||
char *nick = muc_nick(mucwin->roomjid);
|
char *nick = muc_nick(mucwin->roomjid);
|
||||||
char *password = muc_password(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) {
|
if (added) {
|
||||||
win_println(window, THEME_DEFAULT, "!", "Bookmark added for %s.", mucwin->roomjid);
|
win_println(window, THEME_DEFAULT, "!", "Bookmark added for %s.", mucwin->roomjid);
|
||||||
} else {
|
} else {
|
||||||
@@ -4710,7 +4710,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *opt_keys[] = { "autojoin", "nick", "password", NULL };
|
gchar *opt_keys[] = { "autojoin", "nick", "password", "name", NULL };
|
||||||
gboolean parsed;
|
gboolean parsed;
|
||||||
|
|
||||||
GHashTable *options = parse_options(&args[2], opt_keys, &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 *nick = g_hash_table_lookup(options, "nick");
|
||||||
char *password = g_hash_table_lookup(options, "password");
|
char *password = g_hash_table_lookup(options, "password");
|
||||||
|
char *name = g_hash_table_lookup(options, "name");
|
||||||
|
|
||||||
if (strcmp(cmd, "add") == 0) {
|
if (strcmp(cmd, "add") == 0) {
|
||||||
gboolean added = bookmark_add(jid, nick, password, autojoin);
|
gboolean added = bookmark_add(jid, nick, password, autojoin, name);
|
||||||
if (added) {
|
if (added) {
|
||||||
cons_show("Bookmark added for %s.", jid);
|
cons_show("Bookmark added for %s.", jid);
|
||||||
} else {
|
} else {
|
||||||
@@ -4747,7 +4748,7 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cmd, "update") == 0) {
|
if (strcmp(cmd, "update") == 0) {
|
||||||
gboolean updated = bookmark_update(jid, nick, password, autojoin);
|
gboolean updated = bookmark_update(jid, nick, password, autojoin, name);
|
||||||
if (updated) {
|
if (updated) {
|
||||||
cons_show("Bookmark updated.");
|
cons_show("Bookmark updated.");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1139,7 +1139,7 @@ sv_ev_muc_self_online(const char *const room, const char *const nick, gboolean c
|
|||||||
|
|
||||||
if (muc_invites_contain(room)) {
|
if (muc_invites_contain(room)) {
|
||||||
if (prefs_get_boolean(PREF_BOOKMARK_INVITE) && !bookmark_exists(room)) {
|
if (prefs_get_boolean(PREF_BOOKMARK_INVITE) && !bookmark_exists(room)) {
|
||||||
bookmark_add(room, nick, muc_invite_password(room), "on");
|
bookmark_add(room, nick, muc_invite_password(room), "on", NULL);
|
||||||
}
|
}
|
||||||
muc_invites_remove(room);
|
muc_invites_remove(room);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ bookmark_request(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str)
|
bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str, const char *name)
|
||||||
{
|
{
|
||||||
assert(jid != NULL);
|
assert(jid != NULL);
|
||||||
|
|
||||||
@@ -121,6 +121,11 @@ bookmark_add(const char *jid, const char *nick, const char *password, const char
|
|||||||
} else {
|
} else {
|
||||||
bookmark->password = NULL;
|
bookmark->password = NULL;
|
||||||
}
|
}
|
||||||
|
if (name) {
|
||||||
|
bookmark->password = strdup(name);
|
||||||
|
} else {
|
||||||
|
bookmark->password = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (g_strcmp0(autojoin_str, "on") == 0) {
|
if (g_strcmp0(autojoin_str, "on") == 0) {
|
||||||
bookmark->autojoin = TRUE;
|
bookmark->autojoin = TRUE;
|
||||||
@@ -137,7 +142,7 @@ bookmark_add(const char *jid, const char *nick, const char *password, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str)
|
bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str, const char *name)
|
||||||
{
|
{
|
||||||
assert(jid != NULL);
|
assert(jid != NULL);
|
||||||
|
|
||||||
@@ -154,6 +159,10 @@ bookmark_update(const char *jid, const char *nick, const char *password, const c
|
|||||||
free(bookmark->password);
|
free(bookmark->password);
|
||||||
bookmark->password = strdup(password);
|
bookmark->password = strdup(password);
|
||||||
}
|
}
|
||||||
|
if (name) {
|
||||||
|
free(bookmark->name);
|
||||||
|
bookmark->name = strdup(name);
|
||||||
|
}
|
||||||
if (autojoin_str) {
|
if (autojoin_str) {
|
||||||
if (g_strcmp0(autojoin_str, "on") == 0) {
|
if (g_strcmp0(autojoin_str, "on") == 0) {
|
||||||
bookmark->autojoin = TRUE;
|
bookmark->autojoin = TRUE;
|
||||||
@@ -359,11 +368,17 @@ _send_bookmarks(void)
|
|||||||
xmpp_stanza_set_name(conference, STANZA_NAME_CONFERENCE);
|
xmpp_stanza_set_name(conference, STANZA_NAME_CONFERENCE);
|
||||||
xmpp_stanza_set_attribute(conference, STANZA_ATTR_JID, bookmark->barejid);
|
xmpp_stanza_set_attribute(conference, STANZA_ATTR_JID, bookmark->barejid);
|
||||||
|
|
||||||
Jid *jidp = jid_create(bookmark->barejid);
|
if (bookmark->name) {
|
||||||
if (jidp->localpart) {
|
// use specified bookmark name
|
||||||
xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, jidp->localpart);
|
xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, bookmark->name);
|
||||||
|
} else {
|
||||||
|
// use localpart of JID by if no name is specified
|
||||||
|
Jid *jidp = jid_create(bookmark->barejid);
|
||||||
|
if (jidp->localpart) {
|
||||||
|
xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, jidp->localpart);
|
||||||
|
}
|
||||||
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
jid_destroy(jidp);
|
|
||||||
|
|
||||||
if (bookmark->autojoin) {
|
if (bookmark->autojoin) {
|
||||||
xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "true");
|
xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "true");
|
||||||
|
|||||||
@@ -251,8 +251,8 @@ void caps_add_feature(char *feature);
|
|||||||
void caps_remove_feature(char *feature);
|
void caps_remove_feature(char *feature);
|
||||||
gboolean caps_jid_has_feature(const char *const jid, const char *const feature);
|
gboolean caps_jid_has_feature(const char *const jid, const char *const feature);
|
||||||
|
|
||||||
gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str);
|
gboolean bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str, const char *name);
|
||||||
gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str);
|
gboolean bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str, const char *name);
|
||||||
gboolean bookmark_remove(const char *jid);
|
gboolean bookmark_remove(const char *jid);
|
||||||
gboolean bookmark_join(const char *jid);
|
gboolean bookmark_join(const char *jid);
|
||||||
GList* bookmark_get_list(void);
|
GList* bookmark_get_list(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user