Distinguish between sent and received messages
authorThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Tue, 25 Nov 2008 02:50:07 +0000 (00:50 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 9 May 2011 01:13:11 +0000 (22:13 -0300)
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.

chat.c

diff --git a/chat.c b/chat.c
index 253340b..090652c 100644 (file)
--- 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);
 }