1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-22 19:45:54 -04:00

Handle room presence notifications

This commit is contained in:
James Booth 2012-11-05 21:36:32 +00:00
parent 0deba9e13e
commit 2f6361a578
6 changed files with 53 additions and 2 deletions

View File

@ -1014,8 +1014,8 @@ _cmd_join(const char * const inp, struct cmd_help_t help)
strcpy(jid_cpy, jid);
nick = strdup(strtok(jid_cpy, "@"));
}
jabber_join(room_jid, nick);
win_join_chat(room_jid, nick);
}
}

View File

@ -605,7 +605,12 @@ _presence_handler(xmpp_conn_t * const conn,
char *from = xmpp_stanza_get_attribute(stanza, "from");
if (room_jid_is_room_chat(from)) {
cons_show("CHAT ROOM PRESENCE RECIEVED");
char **tokens = g_strsplit(from, "/", 0);
char *room_jid = tokens[0];
char *nick = tokens[1];
if (strcmp(room_get_nick_for_room(room_jid), nick) != 0) {
win_show_chat_room_member(room_jid, nick);
}
} else {
char *short_from = strtok(from, "/");
char *type = xmpp_stanza_get_attribute(stanza, "type");

View File

@ -58,3 +58,17 @@ room_jid_is_room_chat(const char * const jid)
}
char *
room_get_nick_for_room(const char * const jid)
{
GSList *current = rooms;
while (current != NULL) {
muc_room *room = current->data;
if (strcmp(jid, room->jid) == 0) {
return room->nick;
}
current = g_slist_next(current);
}
return NULL;
}

View File

@ -24,3 +24,4 @@
void room_join(const char * const jid, const char * const nick);
gboolean room_jid_is_room_chat(const char * const jid);
char * room_get_nick_for_room(const char * const jid);

View File

@ -103,6 +103,10 @@ void win_show(const char * const msg);
void win_bad_show(const char * const msg);
void win_remind(void);
void win_join_chat(const char * const room_jid, const char * const nick);
void win_show_chat_room_member(const char * const room_jid,
const char * const nick);
// console window actions
void cons_about(void);
void cons_help(void);

View File

@ -470,6 +470,33 @@ win_show_outgoing_msg(const char * const from, const char * const to,
_win_switch_if_active(win_index);
}
void
win_join_chat(const char * const room_jid, const char * const nick)
{
int win_index = _find_prof_win_index(room_jid);
// create new window
if (win_index == NUM_WINS) {
win_index = _new_prof_win(room_jid);
}
_win_switch_if_active(win_index);
}
void
win_show_chat_room_member(const char * const room_jid, const char * const nick)
{
int win_index = _find_prof_win_index(room_jid);
WINDOW *win = _wins[win_index].win;
wattron(win, COLOUR_ONLINE);
wprintw(win, "%s\n", nick);
wattroff(win, COLOUR_ONLINE);
if (win_index == _curr_prof_win)
dirty = TRUE;
}
void
win_show(const char * const msg)
{