diff --git a/src/command.c b/src/command.c index 705be6de..c0155c38 100644 --- a/src/command.c +++ b/src/command.c @@ -1009,13 +1009,7 @@ _cmd_sub(gchar **args, struct cmd_help_t help) log_info("Sent subscription request to %s.", bare_jid); } else if (strcmp(subcmd, "show") == 0) { PContact contact = contact_list_get_contact(bare_jid); - if (contact == NULL) { - if (win_current_is_chat()) { - win_current_show("No subscription information for %s.", bare_jid); - } else { - cons_show("No subscription information for %s.", bare_jid); - } - } else if (p_contact_subscription(contact) == NULL) { + if ((contact == NULL) || (p_contact_subscription(contact) == NULL)) { if (win_current_is_chat()) { win_current_show("No subscription information for %s.", bare_jid); } else { @@ -1023,11 +1017,21 @@ _cmd_sub(gchar **args, struct cmd_help_t help) } } else { if (win_current_is_chat()) { - win_current_show("%s subscription status: %s.", bare_jid, - p_contact_subscription(contact)); + if (p_contact_pending_out(contact)) { + win_current_show("%s subscription status: %s, request pending.", + bare_jid, p_contact_subscription(contact)); + } else { + win_current_show("%s subscription status: %s.", bare_jid, + p_contact_subscription(contact)); + } } else { - cons_show("%s subscription status: %s.", bare_jid, - p_contact_subscription(contact)); + if (p_contact_pending_out(contact)) { + cons_show("%s subscription status: %s, request pending.", + bare_jid, p_contact_subscription(contact)); + } else { + cons_show("%s subscription status: %s.", bare_jid, + p_contact_subscription(contact)); + } } } } else { diff --git a/src/contact.c b/src/contact.c index 9188b5f0..9cbe5d69 100644 --- a/src/contact.c +++ b/src/contact.c @@ -33,12 +33,13 @@ struct p_contact_t { char *presence; char *status; char *subscription; + gboolean pending_out; }; PContact p_contact_new(const char * const jid, const char * const name, const char * const presence, const char * const status, - const char * const subscription) + const char * const subscription, gboolean pending_out) { PContact contact = malloc(sizeof(struct p_contact_t)); contact->jid = strdup(jid); @@ -64,6 +65,8 @@ p_contact_new(const char * const jid, const char * const name, else contact->subscription = strdup("none");; + contact->pending_out = pending_out; + return contact; } @@ -156,6 +159,12 @@ p_contact_subscription(const PContact contact) return contact->subscription; } +gboolean +p_contact_pending_out(const PContact contact) +{ + return contact->pending_out; +} + void p_contact_set_presence(const PContact contact, const char * const presence) { diff --git a/src/contact.h b/src/contact.h index a4f487e8..314cf0f4 100644 --- a/src/contact.h +++ b/src/contact.h @@ -27,7 +27,7 @@ typedef struct p_contact_t *PContact; PContact p_contact_new(const char * const jid, const char * const name, const char * const presence, const char * const status, - const char * const subscription); + const char * const subscription, gboolean pending_out); PContact p_contact_copy(PContact contact); void p_contact_free(PContact contact); const char * p_contact_jid(PContact contact); @@ -35,6 +35,7 @@ const char * p_contact_name(PContact contact); const char * p_contact_presence(PContact contact); const char * p_contact_status(PContact contact); const char * p_contact_subscription(const PContact contact); +gboolean p_contact_pending_out(const PContact contact); void p_contact_set_presence(const PContact contact, const char * const presence); void p_contact_set_status(const PContact contact, const char * const status); int p_contacts_equal_deep(const PContact c1, const PContact c2); diff --git a/src/contact_list.c b/src/contact_list.c index 714750dd..4b3b3a03 100644 --- a/src/contact_list.c +++ b/src/contact_list.c @@ -56,13 +56,14 @@ contact_list_reset_search_attempts(void) gboolean contact_list_add(const char * const jid, const char * const name, const char * const presence, const char * const status, - const char * const subscription) + const char * const subscription, gboolean pending_out) { gboolean added = FALSE; PContact contact = g_hash_table_lookup(contacts, jid); if (contact == NULL) { - contact = p_contact_new(jid, name, presence, status, subscription); + contact = p_contact_new(jid, name, presence, status, subscription, + pending_out); g_hash_table_insert(contacts, strdup(jid), contact); p_autocomplete_add(ac, strdup(jid)); added = TRUE; diff --git a/src/contact_list.h b/src/contact_list.h index 90ae947b..0fd27010 100644 --- a/src/contact_list.h +++ b/src/contact_list.h @@ -32,7 +32,7 @@ void contact_list_clear(void); void contact_list_reset_search_attempts(void); gboolean contact_list_add(const char * const jid, const char * const name, const char * const presence, const char * const status, - const char * const subscription); + const char * const subscription, gboolean pending_out); gboolean contact_list_update_contact(const char * const jid, const char * const presence, const char * const status); GSList * get_contact_list(void); diff --git a/src/jabber.c b/src/jabber.c index b1cc6cf5..3a0c23bd 100644 --- a/src/jabber.c +++ b/src/jabber.c @@ -760,7 +760,15 @@ _roster_handler(xmpp_conn_t * const conn, const char *jid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); - gboolean added = contact_list_add(jid, name, "offline", NULL, sub); + + gboolean pending_out = FALSE; + const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); + if ((ask != NULL) && (strcmp(ask, "subscribe") == 0)) { + pending_out = TRUE; + } + + gboolean added = contact_list_add(jid, name, "offline", NULL, sub, + pending_out); if (!added) { log_warning("Attempt to add contact twice: %s", jid); diff --git a/src/room_chat.c b/src/room_chat.c index d84a23fe..a55b8910 100644 --- a/src/room_chat.c +++ b/src/room_chat.c @@ -252,7 +252,7 @@ room_add_to_roster(const char * const room, const char * const nick, updated = TRUE; } - PContact contact = p_contact_new(nick, NULL, show, status, NULL); + PContact contact = p_contact_new(nick, NULL, show, status, NULL, FALSE); g_hash_table_replace(chat_room->roster, strdup(nick), contact); } diff --git a/src/stanza.h b/src/stanza.h index 9992c659..e29aa873 100644 --- a/src/stanza.h +++ b/src/stanza.h @@ -67,6 +67,7 @@ #define STANZA_ATTR_SUBSCRIPTION "subscription" #define STANZA_ATTR_XMLNS "xmlns" #define STANZA_ATTR_NICK "nick" +#define STANZA_ATTR_ASK "ask" #define STANZA_TEXT_AWAY "away" #define STANZA_TEXT_DND "dnd"