From: Thadeu Lima de Souza Cascardo Date: Tue, 25 Nov 2008 02:50:07 +0000 (-0200) Subject: Distinguish between sent and received messages X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fchat.git;a=commitdiff_plain;h=355d729787870575a0ed4795553a300271222bca Distinguish between sent and received messages Prefix every message in the textview with a character indicating its direction, print the destination in case it is a sent message and do not print messages that do not have a source nor destination. --- diff --git a/chat.c b/chat.c index 253340b..090652c 100644 --- a/chat.c +++ b/chat.c @@ -39,18 +39,33 @@ hc_xmpp_chat (hc_xmpp_t *xmpp, iks *message) GtkTextIter textiter; char *str; char *from; + char *to; char *body; + int sent; str = iks_string (iks_stack (message), message); write (fd, str, strlen (str)); - if ((from = iks_find_attrib (message, "from")) == NULL) - from = ""; - if ((body = iks_cdata (iks_child (iks_find (message, "body")))) == NULL) - body = ""; + from = iks_find_attrib (message, "from"); + to = iks_find_attrib (message, "to"); + if (from == NULL) + sent = 1; + if (sent && to == NULL) + return; + body = iks_cdata (iks_child (iks_find (message, "body"))); textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview)); gtk_text_buffer_get_end_iter (textbuffer, &textiter); - gtk_text_buffer_insert (textbuffer, &textiter, from, -1); + if (sent) + { + gtk_text_buffer_insert (textbuffer, &textiter, "> ", -1); + gtk_text_buffer_insert (textbuffer, &textiter, to, -1); + } + else + { + gtk_text_buffer_insert (textbuffer, &textiter, "< ", -1); + gtk_text_buffer_insert (textbuffer, &textiter, from, -1); + } gtk_text_buffer_insert (textbuffer, &textiter, ": ", -1); - gtk_text_buffer_insert (textbuffer, &textiter, body, -1); + if (body) + gtk_text_buffer_insert (textbuffer, &textiter, body, -1); gtk_text_buffer_insert (textbuffer, &textiter, "\n", -1); }