mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Contact list synch with server
This commit is contained in:
parent
7a9d127ae2
commit
cfc2307808
2
Makefile
2
Makefile
@ -12,7 +12,7 @@ profanity: $(OBJS)
|
||||
$(CC) -o profanity $(OBJS) $(LIBS)
|
||||
|
||||
log.o: log.h
|
||||
windows.o: windows.h util.h
|
||||
windows.o: windows.h util.h contact_list.h
|
||||
title_bar.o: windows.h
|
||||
status_bar.o: windows.h util.h
|
||||
input_win.o: windows.h
|
||||
|
@ -149,12 +149,7 @@ static int _cmd_who(void)
|
||||
static int _cmd_pres(void)
|
||||
{
|
||||
struct contact_list *list = get_contact_list();
|
||||
|
||||
int i;
|
||||
for (i = 0; i < list->size; i++) {
|
||||
char *contact = list->contacts[i];
|
||||
cons_show(contact);
|
||||
}
|
||||
cons_show_online_contacts(list);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -32,7 +32,31 @@ void contact_list_clear(void)
|
||||
|
||||
int contact_list_remove(char *contact)
|
||||
{
|
||||
return 0;
|
||||
if (!_contact_list) {
|
||||
return 0;
|
||||
} else {
|
||||
struct _contact_t *curr = _contact_list;
|
||||
struct _contact_t *prev = NULL;
|
||||
|
||||
while(curr) {
|
||||
if (strcmp(curr->contact, contact) == 0) {
|
||||
if (prev)
|
||||
prev->next = curr->next;
|
||||
else
|
||||
_contact_list = curr->next;
|
||||
|
||||
free(curr->contact);
|
||||
free(curr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int contact_list_add(char *contact)
|
||||
@ -81,7 +105,6 @@ struct contact_list *get_contact_list(void)
|
||||
(char *) malloc((strlen(curr->contact) + 1) * sizeof(char));
|
||||
strcpy(list->contacts[count], curr->contact);
|
||||
count++;
|
||||
|
||||
curr = curr->next;
|
||||
}
|
||||
}
|
||||
|
9
jabber.c
9
jabber.c
@ -244,13 +244,13 @@ static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
|
||||
jid = xmpp_stanza_get_attribute(item, "jid");
|
||||
|
||||
if (name != NULL) {
|
||||
char line[2 + strlen(name) + 2 + strlen(jid) + 1 + 1];
|
||||
sprintf(line, " %s (%s)", name, jid);
|
||||
char line[strlen(name) + 2 + strlen(jid) + 1 + 1];
|
||||
sprintf(line, "%s (%s)", name, jid);
|
||||
cons_show(line);
|
||||
|
||||
} else {
|
||||
char line[2 + strlen(jid) + 1];
|
||||
sprintf(line, " %s", jid);
|
||||
char line[strlen(jid) + 1];
|
||||
sprintf(line, "%s", jid);
|
||||
cons_show(line);
|
||||
}
|
||||
|
||||
@ -316,6 +316,7 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn,
|
||||
contact_list_add(short_from);
|
||||
} else {// offline
|
||||
win_contact_offline(short_from, show_str, status_str);
|
||||
contact_list_remove(short_from);
|
||||
}
|
||||
|
||||
win_page_off();
|
||||
|
@ -113,7 +113,7 @@ static void add_twice_at_end_adds_once(void)
|
||||
assert_string_equals("Bob", list->contacts[2]);
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
static void remove_when_none_does_nothing(void)
|
||||
{
|
||||
contact_list_remove("James");
|
||||
@ -195,7 +195,7 @@ static void remove_third_when_three(void)
|
||||
assert_int_equals(2, list->size);
|
||||
assert_string_equals("James", list->contacts[0]);
|
||||
assert_string_equals("Dave", list->contacts[1]);
|
||||
}*/
|
||||
}
|
||||
|
||||
void register_contact_list_tests(void)
|
||||
{
|
||||
@ -211,12 +211,11 @@ void register_contact_list_tests(void)
|
||||
TEST(add_twice_at_beginning_adds_once);
|
||||
TEST(add_twice_in_middle_adds_once);
|
||||
TEST(add_twice_at_end_adds_once);
|
||||
/* TEST(remove_when_none_does_nothing);
|
||||
TEST(remove_when_none_does_nothing);
|
||||
TEST(remove_when_one_removes);
|
||||
TEST(remove_first_when_two);
|
||||
TEST(remove_second_when_two);
|
||||
TEST(remove_first_when_three);
|
||||
TEST(remove_second_when_three);
|
||||
TEST(remove_third_when_three);
|
||||
*/
|
||||
}
|
||||
|
37
windows.c
37
windows.c
@ -211,24 +211,35 @@ void cons_help(void)
|
||||
_win_show_time(_cons_win);
|
||||
wprintw(_cons_win, "Help:\n");
|
||||
|
||||
cons_show(" Commands:");
|
||||
cons_show(" /help : This help.");
|
||||
cons_show(" /connect user@host : Login to jabber.");
|
||||
cons_show(" /who : Get roster.");
|
||||
cons_show(" /close : Close a chat window.");
|
||||
cons_show(" /msg user@host mesg : Send mesg to user.");
|
||||
cons_show(" /quit : Quit Profanity.");
|
||||
cons_show(" Keys:");
|
||||
cons_show(" F1 : This console window.");
|
||||
cons_show(" F2-10 : Chat windows.");
|
||||
cons_show(" UP, DOWN : Navigate input history.");
|
||||
cons_show(" LEFT, RIGHT : Edit current input.");
|
||||
cons_show(" PAGE UP, PAGE DOWN : Page the chat window.");
|
||||
cons_show("/help : This help.");
|
||||
cons_show("/connect user@host : Login to jabber.");
|
||||
cons_show("/who : Get roster.");
|
||||
cons_show("/close : Close a chat window.");
|
||||
cons_show("/msg user@host mesg : Send mesg to user.");
|
||||
cons_show("/quit : Quit Profanity.");
|
||||
cons_show("F1 : This console window.");
|
||||
cons_show("F2-10 : Chat windows.");
|
||||
cons_show("UP, DOWN : Navigate input history.");
|
||||
cons_show("LEFT, RIGHT : Edit current input.");
|
||||
cons_show("PAGE UP, PAGE DOWN : Page the chat window.");
|
||||
|
||||
if (_curr_prof_win == 0)
|
||||
dirty = TRUE;
|
||||
}
|
||||
|
||||
void cons_show_online_contacts(struct contact_list *list)
|
||||
{
|
||||
_win_show_time(_cons_win);
|
||||
wprintw(_cons_win, "Online contacts:\n");
|
||||
|
||||
int i;
|
||||
for (i = 0; i < list->size; i++) {
|
||||
char *contact = list->contacts[i];
|
||||
cons_show(contact);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void cons_bad_show(char *msg)
|
||||
{
|
||||
_win_show_time(_cons_win);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define WINDOWS_h
|
||||
|
||||
#include <ncurses.h>
|
||||
#include "contact_list.h"
|
||||
|
||||
struct prof_win {
|
||||
char from[100];
|
||||
@ -60,6 +61,7 @@ void win_handle_page(int *ch);
|
||||
void win_page_off(void);
|
||||
void win_contact_online(char *from, char *show, char *status);
|
||||
void win_contact_offline(char *from, char *show, char *status);
|
||||
void cons_show_online_contacts(struct contact_list *list);
|
||||
|
||||
// console window actions
|
||||
void cons_help(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user