comparison mcabber/src/jabglue.c @ 989:859ab76e5093

Send JEP-22 delivered messages
author Mikael Berthe <mikael@lilotux.net>
date Tue, 31 Oct 2006 20:30:29 +0100
parents 6e2bfd1ffded
children 35e7913affb7
comparison
equal deleted inserted replaced
988:6e2bfd1ffded 989:859ab76e5093
492 event = xmlnode_insert_tag(x, "x"); 492 event = xmlnode_insert_tag(x, "x");
493 xmlnode_put_attrib(event, "xmlns", NS_EVENT); 493 xmlnode_put_attrib(event, "xmlns", NS_EVENT);
494 xmlnode_insert_tag(event, "composing"); 494 xmlnode_insert_tag(event, "composing");
495 495
496 // An id is mandatory when using JEP-0022. 496 // An id is mandatory when using JEP-0022.
497 if (!msgid) { 497 if (!msgid && (text || subject)) {
498 struct jep0022 *jep22;
498 msgid = new_msgid(); 499 msgid = new_msgid();
499 // FIXME update last_msgid_sent 500 // Let's update last_msgid_sent
500 // We do not update it when the msgid is provided by the caller, 501 // (We do not update it when the msgid is provided by the caller,
501 // because this is probably a special message (e.g. delivered...) 502 // because this is probably a special message...)
503 if (sl_buddy)
504 jep22 = buddy_resource_jep22(sl_buddy->data, rname);
505 if (jep22) {
506 g_free(jep22->last_msgid_sent);
507 jep22->last_msgid_sent = g_strdup(msgid);
508 }
502 } 509 }
503 } 510 }
504 #endif 511 #endif
505 512
506 xmlnode_put_attrib(x, "id", msgid); 513 xmlnode_put_attrib(x, "id", msgid);
508 jab_send(jc, x); 515 jab_send(jc, x);
509 xmlnode_free(x); 516 xmlnode_free(x);
510 517
511 jb_reset_keepalive(); 518 jb_reset_keepalive();
512 } 519 }
520
521 #ifdef JEP0022
522 // jb_send_jep22_event()
523 // Send a JEP-22 message event (delivered, composing...).
524 void jb_send_jep22_event(const char *jid, guint type)
525 {
526 xmlnode x;
527 xmlnode event;
528 const char *msgid;
529 char *rname, *barejid;
530 GSList *sl_buddy;
531 struct jep0022 *jep22 = NULL;
532
533 if (!online) return;
534
535 rname = strchr(jid, JID_RESOURCE_SEPARATOR);
536 barejid = jidtodisp(jid);
537 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
538 g_free(barejid);
539
540 // If we can get a resource name, we use it. Else we use NULL,
541 // which hopefully will give us the most likely resource.
542 if (rname)
543 rname++;
544 if (sl_buddy)
545 jep22 = buddy_resource_jep22(sl_buddy->data, rname);
546
547 if (jep22)
548 msgid = jep22->last_msgid_rcvd;
549
550 x = jutil_msgnew(TMSG_CHAT, (char*)jid, NULL, NULL);
551
552 event = xmlnode_insert_tag(x, "x");
553 xmlnode_put_attrib(event, "xmlns", NS_EVENT);
554 if (type == ROSTER_EVENT_DELIVERED)
555 xmlnode_insert_tag(event, "delivered");
556 else if (type == ROSTER_EVENT_COMPOSING)
557 xmlnode_insert_tag(event, "composing");
558 xmlnode_put_attrib(event, "id", (msgid ? msgid : ""));
559
560 jab_send(jc, x);
561 xmlnode_free(x);
562
563 jb_reset_keepalive();
564 }
565 #endif
513 566
514 // jb_subscr_send_auth(jid) 567 // jb_subscr_send_auth(jid)
515 // Allow jid to receive our presence updates 568 // Allow jid to receive our presence updates
516 void jb_subscr_send_auth(const char *jid) 569 void jb_subscr_send_auth(const char *jid)
517 { 570 {
1584 if (jep85->last_state_rcvd == ROSTER_EVENT_COMPOSING) 1637 if (jep85->last_state_rcvd == ROSTER_EVENT_COMPOSING)
1585 events = ROSTER_EVENT_COMPOSING; 1638 events = ROSTER_EVENT_COMPOSING;
1586 else 1639 else
1587 events = ROSTER_EVENT_NONE; 1640 events = ROSTER_EVENT_NONE;
1588 } else { /* JEP-0022 */ 1641 } else { /* JEP-0022 */
1642 #ifdef JEP0022
1589 const char *msgid; 1643 const char *msgid;
1590 jep22->support = CHATSTATES_SUPPORT_OK; 1644 jep22->support = CHATSTATES_SUPPORT_OK;
1591 jep22->last_state_rcvd = ROSTER_EVENT_NONE; 1645 jep22->last_state_rcvd = ROSTER_EVENT_NONE;
1592 1646
1593 msgid = xmlnode_get_attrib(xmldata, "id"); 1647 msgid = xmlnode_get_attrib(xmldata, "id");
1602 1656
1603 } else { 1657 } else {
1604 events &= ~ROSTER_EVENT_COMPOSING; 1658 events &= ~ROSTER_EVENT_COMPOSING;
1605 } 1659 }
1606 1660
1607 if (xmlnode_get_tag(state_ns, "delivered"))
1608 jep22->last_state_rcvd |= ROSTER_EVENT_DELIVERED;
1609
1610 // Cache the message id 1661 // Cache the message id
1611 g_free(jep22->last_msgid_rcvd); 1662 g_free(jep22->last_msgid_rcvd);
1612 if (msgid) 1663 if (msgid)
1613 jep22->last_msgid_rcvd = g_strdup(msgid); 1664 jep22->last_msgid_rcvd = g_strdup(msgid);
1614 else 1665 else
1615 jep22->last_msgid_rcvd = NULL; 1666 jep22->last_msgid_rcvd = NULL;
1667
1668 if (xmlnode_get_tag(state_ns, "delivered")) {
1669 jep22->last_state_rcvd |= ROSTER_EVENT_DELIVERED;
1670
1671 // Do we have to send back an ACK?
1672 if (body)
1673 jb_send_jep22_event(from, ROSTER_EVENT_DELIVERED);
1674 }
1675 #endif
1616 } 1676 }
1617 1677
1618 buddy_resource_setevents(sl_buddy->data, rname, events); 1678 buddy_resource_setevents(sl_buddy->data, rname, events);
1619 1679
1620 update_roster = TRUE; 1680 update_roster = TRUE;