Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 1091:10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
When sending an "active" status, we send it to all resources which have been
sent another status.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 08 Dec 2006 22:08:05 +0100 |
parents | 2a3cfb98bd5e |
children | 7804dbac3875 |
comparison
equal
deleted
inserted
replaced
1090:fff7ee4cefab | 1091:10f9d6fcfeab |
---|---|
661 | 661 |
662 | 662 |
663 #ifdef JEP0085 | 663 #ifdef JEP0085 |
664 // jb_send_jep85_chatstate() | 664 // jb_send_jep85_chatstate() |
665 // Send a JEP-85 chatstate. | 665 // Send a JEP-85 chatstate. |
666 static void jb_send_jep85_chatstate(const char *fjid, guint state) | 666 static void jb_send_jep85_chatstate(const char *bjid, const char *resname, |
667 guint state) | |
667 { | 668 { |
668 xmlnode x; | 669 xmlnode x; |
669 xmlnode event; | 670 xmlnode event; |
670 char *rname, *barejid; | |
671 GSList *sl_buddy; | 671 GSList *sl_buddy; |
672 const char *chattag; | 672 const char *chattag; |
673 char *rjid, *fjid = NULL; | |
673 struct jep0085 *jep85 = NULL; | 674 struct jep0085 *jep85 = NULL; |
674 | 675 |
675 if (!online) return; | 676 if (!online) return; |
676 | 677 |
677 rname = strchr(fjid, JID_RESOURCE_SEPARATOR); | 678 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER); |
678 barejid = jidtodisp(fjid); | 679 |
679 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); | 680 // If we have a resource name, we use it. Else we use NULL, |
680 g_free(barejid); | |
681 | |
682 // If we can get a resource name, we use it. Else we use NULL, | |
683 // which hopefully will give us the most likely resource. | 681 // which hopefully will give us the most likely resource. |
684 if (rname) | |
685 rname++; | |
686 if (sl_buddy) | 682 if (sl_buddy) |
687 jep85 = buddy_resource_jep85(sl_buddy->data, rname); | 683 jep85 = buddy_resource_jep85(sl_buddy->data, resname); |
688 | 684 |
689 if (!jep85 || (jep85->support != CHATSTATES_SUPPORT_OK)) | 685 if (!jep85 || (jep85->support != CHATSTATES_SUPPORT_OK)) |
690 return; | 686 return; |
691 | 687 |
692 if (state == jep85->last_state_sent) | 688 if (state == jep85->last_state_sent) |
703 return; | 699 return; |
704 } | 700 } |
705 | 701 |
706 jep85->last_state_sent = state; | 702 jep85->last_state_sent = state; |
707 | 703 |
708 x = jutil_msgnew(TMSG_CHAT, (char*)fjid, NULL, NULL); | 704 if (resname) |
705 fjid = g_strdup_printf("%s/%s", bjid, resname); | |
706 | |
707 rjid = resname ? fjid : (char*)bjid; | |
708 x = jutil_msgnew(TMSG_CHAT, rjid, NULL, NULL); | |
709 | 709 |
710 event = xmlnode_insert_tag(x, chattag); | 710 event = xmlnode_insert_tag(x, chattag); |
711 xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES); | 711 xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES); |
712 | 712 |
713 jab_send(jc, x); | 713 jab_send(jc, x); |
714 xmlnode_free(x); | 714 xmlnode_free(x); |
715 | 715 |
716 g_free(fjid); | |
716 jb_reset_keepalive(); | 717 jb_reset_keepalive(); |
717 } | 718 } |
718 #endif | 719 #endif |
719 | 720 |
720 #ifdef JEP0022 | 721 #ifdef JEP0022 |
788 // The message is sent to one of the resources with the highest priority. | 789 // The message is sent to one of the resources with the highest priority. |
789 #if defined JEP0022 || defined JEP0085 | 790 #if defined JEP0022 || defined JEP0085 |
790 void jb_send_chatstate(gpointer buddy, guint chatstate) | 791 void jb_send_chatstate(gpointer buddy, guint chatstate) |
791 { | 792 { |
792 const char *bjid; | 793 const char *bjid; |
793 struct jep0085 *jep85 = NULL; | 794 #ifdef JEP0085 |
794 struct jep0022 *jep22 = NULL; | 795 GSList *resources, *p_res, *p_next; |
796 struct jep0085 *jep85; | |
797 #endif | |
798 #ifdef JEP0022 | |
799 struct jep0022 *jep22; | |
800 #endif | |
795 | 801 |
796 bjid = buddy_getjid(buddy); | 802 bjid = buddy_getjid(buddy); |
797 if (!bjid) return; | 803 if (!bjid) return; |
798 | 804 |
799 #ifdef JEP0085 | 805 #ifdef JEP0085 |
800 jep85 = buddy_resource_jep85(buddy, NULL); | 806 /* Send the chatstate to the last resource (which should have the highest |
801 if (jep85 && jep85->support == CHATSTATES_SUPPORT_OK) { | 807 priority). |
802 jb_send_jep85_chatstate(bjid, chatstate); | 808 If chatstate is "active", send an "active" state to all resources |
803 return; | 809 which do not curently have this state. |
804 } | 810 */ |
811 resources = buddy_getresources(buddy); | |
812 for (p_res = resources ; p_res ; p_res = p_next) { | |
813 p_next = g_slist_next(p_res); | |
814 jep85 = buddy_resource_jep85(buddy, p_res->data); | |
815 if (jep85 && jep85->support == CHATSTATES_SUPPORT_OK) { | |
816 // If p_next is NULL, this is the highest (prio) resource, i.e. | |
817 // the one we are probably writing to. | |
818 if (!p_next || (jep85->last_state_sent != ROSTER_EVENT_ACTIVE && | |
819 chatstate == ROSTER_EVENT_ACTIVE)) | |
820 jb_send_jep85_chatstate(bjid, p_res->data, chatstate); | |
821 } | |
822 g_free(p_res->data); | |
823 } | |
824 g_slist_free(resources); | |
805 #endif | 825 #endif |
806 #ifdef JEP0022 | 826 #ifdef JEP0022 |
807 jep22 = buddy_resource_jep22(buddy, NULL); | 827 jep22 = buddy_resource_jep22(buddy, NULL); |
808 if (jep22 && jep22->support == CHATSTATES_SUPPORT_OK) { | 828 if (jep22 && jep22->support == CHATSTATES_SUPPORT_OK) { |
809 jb_send_jep22_event(bjid, chatstate); | 829 jb_send_jep22_event(bjid, chatstate); |