1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-30 21:55:24 +00:00

Subscription management

This commit is contained in:
James Booth 2012-10-28 21:16:22 +00:00
parent d13794bf60
commit 4e0a631fee
4 changed files with 68 additions and 39 deletions

View File

@ -59,6 +59,11 @@ p_contact_new(const char * const jid, const char * const name,
else
contact->status = NULL;
if (subscription != NULL)
contact->subscription = strdup(subscription);
else
contact->subscription = NULL;
return contact;
}
@ -81,6 +86,11 @@ p_contact_copy(PContact contact)
else
copy->status = NULL;
if (contact->subscription != NULL)
copy->subscription = strdup(contact->subscription);
else
copy->subscription = NULL;
return copy;
}
@ -107,6 +117,11 @@ p_contact_free(PContact contact)
contact->status = NULL;
}
if (contact->subscription != NULL) {
free(contact->subscription);
contact->subscription = NULL;
}
free(contact);
contact = NULL;
}
@ -135,6 +150,12 @@ p_contact_status(const PContact contact)
return contact->status;
}
const char *
p_contact_subscription(const PContact contact)
{
return contact->subscription;
}
int
p_contacts_equal_deep(const PContact c1, const PContact c2)
{
@ -142,6 +163,7 @@ p_contacts_equal_deep(const PContact c1, const PContact c2)
int name_eq = (g_strcmp0(c1->name, c2->name) == 0);
int presence_eq = (g_strcmp0(c1->presence, c2->presence) == 0);
int status_eq = (g_strcmp0(c1->status, c2->status) == 0);
int subscription_eq = (g_strcmp0(c1->subscription, c2->subscription) == 0);
return (jid_eq && name_eq && presence_eq && status_eq);
return (jid_eq && name_eq && presence_eq && status_eq && subscription_eq);
}

View File

@ -34,6 +34,7 @@ const char * p_contact_jid(PContact contact);
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);
int p_contacts_equal_deep(const PContact c1, const PContact c2);
#endif

View File

@ -386,14 +386,8 @@ _roster_handler(xmpp_conn_t * const conn,
const char *jid = xmpp_stanza_get_attribute(item, "jid");
const char *name = xmpp_stanza_get_attribute(item, "name");
const char *sub = xmpp_stanza_get_attribute(item, "subscription");
contact_list_add(jid, name, "offline", NULL, sub);
if (sub != NULL) {
if (strcmp(sub, "none") != 0) {
contact_list_add(jid, name, "offline", NULL, sub);
}
}
item = xmpp_stanza_get_next(item);
}
/*

View File

@ -703,44 +703,56 @@ cons_show_contacts(GSList *list)
while(curr) {
PContact contact = curr->data;
const char *jid = p_contact_jid(contact);
const char *name = p_contact_name(contact);
const char *presence = p_contact_presence(contact);
const char *status = p_contact_status(contact);
const char *sub = p_contact_subscription(contact);
_win_show_time(_cons_win);
if (strcmp(sub, "none") != 0) {
_win_show_time(_cons_win);
if (strcmp(presence, "online") == 0) {
wattron(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattron(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattron(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattron(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattron(_cons_win, COLOUR_XA);
} else {
wattron(_cons_win, COLOUR_OFFLINE);
}
if (strcmp(presence, "online") == 0) {
wattron(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattron(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattron(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattron(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattron(_cons_win, COLOUR_XA);
} else {
wattron(_cons_win, COLOUR_OFFLINE);
}
wprintw(_cons_win, "%s", p_contact_jid(contact));
wprintw(_cons_win, " is %s", presence);
wprintw(_cons_win, "%s", jid);
if (p_contact_status(contact))
wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
if (name != NULL) {
wprintw(_cons_win, " (%s)", name);
}
wprintw(_cons_win, "\n");
wprintw(_cons_win, " is %s", presence);
if (strcmp(presence, "online") == 0) {
wattroff(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattroff(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattroff(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattroff(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattroff(_cons_win, COLOUR_XA);
} else {
wattroff(_cons_win, COLOUR_OFFLINE);
if (status != NULL) {
wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
}
wprintw(_cons_win, "\n");
if (strcmp(presence, "online") == 0) {
wattroff(_cons_win, COLOUR_ONLINE);
} else if (strcmp(presence, "away") == 0) {
wattroff(_cons_win, COLOUR_AWAY);
} else if (strcmp(presence, "chat") == 0) {
wattroff(_cons_win, COLOUR_CHAT);
} else if (strcmp(presence, "dnd") == 0) {
wattroff(_cons_win, COLOUR_DND);
} else if (strcmp(presence, "xa") == 0) {
wattroff(_cons_win, COLOUR_XA);
} else {
wattroff(_cons_win, COLOUR_OFFLINE);
}
}
curr = g_slist_next(curr);