comparison mcabber/mcabber/xmpp.c @ 2013:8dc418af3e72

Allow to select to which buddy resource messages go. Closes issue #55
author Hermitifier
date Thu, 01 Mar 2012 15:10:41 +0100
parents a73ce708c2c9
children 87049d55e34f
comparison
equal deleted inserted replaced
2012:2039ea6bd7a5 2013:8dc418af3e72
637 // The message is sent to one of the resources with the highest priority. 637 // The message is sent to one of the resources with the highest priority.
638 #if defined XEP0022 || defined XEP0085 638 #if defined XEP0022 || defined XEP0085
639 void xmpp_send_chatstate(gpointer buddy, guint chatstate) 639 void xmpp_send_chatstate(gpointer buddy, guint chatstate)
640 { 640 {
641 const char *bjid; 641 const char *bjid;
642 const char *activeres;
642 #ifdef XEP0085 643 #ifdef XEP0085
643 GSList *resources, *p_res, *p_next; 644 GSList *resources, *p_res, *p_next;
644 struct xep0085 *xep85 = NULL; 645 struct xep0085 *xep85 = NULL;
645 #endif 646 #endif
646 #ifdef XEP0022 647 #ifdef XEP0022
647 struct xep0022 *xep22; 648 struct xep0022 *xep22;
648 #endif 649 #endif
649 650
650 bjid = buddy_getjid(buddy); 651 bjid = buddy_getjid(buddy);
651 if (!bjid) return; 652 if (!bjid) return;
653 activeres = buddy_getactiveresource(buddy);
652 654
653 #ifdef XEP0085 655 #ifdef XEP0085
654 /* Send the chatstate to the last resource (which should have the highest 656 /* Send the chatstate to the last resource (which should have the highest
655 priority). 657 priority).
656 If chatstate is "active", send an "active" state to all resources 658 If chatstate is "active", send an "active" state to all resources
660 for (p_res = resources ; p_res ; p_res = p_next) { 662 for (p_res = resources ; p_res ; p_res = p_next) {
661 p_next = g_slist_next(p_res); 663 p_next = g_slist_next(p_res);
662 xep85 = buddy_resource_xep85(buddy, p_res->data); 664 xep85 = buddy_resource_xep85(buddy, p_res->data);
663 if (xep85 && xep85->support == CHATSTATES_SUPPORT_OK) { 665 if (xep85 && xep85->support == CHATSTATES_SUPPORT_OK) {
664 // If p_next is NULL, this is the highest (prio) resource, i.e. 666 // If p_next is NULL, this is the highest (prio) resource, i.e.
665 // the one we are probably writing to. 667 // the one we are probably writing to - unless there is defined an
666 if (!p_next || (xep85->last_state_sent != ROSTER_EVENT_ACTIVE && 668 // active resource
667 chatstate == ROSTER_EVENT_ACTIVE)) 669 if (!g_strcmp0(p_res->data, activeres) || (!p_next && !activeres) ||
670 (xep85->last_state_sent != ROSTER_EVENT_ACTIVE &&
671 chatstate == ROSTER_EVENT_ACTIVE))
668 xmpp_send_xep85_chatstate(bjid, p_res->data, chatstate); 672 xmpp_send_xep85_chatstate(bjid, p_res->data, chatstate);
669 } 673 }
670 g_free(p_res->data); 674 g_free(p_res->data);
671 } 675 }
672 g_slist_free(resources); 676 g_slist_free(resources);
674 // we don't want to send a XEP22 event. 678 // we don't want to send a XEP22 event.
675 if (xep85 && xep85->support == CHATSTATES_SUPPORT_OK) 679 if (xep85 && xep85->support == CHATSTATES_SUPPORT_OK)
676 return; 680 return;
677 #endif 681 #endif
678 #ifdef XEP0022 682 #ifdef XEP0022
679 xep22 = buddy_resource_xep22(buddy, NULL); 683 xep22 = buddy_resource_xep22(buddy, activeres);
680 if (xep22 && xep22->support == CHATSTATES_SUPPORT_OK) { 684 if (xep22 && xep22->support == CHATSTATES_SUPPORT_OK) {
681 xmpp_send_xep22_event(bjid, chatstate); 685 xmpp_send_xep22_event(bjid, chatstate);
682 } 686 }
683 #endif 687 #endif
684 } 688 }