/// <summary> /// Modify the roles of the parties in this list. /// To use, retrive a ParticipantCollection, change the roles /// of the parties in that collection, then pass that modified /// collection in here. /// </summary> /// <param name="parties">The modified participant collection</param> /// <param name="reason">The reason for the change</param> /// <param name="callback">A callback to call when complete. Will have a null IQ if there were no changes to make.</param> /// <param name="state">Caller's state information</param> public void ModifyAffiliations(ParticipantCollection parties, string reason, IqCB callback, object state) { /* <iq from='*****@*****.**' id='ban2' to='[email protected]/throne' type='result'> <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; int count = 0; foreach (RoomParticipant party in parties) { if (party.Changed && (party.RealJID != null)) { count++; AdminItem item = query.AddItem(); item.JID = party.RealJID; item.Affiliation = party.Affiliation; item.Reason = reason; } } if (count > 0) m_manager.BeginIQ(iq, callback, state); else callback(this, null, state); }
/// <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); }
/// <summary> /// Modify the roles of the parties in this list. /// To use, retrive a ParticipantCollection, change the roles /// of the parties in that collection, then pass that modified /// collection in here. /// </summary> /// <param name="parties">The modified participant collection</param> /// <param name="reason">The reason for the change</param> /// <param name="callback">A callback to call when complete. Will have a null IQ if there were no changes to make.</param> /// <param name="state">Caller's state information</param> public void ModifyRoles(ParticipantCollection parties, string reason, IqCB callback, object state) { /* <iq from='[email protected]/globe' id='voice4' to='*****@*****.**' type='set'> <query xmlns='http://jabber.org/protocol/muc#admin'> <item nick='Hecate' role='visitor'/> <item nick='rosencrantz' role='participant'> <reason>A worthy fellow.</reason> </item> <item nick='guildenstern' role='participant'> <reason>A worthy fellow.</reason> </item> </query> </iq> */ RoomAdminIQ iq = new RoomAdminIQ(m_manager.Stream.Document); iq.To = m_room; iq.Type = IQType.set; AdminQuery query = iq.Instruction; int count = 0; foreach (RoomParticipant party in parties) { if (party.Changed) { count++; AdminItem item = query.AddItem(); item.Nick = party.Nick; item.Role = party.Role; item.Reason = reason; } } if (count > 0) m_manager.BeginIQ(iq, callback, state); else callback(this, null, state); }
/// <summary> /// Retrieve all of the parties with a given role. /// Modify the affiliations of persons in this list, then call ModifyRoles /// </summary> /// <param name="role">The role to search for</param> /// <param name="callback">A callback to receive the participant list</param> /// <param name="state">Caller state information</param> public void RetrieveListByRole(RoomRole role, RoomParticipantsEvent callback, object state) { if (callback == null) throw new ArgumentNullException("callback"); /* <iq from='[email protected]/globe' id='voice3' to='*****@*****.**' type='get'> <query xmlns='http://jabber.org/protocol/muc#admin'> <item role='participant'/> </query> </iq> */ RoomAdminIQ iq = new RoomAdminIQ(m_manager.Stream.Document); iq.To = m_room; AdminQuery query = iq.Instruction; query.AddItem().Role = role; m_manager.BeginIQ(iq, new IqCB(GotList), new RetrieveParticipantsState(callback, state)); }
/// <summary> /// Change the role of a user in the room, by nickname. Must be a moderator. /// </summary> /// <param name="nick">The nickname of the user to modify.</param> /// <param name="role">The new role</param> /// <param name="reason">The reason for the change</param> public void ChangeRole(string nick, RoomRole role, string reason) { if (m_state != STATE.running) throw new InvalidOperationException("Must be in running state to change role: " + m_state.ToString()); if (nick == null) throw new ArgumentNullException("nick"); if (role == RoomRole.UNSPECIFIED) throw new ArgumentNullException("role"); /* <iq from='[email protected]/pda' id='kick1' to='*****@*****.**' type='set'> <query xmlns='http://jabber.org/protocol/muc#admin'> <item nick='pistol' role='none'> <reason>Avaunt, you cullion!</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.Nick = nick; item.Role = role; item.Reason = reason; m_manager.BeginIQ(iq, null, null); }