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

Handle chat history from groupchat

This commit is contained in:
James Booth 2012-11-05 22:21:03 +00:00
parent 83834b96ae
commit ad8845991c
3 changed files with 41 additions and 2 deletions

View File

@ -401,8 +401,25 @@ _message_handler(xmpp_conn_t * const conn,
from = xmpp_stanza_get_attribute(stanza, "from"); from = xmpp_stanza_get_attribute(stanza, "from");
if (room_jid_is_room_chat(from)) { if (room_jid_is_room_chat(from)) {
xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, "delay");
if (delay != NULL) {
char *utc_stamp = xmpp_stanza_get_attribute(delay, "stamp");
GTimeVal tv_stamp;
if(g_time_val_from_iso8601(utc_stamp, &tv_stamp)) {
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
if (body != NULL) {
char *message = xmpp_stanza_get_text(body);
char **tokens = g_strsplit(from, "/", 0);
char *room_jid = tokens[0];
char *nick = tokens[1];
win_show_room_history(room_jid, nick, tv_stamp, message);
}
} else {
log_error("Couldn't parse datetime string receiving room history: %s", utc_stamp);
}
} else {
// handle normal groupchat messages
}
cons_show("CHAT ROOM MESSAGE RECIEVED"); cons_show("CHAT ROOM MESSAGE RECIEVED");
} else { } else {

View File

@ -107,6 +107,8 @@ void win_join_chat(const char * const room_jid, const char * const nick);
void win_show_chat_room_member(const char * const room_jid, void win_show_chat_room_member(const char * const room_jid,
const char * const nick); const char * const nick);
int win_in_groupchat(void); int win_in_groupchat(void);
void win_show_room_history(const char * const room_jid, const char * const nick,
GTimeVal tv_stamp, const char * const message);
// console window actions // console window actions
void cons_about(void); void cons_about(void);

View File

@ -508,6 +508,26 @@ win_show_chat_room_member(const char * const room_jid, const char * const nick)
dirty = TRUE; dirty = TRUE;
} }
void
win_show_room_history(const char * const room_jid, const char * const nick,
GTimeVal tv_stamp, const char * const message)
{
int win_index = _find_prof_win_index(room_jid);
WINDOW *win = _wins[win_index].win;
GDateTime *time = g_date_time_new_from_timeval_utc(&tv_stamp);
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wprintw(win, "%s - ", date_fmt);
g_date_time_unref(time);
g_free(date_fmt);
wprintw(win, "%s: ", nick);
_win_show_message(win, message);
if (win_index == _curr_prof_win)
dirty = TRUE;
}
void void
win_show(const char * const msg) win_show(const char * const msg)
{ {