diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-05-22 14:18:20 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-05-22 14:18:20 +0200 |
commit | 88c36745fe3f568f09fcd4078fc760a52e826eb7 (patch) | |
tree | 3689d6661dae93788c394e93acc64cbf4f385052 /src/xmpp | |
parent | fad296b79e42a0df6c0f118e1c011f480462551f (diff) | |
download | profani-tty-88c36745fe3f568f09fcd4078fc760a52e826eb7.tar.gz |
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
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/bookmark.c | 27 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 4 |
2 files changed, 23 insertions, 8 deletions
diff --git a/src/xmpp/bookmark.c b/src/xmpp/bookmark.c index 81d7e19e..e546ef18 100644 --- a/src/xmpp/bookmark.c +++ b/src/xmpp/bookmark.c @@ -95,7 +95,7 @@ bookmark_request(void) } 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); @@ -121,6 +121,11 @@ bookmark_add(const char *jid, const char *nick, const char *password, const char } else { bookmark->password = NULL; } + if (name) { + bookmark->password = strdup(name); + } else { + bookmark->password = NULL; + } if (g_strcmp0(autojoin_str, "on") == 0) { bookmark->autojoin = TRUE; @@ -137,7 +142,7 @@ bookmark_add(const char *jid, const char *nick, const char *password, const char } 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); @@ -154,6 +159,10 @@ bookmark_update(const char *jid, const char *nick, const char *password, const c free(bookmark->password); bookmark->password = strdup(password); } + if (name) { + free(bookmark->name); + bookmark->name = strdup(name); + } if (autojoin_str) { if (g_strcmp0(autojoin_str, "on") == 0) { bookmark->autojoin = TRUE; @@ -359,11 +368,17 @@ _send_bookmarks(void) xmpp_stanza_set_name(conference, STANZA_NAME_CONFERENCE); xmpp_stanza_set_attribute(conference, STANZA_ATTR_JID, bookmark->barejid); - Jid *jidp = jid_create(bookmark->barejid); - if (jidp->localpart) { - xmpp_stanza_set_attribute(conference, STANZA_ATTR_NAME, jidp->localpart); + if (bookmark->name) { + // use specified bookmark name + 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) { xmpp_stanza_set_attribute(conference, STANZA_ATTR_AUTOJOIN, "true"); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index c06939cb..9254ac6b 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -251,8 +251,8 @@ void caps_add_feature(char *feature); void caps_remove_feature(char *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_update(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, const char *name); gboolean bookmark_remove(const char *jid); gboolean bookmark_join(const char *jid); GList* bookmark_get_list(void); |