1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added /roster remove command

This commit is contained in:
James Booth 2013-06-02 00:06:05 +01:00
parent 518b6721ff
commit 01bdc6ae5a
5 changed files with 56 additions and 0 deletions

View File

@ -918,7 +918,9 @@ cmd_init(void)
autocomplete_add(wins_ac, strdup("tidy"));
roster_ac = autocomplete_new();
autocomplete_add(roster_ac, strdup("add"));
autocomplete_add(roster_ac, strdup("nick"));
autocomplete_add(roster_ac, strdup("remove"));
theme_load_ac = NULL;
@ -2038,6 +2040,21 @@ _cmd_roster(gchar **args, struct cmd_help_t help)
return TRUE;
}
// remove contact
if (strcmp(args[0], "remove") == 0) {
if (args[1] == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *jid = args[1];
roster_remove(jid);
return TRUE;
}
// change nickname
if (strcmp(args[0], "nick") == 0) {

View File

@ -145,6 +145,16 @@ roster_add_new(const char * const barejid, const char * const name)
xmpp_stanza_release(iq);
}
void
roster_remove(const char * const barejid)
{
xmpp_conn_t * const conn = connection_get_conn();
xmpp_ctx_t * const ctx = connection_get_ctx();
xmpp_stanza_t *iq = stanza_create_roster_remove_set(ctx, barejid);
xmpp_send(conn, iq);
xmpp_stanza_release(iq);
}
gboolean
roster_add(const char * const barejid, const char * const name, GSList *groups,
const char * const subscription, gboolean pending_out)
@ -366,6 +376,9 @@ _roster_handle_push(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
// remove from roster
if (g_strcmp0(sub, "remove") == 0) {
// remove barejid and name
if (name == NULL) {
name = barejid;
}
autocomplete_remove(barejid_ac, barejid);
autocomplete_remove(name_ac, name);
g_hash_table_remove(name_to_barejid, name);

View File

@ -89,6 +89,29 @@ stanza_create_message(xmpp_ctx_t *ctx, const char * const recipient,
return msg;
}
xmpp_stanza_t *
stanza_create_roster_remove_set(xmpp_ctx_t *ctx, const char * const barejid)
{
xmpp_stanza_t *iq = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(iq, STANZA_NAME_IQ);
xmpp_stanza_set_type(iq, STANZA_TYPE_SET);
xmpp_stanza_t *query = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(query, STANZA_NAME_QUERY);
xmpp_stanza_set_ns(query, XMPP_NS_ROSTER);
xmpp_stanza_t *item = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, barejid);
xmpp_stanza_set_attribute(item, STANZA_ATTR_SUBSCRIPTION, "remove");
xmpp_stanza_add_child(query, item);
xmpp_stanza_add_child(iq, query);
return iq;
}
xmpp_stanza_t *
stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const jid,
const char * const handle, GSList *groups)

View File

@ -180,5 +180,7 @@ char * stanza_get_show(xmpp_stanza_t *stanza, char *def);
xmpp_stanza_t * stanza_create_roster_set(xmpp_ctx_t *ctx, const char * const jid,
const char * const handle, GSList *groups);
xmpp_stanza_t * stanza_create_roster_remove_set(xmpp_ctx_t *ctx,
const char * const barejid);
#endif

View File

@ -144,5 +144,6 @@ gboolean roster_add(const char * const barejid, const char * const name,
void roster_change_name(const char * const barejid, const char * const new_name);
char * roster_barejid_from_name(const char * const name);
void roster_add_new(const char * const barejid, const char * const name);
void roster_remove(const char * const barejid);
#endif