comparison mcabber/mcabber/xmpp.c @ 2032:f740c4128f76

Fix receipts handling according to recent XEP updates * add lm_get_uid() @xmpp_helper.h * identify receipts by id attribute of 'received' subelement instead of stanza id
author Myhailo Danylenko <isbear@ukrpost.net>
date Sun, 14 Oct 2012 17:39:11 +0200
parents 107d39cd968b
children a37fbc3ac6aa
comparison
equal deleted inserted replaced
2031:2b13be73351d 2032:f740c4128f76
291 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fulljid); 291 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fulljid);
292 g_free(fulljid); 292 g_free(fulljid);
293 g_free(p_res->data); 293 g_free(p_res->data);
294 } 294 }
295 g_slist_free(resources); 295 g_slist_free(resources);
296 }
297
298 static LmHandlerResult cb_xep184(LmMessageHandler *h, LmConnection *c,
299 LmMessage *m, gpointer user_data)
300 {
301 char *from = jidtodisp(lm_message_get_from(m));
302 scr_remove_receipt_flag(from, h);
303 g_free(from);
304 return LM_HANDLER_RESULT_REMOVE_MESSAGE;
305 } 296 }
306 297
307 // xmpp_send_msg(jid, text, type, subject, 298 // xmpp_send_msg(jid, text, type, subject,
308 // otrinject, *encrypted, type_overwrite) 299 // otrinject, *encrypted, type_overwrite)
309 // When encrypted is not NULL, the function set *encrypted to 1 if the 300 // When encrypted is not NULL, the function set *encrypted to 1 if the
427 418
428 // XEP-0184: Message Receipts 419 // XEP-0184: Message Receipts
429 if (sl_buddy && xep184 && 420 if (sl_buddy && xep184 &&
430 caps_has_feature(buddy_resource_getcaps(sl_buddy->data, rname), 421 caps_has_feature(buddy_resource_getcaps(sl_buddy->data, rname),
431 NS_RECEIPTS, barejid)) { 422 NS_RECEIPTS, barejid)) {
432 lm_message_node_set_attribute 423 lm_message_node_set_attribute(lm_message_node_add_child(x->node, "request",
433 (lm_message_node_add_child(x->node, "request", NULL), 424 NULL),
434 "xmlns", NS_RECEIPTS); 425 "xmlns", NS_RECEIPTS);
435 *xep184 = lm_message_handler_new(cb_xep184, NULL, NULL); 426 *xep184 = lm_get_uid ();
427 lm_message_node_set_attribute (x->node, "id", (const gchar *)*xep184);
436 } 428 }
437 g_free(barejid); 429 g_free(barejid);
438 430
439 #if defined XEP0022 || defined XEP0085 431 #if defined XEP0022 || defined XEP0085
440 // If typing notifications are disabled, we can skip all this stuff... 432 // If typing notifications are disabled, we can skip all this stuff...
497 xmpp_send_msg_no_chatstates: 489 xmpp_send_msg_no_chatstates:
498 #ifdef WITH_DEPRECATED_STATUS_INVISIBLE 490 #ifdef WITH_DEPRECATED_STATUS_INVISIBLE
499 if (mystatus != invisible) 491 if (mystatus != invisible)
500 #endif 492 #endif
501 update_last_use(); 493 update_last_use();
502 if (xep184 && *xep184) { 494 lm_connection_send(lconnection, x, NULL);
503 lm_connection_send_with_reply(lconnection, x, *xep184, NULL);
504 lm_message_handler_unref(*xep184);
505 } else
506 lm_connection_send(lconnection, x, NULL);
507 lm_message_unref(x); 495 lm_message_unref(x);
508 } 496 }
509 497
510 #ifdef XEP0085 498 #ifdef XEP0085
511 // xmpp_send_xep85_chatstate() 499 // xmpp_send_xep85_chatstate()
1301 y = lm_message_node_add_child(rcvd->node, "received", NULL); 1289 y = lm_message_node_add_child(rcvd->node, "received", NULL);
1302 lm_message_node_set_attribute(y, "xmlns", NS_RECEIPTS); 1290 lm_message_node_set_attribute(y, "xmlns", NS_RECEIPTS);
1303 lm_message_node_set_attribute(y, "id", mid); 1291 lm_message_node_set_attribute(y, "id", mid);
1304 lm_connection_send(connection, rcvd, NULL); 1292 lm_connection_send(connection, rcvd, NULL);
1305 lm_message_unref(rcvd); 1293 lm_message_unref(rcvd);
1294 }
1295
1296 { // xep184 receipt confirmation
1297 LmMessageNode *received = lm_message_node_get_child(m->node, "received");
1298 if (received && !g_strcmp0(lm_message_node_get_attribute(received, "xmlns"), NS_RECEIPTS)) {
1299 char *jid = jidtodisp(from);
1300 const char *id = lm_message_node_get_attribute(received, "id");
1301 scr_remove_receipt_flag(jid, id);
1302 g_free(jid);
1303 }
1306 } 1304 }
1307 1305
1308 if (from) { 1306 if (from) {
1309 x = lm_message_node_find_xmlns(m->node, NS_MUC_USER); 1307 x = lm_message_node_find_xmlns(m->node, NS_MUC_USER);
1310 if (x && !strcmp(x->name, "x")) 1308 if (x && !strcmp(x->name, "x"))