mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Dealt with online notifications when no show
This commit is contained in:
parent
bcef3b1a49
commit
2b743ea9ac
@ -35,8 +35,9 @@ struct _contact_node_t {
|
||||
static struct _contact_node_t *_contact_list = NULL;
|
||||
|
||||
static struct _contact_node_t * _make_contact_node(const char * const name,
|
||||
const char * const show);
|
||||
static contact_t * _new_contact(const char * const name, const char * const show);
|
||||
const char * const show, const char * const status);
|
||||
static contact_t * _new_contact(const char * const name, const char * const show,
|
||||
const char * const status);
|
||||
static void _destroy_contact(contact_t *contact);
|
||||
|
||||
void contact_list_clear(void)
|
||||
@ -85,11 +86,12 @@ int contact_list_remove(const char * const name)
|
||||
}
|
||||
}
|
||||
|
||||
int contact_list_add(const char * const name, const char * const show)
|
||||
int contact_list_add(const char * const name, const char * const show,
|
||||
const char * const status)
|
||||
{
|
||||
|
||||
if (!_contact_list) {
|
||||
_contact_list = _make_contact_node(name, show);
|
||||
_contact_list = _make_contact_node(name, show, status);
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
@ -99,17 +101,8 @@ int contact_list_add(const char * const name, const char * const show)
|
||||
while(curr) {
|
||||
contact_t *curr_contact = curr->contact;
|
||||
if (strcmp(curr_contact->name, name) == 0) {
|
||||
if (curr_contact->show != NULL) {
|
||||
free(curr_contact->show);
|
||||
curr_contact->show = NULL;
|
||||
|
||||
if (show != NULL) {
|
||||
curr_contact->show =
|
||||
(char *) malloc((strlen(show) + 1) * sizeof(char));
|
||||
strcpy(curr_contact->show, show);
|
||||
}
|
||||
}
|
||||
|
||||
_destroy_contact(curr->contact);
|
||||
curr->contact = _new_contact(name, show, status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -117,7 +110,7 @@ int contact_list_add(const char * const name, const char * const show)
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
curr = _make_contact_node(name, show);
|
||||
curr = _make_contact_node(name, show, status);
|
||||
|
||||
if (prev)
|
||||
prev->next = curr;
|
||||
@ -143,7 +136,8 @@ contact_list_t *get_contact_list(void)
|
||||
while(curr) {
|
||||
contact_t *curr_contact = curr->contact;
|
||||
list->contacts[count] =
|
||||
_new_contact(curr_contact->name, curr_contact->show);
|
||||
_new_contact(curr_contact->name, curr_contact->show,
|
||||
curr_contact->status);
|
||||
count++;
|
||||
curr = curr->next;
|
||||
}
|
||||
@ -155,27 +149,36 @@ contact_list_t *get_contact_list(void)
|
||||
}
|
||||
|
||||
struct _contact_node_t * _make_contact_node(const char * const name,
|
||||
const char * const show)
|
||||
const char * const show, const char * const status)
|
||||
{
|
||||
struct _contact_node_t *new =
|
||||
(struct _contact_node_t *) malloc(sizeof(struct _contact_node_t));
|
||||
new->contact = _new_contact(name, show);
|
||||
new->contact = _new_contact(name, show, status);
|
||||
new->next = NULL;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
static contact_t * _new_contact(const char * const name, const char * const show)
|
||||
static contact_t * _new_contact(const char * const name, const char * const show,
|
||||
const char * const status)
|
||||
{
|
||||
contact_t *new = (contact_t *) malloc(sizeof(contact_t));
|
||||
new->name = (char *) malloc((strlen(name) + 1) * sizeof(char));
|
||||
strcpy(new->name, name);
|
||||
|
||||
if (show != NULL) {
|
||||
if (show == NULL || (strcmp(show, "") == 0)) {
|
||||
new->show = (char *) malloc((strlen("online") + 1) * sizeof(char));
|
||||
strcpy(new->show, "online");
|
||||
} else {
|
||||
new->show = (char *) malloc((strlen(show) + 1) * sizeof(char));
|
||||
strcpy(new->show, show);
|
||||
}
|
||||
|
||||
if (status != NULL) {
|
||||
new->status = (char *) malloc((strlen(status) + 1) * sizeof(char));
|
||||
strcpy(new->status, status);
|
||||
} else {
|
||||
new->show = NULL;
|
||||
new->status = NULL;
|
||||
}
|
||||
|
||||
return new;
|
||||
@ -185,9 +188,10 @@ static void _destroy_contact(contact_t *contact)
|
||||
{
|
||||
free(contact->name);
|
||||
|
||||
if (contact->show != NULL) {
|
||||
if (contact->show != NULL)
|
||||
free(contact->show);
|
||||
}
|
||||
if (contact->status != NULL)
|
||||
free(contact->status);
|
||||
|
||||
free(contact);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
typedef struct _contact {
|
||||
char *name;
|
||||
char *show;
|
||||
char *status;
|
||||
} contact_t;
|
||||
|
||||
typedef struct _contact_list_t {
|
||||
@ -34,7 +35,8 @@ typedef struct _contact_list_t {
|
||||
} contact_list_t;
|
||||
|
||||
void contact_list_clear(void);
|
||||
int contact_list_add(const char * const name, const char * const show);
|
||||
int contact_list_add(const char * const name, const char * const show,
|
||||
const char * const status);
|
||||
int contact_list_remove(const char * const name);
|
||||
contact_list_t * get_contact_list(void);
|
||||
|
||||
|
2
jabber.c
2
jabber.c
@ -324,7 +324,7 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn,
|
||||
if (strcmp(short_jid, short_from) !=0) {
|
||||
if (type == NULL) {// online
|
||||
win_contact_online(short_from, show_str, status_str);
|
||||
contact_list_add(short_from, show_str);
|
||||
contact_list_add(short_from, show_str, status_str);
|
||||
} else {// offline
|
||||
win_contact_offline(short_from, show_str, status_str);
|
||||
contact_list_remove(short_from);
|
||||
|
@ -15,14 +15,14 @@ static void empty_list_when_none_added(void)
|
||||
|
||||
static void contains_one_element(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
assert_int_equals(1, list->size);
|
||||
}
|
||||
|
||||
static void first_element_correct(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
contact_t *james = list->contacts[0];
|
||||
|
||||
@ -31,8 +31,8 @@ static void first_element_correct(void)
|
||||
|
||||
static void contains_two_elements(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
|
||||
assert_int_equals(2, list->size);
|
||||
@ -40,8 +40,8 @@ static void contains_two_elements(void)
|
||||
|
||||
static void first_and_second_elements_correct(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
contact_t *james = list->contacts[0];
|
||||
contact_t *dave = list->contacts[1];
|
||||
@ -52,9 +52,9 @@ static void first_and_second_elements_correct(void)
|
||||
|
||||
static void contains_three_elements(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
|
||||
assert_int_equals(3, list->size);
|
||||
@ -62,9 +62,9 @@ static void contains_three_elements(void)
|
||||
|
||||
static void first_three_elements_correct(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
contact_t *james = list->contacts[0];
|
||||
contact_t *dave = list->contacts[1];
|
||||
@ -77,10 +77,10 @@ static void first_three_elements_correct(void)
|
||||
|
||||
static void add_twice_at_beginning_adds_once(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
contact_t *james = list->contacts[0];
|
||||
contact_t *dave = list->contacts[1];
|
||||
@ -94,10 +94,10 @@ static void add_twice_at_beginning_adds_once(void)
|
||||
|
||||
static void add_twice_in_middle_adds_once(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
contact_t *james = list->contacts[0];
|
||||
contact_t *dave = list->contacts[1];
|
||||
@ -111,10 +111,10 @@ static void add_twice_in_middle_adds_once(void)
|
||||
|
||||
static void add_twice_at_end_adds_once(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_t *list = get_contact_list();
|
||||
contact_t *james = list->contacts[0];
|
||||
contact_t *dave = list->contacts[1];
|
||||
@ -136,7 +136,7 @@ static void remove_when_none_does_nothing(void)
|
||||
|
||||
static void remove_when_one_removes(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_remove("James");
|
||||
contact_list_t *list = get_contact_list();
|
||||
|
||||
@ -145,8 +145,8 @@ static void remove_when_one_removes(void)
|
||||
|
||||
static void remove_first_when_two(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
|
||||
contact_list_remove("James");
|
||||
contact_list_t *list = get_contact_list();
|
||||
@ -158,8 +158,8 @@ static void remove_first_when_two(void)
|
||||
|
||||
static void remove_second_when_two(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
|
||||
contact_list_remove("Dave");
|
||||
contact_list_t *list = get_contact_list();
|
||||
@ -171,9 +171,9 @@ static void remove_second_when_two(void)
|
||||
|
||||
static void remove_first_when_three(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
|
||||
contact_list_remove("James");
|
||||
contact_list_t *list = get_contact_list();
|
||||
@ -188,9 +188,9 @@ static void remove_first_when_three(void)
|
||||
|
||||
static void remove_second_when_three(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
|
||||
contact_list_remove("Dave");
|
||||
contact_list_t *list = get_contact_list();
|
||||
@ -205,9 +205,9 @@ static void remove_second_when_three(void)
|
||||
|
||||
static void remove_third_when_three(void)
|
||||
{
|
||||
contact_list_add("James", NULL);
|
||||
contact_list_add("Dave", NULL);
|
||||
contact_list_add("Bob", NULL);
|
||||
contact_list_add("James", NULL, NULL);
|
||||
contact_list_add("Dave", NULL, NULL);
|
||||
contact_list_add("Bob", NULL, NULL);
|
||||
|
||||
contact_list_remove("Bob");
|
||||
contact_list_t *list = get_contact_list();
|
||||
|
@ -245,7 +245,9 @@ void cons_show_online_contacts(const contact_list_t * const list)
|
||||
wattron(_cons_win, COLOR_PAIR(2));
|
||||
wprintw(_cons_win, "%s", contact->name);
|
||||
if (contact->show)
|
||||
wprintw(_cons_win, ", %s", contact->show);
|
||||
wprintw(_cons_win, " is %s", contact->show);
|
||||
if (contact->status)
|
||||
wprintw(_cons_win, ", \"%s\"", contact->status);
|
||||
wprintw(_cons_win, "\n");
|
||||
wattroff(_cons_win, COLOR_PAIR(2));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user