Mercurial > ~mikael > mcabber > hg
diff mcabber/src/xmpp.c @ 1602:f4a2c6f767d1
Message Receipts support (XEP-0184)
author | franky |
---|---|
date | Wed, 24 Sep 2008 11:41:29 +0200 |
parents | c5ee395fbc8c |
children | 351427ef0b4b |
line wrap: on
line diff
--- a/mcabber/src/xmpp.c Sun Oct 11 15:59:20 2009 +0200 +++ b/mcabber/src/xmpp.c Wed Sep 24 11:41:29 2008 +0200 @@ -314,6 +314,15 @@ 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_RemoveReceiptFlag(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 @@ -321,7 +330,7 @@ // encryption fails, *encrypted is set to -1. void xmpp_send_msg(const char *fjid, const char *text, int type, const char *subject, gboolean otrinject, gint *encrypted, - LmMessageSubType type_overwrite) + LmMessageSubType type_overwrite, gpointer *xep184) { LmMessage *x; LmMessageSubType subtype; @@ -433,6 +442,16 @@ g_free(enc); } + //XEP-0184: Message Receipts + if (sl_buddy && rname && xep184 && + caps_has_feature(buddy_resource_getcaps(sl_buddy->data, rname), + NS_RECEIPTS)) { + 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); + } + #if defined JEP0022 || defined JEP0085 // If typing notifications are disabled, we can skip all this stuff... if (chatstates_disabled || type == ROSTER_TYPE_ROOM) @@ -492,7 +511,11 @@ xmpp_send_msg_no_chatstates: if (mystatus != invisible) update_last_use(); - lm_connection_send(lconnection, x, NULL); + 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_message_unref(x); } @@ -1243,6 +1266,16 @@ if (from && (body || subject)) gotmessage(lm_message_get_sub_type(m), from, body, enc, subject, timestamp, lm_message_node_find_xmlns(m->node, NS_SIGNED)); + //report received message if message receipt was requested + if (lm_message_node_get_child(m->node, "request")) { + LmMessage *rcvd = lm_message_new(from, LM_MESSAGE_TYPE_MESSAGE); + lm_message_node_set_attribute(rcvd->node, "id", lm_message_get_id(m)); + lm_message_node_set_attribute + (lm_message_node_add_child(rcvd->node, "received", NULL), + "xmlns", NS_RECEIPTS); + lm_connection_send(connection, rcvd, NULL); + lm_message_unref(rcvd); + } if (from) { x = lm_message_node_find_xmlns(m->node,