1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Handle subject from room

This commit is contained in:
James Booth 2012-11-10 03:30:27 +00:00
parent 7799623b4a
commit be2fb1c809
8 changed files with 73 additions and 2 deletions

View File

@ -338,8 +338,22 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
{
char *room = NULL;
char *nick = NULL;
char *message = NULL;
xmpp_stanza_t *subject = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_SUBJECT);
gchar *room_jid = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
// handle subject
if (subject != NULL) {
message = xmpp_stanza_get_text(subject);
if (message != NULL) {
room = room_get_room_for_full_jid(room_jid);
prof_handle_room_subject(room, message);
}
return 1;
}
// room jid not of form room/nick
if (!room_parse_room_jid(room_jid, &room, &nick)) {
log_error("Could not parse room jid: %s", room_jid);
g_free(room);
@ -348,6 +362,7 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
return 1;
}
// room not active in profanity
if (!room_is_active(room_jid)) {
log_error("Message recieved for inactive groupchat: %s", room_jid);
g_free(room);
@ -356,9 +371,9 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
return 1;
}
char *message = NULL;
xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
if (body != NULL) {
message = xmpp_stanza_get_text(body);
}

View File

@ -199,6 +199,13 @@ prof_handle_room_message(const char * const room_jid, const char * const nick,
win_page_off();
}
void
prof_handle_room_subject(const char * const room_jid, const char * const subject)
{
win_show_room_subject(room_jid, subject);
win_page_off();
}
void
prof_handle_room_roster_complete(const char * const room)
{

View File

@ -40,6 +40,8 @@ void prof_handle_room_history(const char * const room_jid,
const char * const nick, GTimeVal tv_stamp, const char * const message);
void prof_handle_room_message(const char * const room_jid, const char * const nick,
const char * const message);
void prof_handle_room_subject(const char * const room_jid,
const char * const subject);
void prof_handle_room_roster_complete(const char * const room);
void prof_handle_room_member_online(const char * const room,
const char * const nick, const char * const show, const char * const status);

View File

@ -97,6 +97,23 @@ room_get_nick_for_room(const char * const jid)
}
}
char *
room_get_room_for_full_jid(const char * const jid)
{
char **tokens = g_strsplit(jid, "/", 0);
char *room;
if (tokens == NULL || tokens[0] == NULL) {
return NULL;
} else {
room = strdup(tokens[0]);
g_strfreev(tokens);
return room;
}
}
gboolean
room_parse_room_jid(const char * const room_jid, char **room, char **nick)
{

View File

@ -29,6 +29,7 @@ void room_join(const char * const jid, const char * const nick);
void room_leave(const char * const jid);
gboolean room_is_active(const char * const jid);
char * room_get_nick_for_room(const char * const jid);
char * room_get_room_for_full_jid(const char * const jid);
gboolean room_parse_room_jid(const char * const room_jid, char **room,
char **nick);
void room_add_to_roster(const char * const jid, const char * const nick);

View File

@ -43,6 +43,7 @@
#define STANZA_NAME_ERROR "error"
#define STANZA_NAME_PING "ping"
#define STANZA_NAME_TEXT "text"
#define STANZA_NAME_SUBJECT "subject"
#define STANZA_TYPE_CHAT "chat"
#define STANZA_TYPE_GROUPCHAT "groupchat"

View File

@ -113,6 +113,8 @@ void win_show_room_history(const char * const room_jid, const char * const nick,
GTimeVal tv_stamp, const char * const message);
void win_show_room_message(const char * const room_jid, const char * const nick,
const char * const message);
void win_show_room_subject(const char * const room_jid,
const char * const subject);
void win_show_room_member_offline(const char * const room, const char * const nick);
void win_show_room_member_online(const char * const room, const char * const nick);

View File

@ -563,9 +563,13 @@ win_show_room_roster(const char * const room)
GList *roster = room_get_roster(room);
if ((roster == NULL) || (g_list_length(roster) == 0)) {
wattron(win, COLOUR_INC);
wprintw(win, "You are alone!\n");
wattroff(win, COLOUR_INC);
} else {
wattron(win, COLOUR_INC);
wprintw(win, "Room occupants:\n");
wattroff(win, COLOUR_INC);
wattron(win, COLOUR_ONLINE);
while (roster != NULL) {
@ -683,6 +687,28 @@ win_show_room_message(const char * const room_jid, const char * const nick,
}
}
void
win_show_room_subject(const char * const room_jid, const char * const subject)
{
int win_index = _find_prof_win_index(room_jid);
WINDOW *win = _wins[win_index].win;
wattron(win, COLOUR_INC);
wprintw(win, "Room subject: ");
wattroff(win, COLOUR_INC);
wprintw(win, "%s\n", subject);
// currently in groupchat window
if (win_index == _curr_prof_win) {
status_bar_active(win_index);
dirty = TRUE;
// not currenlty on groupchat window
} else {
status_bar_new(win_index);
}
}
void
win_show(const char * const msg)
{