changeset 1019:9d5f6e0ea7b3

XEP-0145: display note dates Display note creation/modification dates (if available) in /roster note.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 15 Nov 2006 22:24:20 +0100
parents 45d022fbce3a
children 60c94b697f61
files mcabber/src/commands.c mcabber/src/jabglue.c mcabber/src/jabglue.h
diffstat 3 files changed, 59 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Wed Nov 15 19:27:59 2006 +0100
+++ b/mcabber/src/commands.c	Wed Nov 15 22:24:20 2006 +0100
@@ -470,7 +470,7 @@
 static void roster_note(char *arg)
 {
   const char *jid;
-  gchar *msg, *note;
+  gchar *msg, *notetxt;
   guint type;
 
   if (!current_buddy)
@@ -493,19 +493,48 @@
 
   if (msg) {    // Set a note
     if (!strcmp(msg, "-"))
-      note = NULL; // delete note
+      notetxt = NULL; // delete note
     else
-      note = msg;
-    jb_set_storage_rosternotes(jid, note);
+      notetxt = msg;
+    jb_set_storage_rosternotes(jid, notetxt);
+    g_free(msg);
   } else {      // Display a note
-    note = jb_get_storage_rosternotes(jid);
-    if (note)
-      msg = g_strdup_printf("Note: %s", note);
-    else
-      msg = g_strdup_printf("This item doesn't have a note.");
-    scr_WriteIncomingMessage(jid, msg, 0, HBB_PREFIX_INFO);
+    struct annotation *note = jb_get_storage_rosternotes(jid);
+    if (note) {
+      char tbuf[128];
+      guint msg_flag = HBB_PREFIX_INFO;
+      /* We use the flag prefix_info for the first line, and prefix_none
+         for the other lines, for better readability */
+
+      // If we have the creation date, display it
+      if (note->cdate) {
+        strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S",
+                 localtime(&note->cdate));
+        msg = g_strdup_printf("Note created  %s", tbuf);
+        scr_WriteIncomingMessage(jid, msg, 0, msg_flag);
+        g_free(msg);
+        msg_flag = HBB_PREFIX_NONE;
+      }
+      // If we have the modification date, display it
+      if (note->mdate) {
+        strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S",
+                 localtime(&note->mdate));
+        msg = g_strdup_printf("Note modified %s", tbuf);
+        scr_WriteIncomingMessage(jid, msg, 0, msg_flag);
+        g_free(msg);
+        msg_flag = HBB_PREFIX_NONE;
+      }
+      // Note text
+      msg = g_strdup_printf("Note: %s", note->text);
+      scr_WriteIncomingMessage(jid, msg, 0, msg_flag);
+      g_free(note->text);
+      g_free(note);
+      g_free(msg);
+    } else {
+      scr_WriteIncomingMessage(jid, "This item doesn't have a note.", 0,
+                               HBB_PREFIX_INFO);
+    }
   }
-  g_free(msg);
 }
 
 /* Commands callback functions */
--- a/mcabber/src/jabglue.c	Wed Nov 15 19:27:59 2006 +0100
+++ b/mcabber/src/jabglue.c	Wed Nov 15 22:24:20 2006 +0100
@@ -1239,9 +1239,9 @@
 }
 
 //  jb_get_storage_rosternotes(barejid)
-// Return thenote associated to this jid.
-// The caller should g_free the string after use.
-char *jb_get_storage_rosternotes(const char *barejid)
+// Return the annotation associated with this jid.
+// The caller should g_free the string and structure after use.
+struct annotation *jb_get_storage_rosternotes(const char *barejid)
 {
   xmlnode x;
 
@@ -1268,7 +1268,15 @@
         continue;
       if (!strcmp(jid, barejid)) {
         // We've found a note for this contact.
-        return g_strdup(xmlnode_get_data(x));
+        struct annotation *note = g_new0(struct annotation, 1);
+        p = xmlnode_get_attrib(x, "cdate");
+        if (p)
+          note->cdate = from_iso8601(p, 1);
+        p = xmlnode_get_attrib(x, "mdate");
+        if (p)
+          note->mdate = from_iso8601(p, 1);
+        note->text = g_strdup(xmlnode_get_data(x));
+        return note;
       }
     }
   }
--- a/mcabber/src/jabglue.h	Wed Nov 15 19:27:59 2006 +0100
+++ b/mcabber/src/jabglue.h	Wed Nov 15 22:24:20 2006 +0100
@@ -35,6 +35,12 @@
   iqreq_vcard
 };
 
+struct annotation {
+  time_t cdate;
+  time_t mdate;
+  gchar *text;
+};
+
 char *compose_jid(const char *username, const char *servername,
                   const char *resource);
 jconn jb_connect(const char *jid, const char *server, unsigned int port,
@@ -71,7 +77,7 @@
 void jb_set_storage_bookmark(const char *roomid, const char *name,
                              const char *nick, const char *passwd,
                              int autojoin);
-char *jb_get_storage_rosternotes(const char *barejid);
+struct annotation *jb_get_storage_rosternotes(const char *barejid);
 void jb_set_storage_rosternotes(const char *barejid, const char *note);
 
 #endif /* __JABGLUE_H__ */