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

Added roster list when using /roster with no args

This commit is contained in:
James Booth 2013-06-01 23:27:46 +01:00
parent 83c4177692
commit d49a01a9c3
5 changed files with 89 additions and 24 deletions

View File

@ -276,7 +276,7 @@ static struct cmd_t main_commands[] =
NULL } } },
{ "/roster",
_cmd_roster, parse_args_with_freetext, 2, 3,
_cmd_roster, parse_args_with_freetext, 0, 3,
{ "/roster nick jid [handle]", "Add or change a contacts handle.",
{ "/roster nick jid [handle]",
"-------------------------",
@ -2008,35 +2008,49 @@ _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;
} else {
char *jid = args[1];
char *name = args[2];
jabber_conn_status_t conn_status = jabber_get_connection_status();
}
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
return TRUE;
}
// 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);
}
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) {
cons_show("You are not currently connected.");
return TRUE;
}
// 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;
}
static gboolean

View File

@ -1239,6 +1239,42 @@ cons_navigation_help(void)
cons_alert();
}
void
cons_show_roster(GSList *list)
{
GSList *curr = list;
cons_show("");
cons_show("Roster:");
while(curr) {
PContact contact = curr->data;
GString *title = g_string_new(" ");
title = g_string_append(title, p_contact_barejid(contact));
if (p_contact_name(contact) != NULL) {
title = g_string_append(title, " (");
title = g_string_append(title, strdup(p_contact_name(contact)));
title = g_string_append(title, ")");
}
cons_show(title->str);
g_string_free(title, TRUE);
GString *sub = g_string_new(" Subscription : ");
sub = g_string_append(sub, p_contact_subscription(contact));
if (p_contact_pending_out(contact)) {
sub = g_string_append(sub, ", request sent");
}
if (presence_sub_request_exists(p_contact_barejid(contact))) {
sub = g_string_append(sub, ", request received");
}
cons_show(sub->str);
g_string_free(sub, TRUE);
curr = g_slist_next(curr);
}
ui_console_dirty();
cons_alert();
}
void
cons_show_contacts(GSList *list)
{

View File

@ -165,6 +165,7 @@ void cons_show_word(const char * const word);
void cons_show_error(const char * const cmd, ...);
void cons_highlight_show(const char * const cmd);
void cons_show_contacts(GSList * list);
void cons_show_roster(GSList * list);
void cons_show_wins(void);
void cons_show_status(const char * const barejid);
void cons_show_info(PContact pcontact);

View File

@ -153,6 +153,19 @@ presence_sub_request_find(char * search_str)
return autocomplete_complete(sub_requests_ac, search_str);
}
gboolean
presence_sub_request_exists(const char * const bare_jid)
{
GSList *requests = autocomplete_get_list(sub_requests_ac);
while (requests != NULL) {
if (strcmp(requests->data, bare_jid) == 0) {
return TRUE;
}
requests = g_slist_next(requests);
}
return FALSE;
}
void
presence_reset_sub_request_search(void)
{

View File

@ -113,6 +113,7 @@ void presence_change_room_nick(const char * const room, const char * const nick)
void presence_leave_chat_room(const char * const room_jid);
void presence_update(resource_presence_t status, const char * const msg,
int idle);
gboolean presence_sub_request_exists(const char * const bare_jid);
// iq functions
void iq_send_software_version(const char * const fulljid);