--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/fix-receipts Sun Jul 17 23:05:54 2011 +0300
@@ -0,0 +1,157 @@
+# HG changeset patch
+# Parent 18f757abb3ead106adc6d4ccaa16cdf9b6faf86a
+
+diff -r 18f757abb3ea mcabber/mcabber/hbuf.c
+--- a/mcabber/mcabber/hbuf.c Wed Jun 08 02:47:30 2011 +0000
++++ b/mcabber/mcabber/hbuf.c Sun Jul 17 23:05:20 2011 +0300
+@@ -525,7 +525,7 @@
+ // hbuf_remove_receipt(hbuf, xep184)
+ // Remove the Receipt Flag for the message with the given xep184 id
+ // Returns TRUE if it was found and removed, otherwise FALSE
+-gboolean hbuf_remove_receipt(GList *hbuf, gpointer xep184)
++gboolean hbuf_remove_receipt(GList *hbuf, gconstpointer xep184)
+ {
+ hbuf_block *blk;
+
+@@ -533,7 +533,8 @@
+
+ for ( ; hbuf; hbuf = g_list_previous(hbuf)) {
+ blk = (hbuf_block*)(hbuf->data);
+- if (blk->prefix.xep184 == xep184) {
++ if (!g_strcmp0 (blk->prefix.xep184, xep184)) {
++ g_free (blk->prefix.xep184);
+ blk->prefix.xep184 = NULL;
+ blk->prefix.flags ^= HBB_PREFIX_RECEIPT;
+ return TRUE;
+diff -r 18f757abb3ea mcabber/mcabber/hbuf.h
+--- a/mcabber/mcabber/hbuf.h Wed Jun 08 02:47:30 2011 +0000
++++ b/mcabber/mcabber/hbuf.h Sun Jul 17 23:05:20 2011 +0300
+@@ -50,7 +50,7 @@
+ GList *hbuf_jump_date(GList *hbuf, time_t t);
+ GList *hbuf_jump_percent(GList *hbuf, int pc);
+ GList *hbuf_jump_readmark(GList *hbuf);
+-gboolean hbuf_remove_receipt(GList *hbuf, gpointer xep184);
++gboolean hbuf_remove_receipt(GList *hbuf, gconstpointer xep184);
+ void hbuf_set_readmark(GList *hbuf, gboolean action);
+ void hbuf_remove_trailing_readmark(GList *hbuf);
+
+diff -r 18f757abb3ea mcabber/mcabber/screen.c
+--- a/mcabber/mcabber/screen.c Wed Jun 08 02:47:30 2011 +0000
++++ b/mcabber/mcabber/screen.c Sun Jul 17 23:05:20 2011 +0300
+@@ -2220,7 +2220,7 @@
+ scr_show_window(jidto, FALSE);
+ }
+
+-void scr_remove_receipt_flag(const char *bjid, gpointer xep184)
++void scr_remove_receipt_flag(const char *bjid, gconstpointer xep184)
+ {
+ winbuf *win_entry = scr_search_window(bjid, FALSE);
+ if (win_entry) {
+diff -r 18f757abb3ea mcabber/mcabber/screen.h
+--- a/mcabber/mcabber/screen.h Wed Jun 08 02:47:30 2011 +0000
++++ b/mcabber/mcabber/screen.h Sun Jul 17 23:05:20 2011 +0300
+@@ -108,7 +108,7 @@
+ void scr_update_main_status(int forceupdate);
+ void scr_update_chat_status(int forceupdate);
+ void scr_roster_visibility(int status);
+-void scr_remove_receipt_flag(const char *jidto, gpointer xep184);
++void scr_remove_receipt_flag(const char *jidto, gconstpointer xep184);
+ void scr_show_buddy_window(void);
+ int scr_buddy_buffer_exists(const char *jid);
+ void scr_update_buddy_window(void);
+diff -r 18f757abb3ea mcabber/mcabber/xmpp.c
+--- a/mcabber/mcabber/xmpp.c Wed Jun 08 02:47:30 2011 +0000
++++ b/mcabber/mcabber/xmpp.c Sun Jul 17 23:05:20 2011 +0300
+@@ -300,15 +300,6 @@
+ g_slist_free(resources);
+ }
+
+-static LmHandlerResult cb_xep184(LmMessageHandler *h, LmConnection *c,
+- LmMessage *m, gpointer user_data)
+-{
+- char *from = jidtodisp(lm_message_get_from(m));
+- scr_remove_receipt_flag(from, h);
+- g_free(from);
+- return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+-}
+-
+ // xmpp_send_msg(jid, text, type, subject,
+ // otrinject, *encrypted, type_overwrite)
+ // When encrypted is not NULL, the function set *encrypted to 1 if the
+@@ -435,7 +426,8 @@
+ lm_message_node_set_attribute
+ (lm_message_node_add_child(x->node, "request", NULL),
+ "xmlns", NS_RECEIPTS);
+- *xep184 = lm_message_handler_new(cb_xep184, NULL, NULL);
++ *xep184 = lm_get_uid ();
++ lm_message_node_set_attribute (x->node, "id", (const gchar *)*xep184);
+ }
+
+ #if defined XEP0022 || defined XEP0085
+@@ -499,11 +491,7 @@
+ if (mystatus != invisible)
+ #endif
+ update_last_use();
+- if (xep184 && *xep184) {
+- lm_connection_send_with_reply(lconnection, x, *xep184, NULL);
+- lm_message_handler_unref(*xep184);
+- } else
+- lm_connection_send(lconnection, x, NULL);
++ lm_connection_send(lconnection, x, NULL);
+ lm_message_unref(x);
+ }
+
+@@ -1302,6 +1290,16 @@
+ lm_message_unref(rcvd);
+ }
+
++ { // xep184 receipt confirmation
++ LmMessageNode *received = lm_message_node_get_child (m->node, "received");
++ if (received && !g_strcmp0 (lm_message_node_get_attribute (received, "xmlns"), NS_RECEIPTS)) {
++ char *jid = jidtodisp(from);
++ const char *id = lm_message_node_get_attribute (received, "id");
++ scr_remove_receipt_flag(jid, id);
++ g_free(jid);
++ }
++ }
++
+ if (from) {
+ x = lm_message_node_find_xmlns(m->node, NS_MUC_USER);
+ if (x && !strcmp(x->name, "x"))
+diff -r 18f757abb3ea mcabber/mcabber/xmpp_helper.c
+--- a/mcabber/mcabber/xmpp_helper.c Wed Jun 08 02:47:30 2011 +0000
++++ b/mcabber/mcabber/xmpp_helper.c Sun Jul 17 23:05:20 2011 +0300
+@@ -72,7 +72,6 @@
+ {0, NULL, NULL, NULL, NULL}
+ };
+
+-
+ #ifdef MODULES_ENABLE
+ static GSList *xmpp_additional_features = NULL;
+ static char *ver, *ver_notavail;
+@@ -104,6 +103,13 @@
+ }
+ #endif
+
++// The caller must g_free this after use
++gchar *lm_get_uid ()
++{
++ static guint xmpp_uid = 0;
++ return g_strdup_printf ("mc%u", ++xmpp_uid);
++}
++
+ const gchar* lm_message_node_get_child_value(LmMessageNode *node,
+ const gchar *child)
+ {
+diff -r 18f757abb3ea mcabber/mcabber/xmpp_helper.h
+--- a/mcabber/mcabber/xmpp_helper.h Wed Jun 08 02:47:30 2011 +0000
++++ b/mcabber/mcabber/xmpp_helper.h Sun Jul 17 23:05:20 2011 +0300
+@@ -29,6 +29,8 @@
+ void xmpp_del_feature (const char *xmlns);
+ #endif
+
++gchar *lm_get_uid (void);
++
+ LmMessageNode *lm_message_node_new(const gchar *name, const gchar *xmlns);
+ LmMessageNode *lm_message_node_find_xmlns(LmMessageNode *node,
+ const char *xmlns);