mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Added /roster add command
This commit is contained in:
parent
d49a01a9c3
commit
518b6721ff
@ -2008,26 +2008,6 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
||||
static gboolean
|
||||
_cmd_roster(gchar **args, struct cmd_help_t help)
|
||||
{
|
||||
// show roster
|
||||
if (args[0] == NULL) {
|
||||
GSList *list = roster_get_contacts();
|
||||
cons_show_roster(list);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// first arg invalid
|
||||
if (strcmp(args[0], "nick") != 0) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (args[1] == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *jid = args[1];
|
||||
char *name = args[2];
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
@ -2035,21 +2015,59 @@ _cmd_roster(gchar **args, struct cmd_help_t help)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// contact does not exist
|
||||
PContact contact = roster_get_contact(jid);
|
||||
if (contact == NULL) {
|
||||
cons_show("Contact not found in roster: %s", jid);
|
||||
// show roster
|
||||
if (args[0] == NULL) {
|
||||
GSList *list = roster_get_contacts();
|
||||
cons_show_roster(list);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
roster_change_name(jid, name);
|
||||
// add contact
|
||||
if (strcmp(args[0], "add") == 0) {
|
||||
|
||||
if (name == NULL) {
|
||||
cons_show("Nickname for %s removed.", jid);
|
||||
} else {
|
||||
cons_show("Nickname for %s set to: %s.", jid, name);
|
||||
if (args[1] == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *jid = args[1];
|
||||
char *name = args[2];
|
||||
|
||||
roster_add_new(jid, name);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// change nickname
|
||||
if (strcmp(args[0], "nick") == 0) {
|
||||
|
||||
if (args[1] == NULL) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *jid = args[1];
|
||||
char *name = args[2];
|
||||
|
||||
// contact does not exist
|
||||
PContact contact = roster_get_contact(jid);
|
||||
if (contact == NULL) {
|
||||
cons_show("Contact not found in roster: %s", jid);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
roster_change_name(jid, name);
|
||||
|
||||
if (name == NULL) {
|
||||
cons_show("Nickname for %s removed.", jid);
|
||||
} else {
|
||||
cons_show("Nickname for %s set to: %s.", jid, name);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,16 @@ roster_reset_search_attempts(void)
|
||||
autocomplete_reset(groups_ac);
|
||||
}
|
||||
|
||||
void
|
||||
roster_add_new(const char * const barejid, const char * const name)
|
||||
{
|
||||
xmpp_conn_t * const conn = connection_get_conn();
|
||||
xmpp_ctx_t * const ctx = connection_get_ctx();
|
||||
xmpp_stanza_t *iq = stanza_create_roster_set(ctx, barejid, name, NULL);
|
||||
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)
|
||||
|
@ -143,5 +143,6 @@ gboolean roster_add(const char * const barejid, const char * const name,
|
||||
GSList *groups, const char * const subscription, gboolean pending_out);
|
||||
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);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user