public override void Accept() { base.Accept(); RoomAffiliation affiliation = RoomAffiliation.none; if (ownerRadioButton.Checked) { affiliation = RoomAffiliation.owner; } else if (adminRadioButton.Checked) { affiliation = RoomAffiliation.admin; } else if (memberRadioButton.Checked) { affiliation = RoomAffiliation.member; } else if (outcastRadioButton.Checked) { affiliation = RoomAffiliation.outcast; } m_Room.ChangeAffiliation(m_Participant.RealJID, affiliation, reasonLineEdit.Text); Gui.CenterWidgetOnScreen(this); }
/// <summary> /// Get all of the participants that are in a given room affiliation. /// </summary> /// <param name="affiliation">The role to search for</param> /// <returns></returns> public RoomParticipant[] GetParticipantsByAffiliation(RoomAffiliation affiliation) { ArrayList res = new ArrayList(m_hash.Count); foreach (RoomParticipant party in m_hash.Values) { if (party.Affiliation == affiliation) res.Add(party); } return (RoomParticipant[])res.ToArray(typeof(RoomParticipant)); }
/// <summary> /// Retrieve all of the parties with a given affiliiation. /// Modify the affiliations of persons in this list, then call ModifyAffiliations /// </summary> /// <param name="affiliation">The affiliation to search for</param> /// <param name="callback">A callback to receive the participant list</param> /// <param name="state">Caller state information</param> public void RetrieveListByAffiliation(RoomAffiliation affiliation, RoomParticipantsEvent callback, object state) { if (callback == null) throw new ArgumentNullException("callback"); /* <iq from='[email protected]/throne' id='ban2' to='*****@*****.**' type='get'> <query xmlns='http://jabber.org/protocol/muc#admin'> <item affiliation='outcast'/> </query> </iq> */ RoomAdminIQ iq = new RoomAdminIQ(m_manager.Stream.Document); iq.To = m_room; AdminQuery query = iq.Instruction; query.AddItem().Affiliation = affiliation; m_manager.BeginIQ(iq, new IqCB(GotList), new RetrieveParticipantsState(callback, state)); }
/// <summary> /// Change the affiliation (long-term) with the room of a user, based on their real JID. /// </summary> /// <param name="jid">The bare JID of the user of which to change the affiliation</param> /// <param name="affiliation">The new affiliation</param> /// <param name="reason">The reason for the change</param> public void ChangeAffiliation(JID jid, RoomAffiliation affiliation, string reason) { if (m_state != STATE.running) throw new InvalidOperationException("Must be in running state to change affiliation: " + m_state.ToString()); if (jid == null) throw new ArgumentNullException("jid"); if (affiliation == RoomAffiliation.UNSPECIFIED) throw new ArgumentNullException("affiliation"); /* <iq from='[email protected]/throne' id='ban1' to='*****@*****.**' type='set'> <query xmlns='http://jabber.org/protocol/muc#admin'> <item affiliation='outcast' jid='*****@*****.**'> <reason>Treason</reason> </item> </query> </iq> */ RoomAdminIQ iq = new RoomAdminIQ(m_manager.Stream.Document); iq.To = m_room; iq.Type = IQType.set; AdminQuery query = iq.Instruction; AdminItem item = query.AddItem(); item.JID = jid; item.Affiliation = affiliation; item.Reason = reason; m_manager.BeginIQ(iq, null, null); }
public bool Input(Presence stanza) { string canonFrom = stanza.From.ToString().ToLower(); //Handle error case if (stanza.Type == PresenceType.Error) { //Check if the error relates to a pending room join operation TaskCompletionSource <JoinRoomResult> pendingRoomJoin = null; if (m_pendingRoomJoins.TryGetValue(canonFrom, out pendingRoomJoin)) { pendingRoomJoin.SetException(Util.ExceptionFromError(stanza.Data["error"], "Failed to join room " + stanza.From.ToString())); m_pendingRoomJoins.TryRemove(canonFrom, out pendingRoomJoin); return(true); } //Check if the error relates to a pending room leave operation TaskCompletionSource <bool> pendingRoomLeave = null; if (m_pendingRoomLeaves.TryGetValue(canonFrom, out pendingRoomLeave)) { pendingRoomLeave.SetException(Util.ExceptionFromError(stanza.Data["error"], "Failed to leave room " + stanza.From.ToString())); m_pendingRoomLeaves.TryRemove(canonFrom, out pendingRoomLeave); return(true); } } //Handle success case var x = stanza.Data["x"]; if (x != null && x.NamespaceURI == "http://jabber.org/protocol/muc#user") { var itemNode = x["item"]; if (itemNode != null) { //See if the result relates to a pending room join operation TaskCompletionSource <JoinRoomResult> pendingRoomJoin = null; if (m_pendingRoomJoins.TryGetValue(canonFrom, out pendingRoomJoin)) { //Parse room affiliation and role RoomAffiliation affiliation = RoomAffiliation.None; if (itemNode.HasAttribute("affiliation")) { string a = itemNode.GetAttribute("affiliation"); Enum.TryParse <RoomAffiliation>(a, true, out affiliation); } RoomRole role = RoomRole.None; if (itemNode.HasAttribute("role")) { Enum.TryParse <RoomRole>(itemNode.GetAttribute("role"), true, out role); } var result = new JoinRoomResult() { Affiliation = affiliation, Role = role }; Exception createException = null; //For rooms that don't exist, the server will create a new room and respond with a role of "owner" if (affiliation == RoomAffiliation.Owner) { //Server should respond with status code 201 to indicate room created. Search for it... //N.B. Prosody doesn't seem to include this node and just auto creates a default room bool created = false; foreach (XmlNode node in x.ChildNodes) { if (node.Name == "status") { var code = node.Attributes["code"]; if (code != null && code.InnerText == "201") { created = true; break; } } } if (created) { //If the room was created, the server expects confirmation of room settings //Send off a request to accept default instant room settings Jid roomJid = new Jid(stanza.From.Domain, stanza.From.Node); var response = im.IqRequest(Core.IqType.Set, roomJid, im.Jid, Xml.Element("query", "http://jabber.org/protocol/muc#owner").Child(Xml.Element("x", "jabber:x:data").Attr("type", "submit"))); if (response.Type == Core.IqType.Error) { createException = Util.ExceptionFromError(response, "Failed to join room " + roomJid); } } } if (createException != null) { pendingRoomJoin.SetException(createException); } else { pendingRoomJoin.SetResult(result); } m_pendingRoomJoins.TryRemove(canonFrom, out pendingRoomJoin); return(true); } //See if the result relates to a pending room leave operation TaskCompletionSource <bool> pendingRoomLeave = null; if (m_pendingRoomLeaves.TryGetValue(canonFrom, out pendingRoomLeave)) { pendingRoomLeave.SetResult(true); m_pendingRoomLeaves.TryRemove(canonFrom, out pendingRoomLeave); return(true); } } } return(false); }