Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/chat.c @ 26884:af2b87aa82ee
Add ability to list roles/affiliations in a chat via slash-commands and
modify roles/affiliations of multiple users at a time. Closes #5649.
Slightly modified patch from Andrei Mozzhuhin. The multiple-user support
is inefficient; all the changes can go in one stanza. We should also
actually track roles/affiliations of members since ejabberd's MUC won't
respond to the list query for a non-admin.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 03 May 2009 19:53:53 +0000 |
parents | 06da00c70eae |
children | eeee4309d3d8 |
comparison
equal
deleted
inserted
replaced
26881:ea2306f2f886 | 26884:af2b87aa82ee |
---|---|
914 jabber_iq_send(iq); | 914 jabber_iq_send(iq); |
915 | 915 |
916 return TRUE; | 916 return TRUE; |
917 } | 917 } |
918 | 918 |
919 static void | |
920 jabber_chat_affiliation_list_cb(JabberStream *js, const char *from, | |
921 JabberIqType type, const char *id, | |
922 xmlnode *packet, gpointer data) | |
923 { | |
924 JabberChat *chat; | |
925 xmlnode *query, *item; | |
926 int chat_id = GPOINTER_TO_INT(data); | |
927 GString *buf; | |
928 | |
929 if(!(chat = jabber_chat_find_by_id(js, chat_id))) | |
930 return; | |
931 | |
932 if (type == JABBER_IQ_ERROR) | |
933 return; | |
934 | |
935 if(!(query = xmlnode_get_child(packet, "query"))) | |
936 return; | |
937 | |
938 buf = g_string_new(_("Affiliations:")); | |
939 | |
940 item = xmlnode_get_child(query, "item"); | |
941 if (item) { | |
942 for( ; item; item = xmlnode_get_next_twin(item)) { | |
943 const char *jid = xmlnode_get_attrib(item, "jid"); | |
944 const char *affiliation = xmlnode_get_attrib(item, "affiliation"); | |
945 if (jid && affiliation) | |
946 g_string_append_printf(buf, "\n%s %s", jid, affiliation); | |
947 } | |
948 } else { | |
949 buf = g_string_append_c(buf, '\n'); | |
950 buf = g_string_append_len(buf, _("No users found"), -1); | |
951 } | |
952 | |
953 purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf->str, | |
954 PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
955 | |
956 g_string_free(buf, TRUE); | |
957 } | |
958 | |
959 gboolean jabber_chat_affiliation_list(JabberChat *chat, const char *affiliation) | |
960 { | |
961 JabberIq *iq; | |
962 char *room_jid; | |
963 xmlnode *query, *item; | |
964 | |
965 iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, | |
966 "http://jabber.org/protocol/muc#admin"); | |
967 | |
968 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
969 xmlnode_set_attrib(iq->node, "to", room_jid); | |
970 | |
971 query = xmlnode_get_child(iq->node, "query"); | |
972 item = xmlnode_new_child(query, "item"); | |
973 xmlnode_set_attrib(item, "affiliation", affiliation); | |
974 | |
975 jabber_iq_set_callback(iq, jabber_chat_affiliation_list_cb, GINT_TO_POINTER(chat->id)); | |
976 jabber_iq_send(iq); | |
977 | |
978 return TRUE; | |
979 } | |
980 | |
919 gboolean jabber_chat_role_user(JabberChat *chat, const char *who, const char *role) | 981 gboolean jabber_chat_role_user(JabberChat *chat, const char *who, const char *role) |
920 { | 982 { |
921 char *to; | 983 char *to; |
922 JabberIq *iq; | 984 JabberIq *iq; |
923 xmlnode *query, *item; | 985 xmlnode *query, *item; |
938 query = xmlnode_get_child(iq->node, "query"); | 1000 query = xmlnode_get_child(iq->node, "query"); |
939 item = xmlnode_new_child(query, "item"); | 1001 item = xmlnode_new_child(query, "item"); |
940 xmlnode_set_attrib(item, "nick", jcm->handle); | 1002 xmlnode_set_attrib(item, "nick", jcm->handle); |
941 xmlnode_set_attrib(item, "role", role); | 1003 xmlnode_set_attrib(item, "role", role); |
942 | 1004 |
1005 jabber_iq_send(iq); | |
1006 | |
1007 return TRUE; | |
1008 } | |
1009 | |
1010 static void jabber_chat_role_list_cb(JabberStream *js, const char *from, | |
1011 JabberIqType type, const char *id, | |
1012 xmlnode *packet, gpointer data) | |
1013 { | |
1014 JabberChat *chat; | |
1015 xmlnode *query, *item; | |
1016 int chat_id = GPOINTER_TO_INT(data); | |
1017 GString *buf; | |
1018 | |
1019 if(!(chat = jabber_chat_find_by_id(js, chat_id))) | |
1020 return; | |
1021 | |
1022 if (type == JABBER_IQ_ERROR) | |
1023 return; | |
1024 | |
1025 if(!(query = xmlnode_get_child(packet, "query"))) | |
1026 return; | |
1027 | |
1028 buf = g_string_new(_("Roles:")); | |
1029 | |
1030 item = xmlnode_get_child(query, "item"); | |
1031 if (item) { | |
1032 for( ; item; item = xmlnode_get_next_twin(item)) { | |
1033 const char *jid = xmlnode_get_attrib(item, "jid"); | |
1034 const char *role = xmlnode_get_attrib(item, "role"); | |
1035 if (jid && role) | |
1036 g_string_append_printf(buf, "\n%s %s", jid, role); | |
1037 } | |
1038 } else { | |
1039 buf = g_string_append_c(buf, '\n'); | |
1040 buf = g_string_append_len(buf, _("No users found"), -1); | |
1041 } | |
1042 | |
1043 purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf->str, | |
1044 PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL)); | |
1045 | |
1046 g_string_free(buf, TRUE); | |
1047 } | |
1048 | |
1049 gboolean jabber_chat_role_list(JabberChat *chat, const char *role) | |
1050 { | |
1051 JabberIq *iq; | |
1052 char *room_jid; | |
1053 xmlnode *query, *item; | |
1054 | |
1055 iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, | |
1056 "http://jabber.org/protocol/muc#admin"); | |
1057 | |
1058 room_jid = g_strdup_printf("%s@%s", chat->room, chat->server); | |
1059 xmlnode_set_attrib(iq->node, "to", room_jid); | |
1060 | |
1061 query = xmlnode_get_child(iq->node, "query"); | |
1062 item = xmlnode_new_child(query, "item"); | |
1063 xmlnode_set_attrib(item, "role", role); | |
1064 | |
1065 jabber_iq_set_callback(iq, jabber_chat_role_list_cb, GINT_TO_POINTER(chat->id)); | |
943 jabber_iq_send(iq); | 1066 jabber_iq_send(iq); |
944 | 1067 |
945 return TRUE; | 1068 return TRUE; |
946 } | 1069 } |
947 | 1070 |