Example #1
0
        /// <summary>
        /// Tries to parse the given string to a MUCAffiliation.
        /// Returns MUCAffiliation.NONE as a default value if it fails.
        /// </summary>
        /// <param name="affiliation">The string that should get parsed to a MUCAffiliation.</param>
        /// <returns>Returns the MUCAffiliation based on the given string. Defaults to: MUCAffiliation.NONE</returns>
        public static MUCAffiliation parseMUCAffiliation(string affiliation)
        {
            MUCAffiliation a = MUCAffiliation.NONE;

            Enum.TryParse(affiliation.ToUpper(), out a);
            return(a);
        }
Example #2
0
        public BanedUser(XmlNode n)
        {
            jid         = n.Attributes["jid"]?.Value;
            affiliation = Utils.parseMUCAffiliation(n.Attributes["affiliation"]?.Value);
            XmlNode reasonNode = XMLUtils.getChildNode(n, "reason");

            reason = reasonNode?.InnerText;
        }
 public RoomInfoMessage(string from, string to, DataForm roomConfig, MUCAffiliation configType) : base(from, to, SET, getRandomId())
 {
     ROOM_CONFIG = roomConfig;
     ROOM_CONFIG.fields.Add(new Field()
     {
         type  = FieldType.HIDDEN,
         value = Consts.XML_XEP_0045_NAMESPACE_ROOM_CONFIG,
         var   = "FORM_TYPE"
     });
     CONFIG_LEVEL = configType;
 }
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--
        /// <summary>
        /// Basic Constructor
        /// </summary>
        /// <history>
        /// 07/07/2018 Created [Fabian Sauter]
        /// </history>
        public RoomInfoMessage(XmlNode node) : base(node)
        {
            XmlNode qNode = XMLUtils.getChildNode(node, "query", Consts.XML_XMLNS, Consts.MUC_ROOM_INFO_NAMESPACE_REGEX);

            if (qNode != null)
            {
                CONFIG_LEVEL = getRoomConfigLevel(qNode.Attributes[Consts.XML_XMLNS].Value);
                XmlNode x = XMLUtils.getChildNode(qNode, "x", Consts.XML_XMLNS, Consts.XML_XEP_0004_NAMESPACE);
                if (x != null)
                {
                    IS_ROOM_CONFIGURATION_ALLOWED = true;
                    ROOM_CONFIG = new DataForm(x);
                    return;
                }
                else
                {
                    IS_ROOM_CONFIGURATION_ALLOWED = false;
                    ROOM_CONFIG = null;
                }
            }
        }
Example #5
0
        //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
        #region --Constructors--
        /// <summary>
        /// Basic Constructor
        /// </summary>
        /// <history>
        /// 07/01/2018 Created [Fabian Sauter]
        /// </history>
        public MUCMemberPresenceMessage(XmlNode node) : base(node)
        {
            this.FROM_NICKNAME = Utils.getJidResourcePart(FROM);
            this.STATUS_CODES  = new List <MUCPresenceStatusCode>();
            XmlNode xNode = XMLUtils.getChildNode(node, "x", Consts.XML_XMLNS, "http://jabber.org/protocol/muc#user");

            if (xNode != null)
            {
                foreach (XmlNode n in xNode.ChildNodes)
                {
                    switch (n.Name)
                    {
                    case "item":
                        this.AFFILIATION = Utils.parseMUCAffiliation(n.Attributes["affiliation"]?.Value);
                        this.ROLE        = Utils.parseMUCRole(n.Attributes["role"]?.Value);
                        this.JID         = n.Attributes["jid"]?.Value;
                        this.NICKNAME    = n.Attributes["nick"]?.Value;
                        break;

                    case "status":
                        string s = n.Attributes["code"]?.Value;
                        if (s != null)
                        {
                            this.STATUS_CODES.Add(parseStatusCode(s));
                        }
                        break;
                    }
                }
            }

            XmlNode eNode = XMLUtils.getChildNode(node, "error");

            if (eNode != null)
            {
                this.ERROR_TYPE    = eNode.Attributes["type"]?.Value;
                this.ERROR_MESSAGE = eNode.InnerText;
            }
        }
Example #6
0
 /// <summary>
 /// Converts the given MUCAffiliation to the equivalent string representation.
 /// e.g. MUCAffiliation.NONE => 'none'
 /// </summary>
 public static string mucAffiliationToString(MUCAffiliation affiliation)
 {
     return(affiliation.ToString().ToLower());
 }
Example #7
0
        /// <summary>
        /// Sends a RoomInfoMessage and saves the given room configuration.
        /// </summary>
        /// <param name="roomJid">The bare JID if the room you would like to save the room configuration for. e.g. '*****@*****.**'</param>
        /// <param name="roomConfiguration">The new room configuration.</param>
        /// <param name="configLevel">The requested configuration level (the senders affiliation).</param>
        /// <param name="onMessage">The method that should get executed once the helper receives a new valid message.</param>
        /// <param name="onTimeout">The method that should get executed once the helper timeout gets triggered.</param>
        /// <returns>Returns a MessageResponseHelper listening for RoomInfoMessage answers.</returns>
        public MessageResponseHelper <IQMessage> saveRoomConfiguration(string roomJid, DataForm roomConfiguration, MUCAffiliation configLevel, MessageResponseHelper <IQMessage> .OnMessageHandler onMessage, MessageResponseHelper <IQMessage> .OnTimeoutHandler onTimeout)
        {
            MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CONNECTION, onMessage, onTimeout);
            RoomInfoMessage msg = new RoomInfoMessage(CONNECTION.account.getFullJid(), roomJid, roomConfiguration, configLevel);

            helper.start(msg);
            return(helper);
        }
Example #8
0
        /// <summary>
        /// Sends a RequestRoomConfigurationMessage and requests the current room configuration.
        /// </summary>
        /// <param name="roomJid">The bare JID if the room you would like to request the room configuration for. e.g. '*****@*****.**'</param>
        /// <param name="configLevel">The requested configuration level (the senders affiliation).</param>
        /// <param name="onMessage">The method that should get executed once the helper receives a new valid message.</param>
        /// <param name="onTimeout">The method that should get executed once the helper timeout gets triggered.</param>
        /// <returns>Returns a MessageResponseHelper listening for RequestRoomConfigurationMessage answers.</returns>
        public MessageResponseHelper <IQMessage> requestRoomConfiguration(string roomJid, MUCAffiliation configLevel, MessageResponseHelper <IQMessage> .OnMessageHandler onMessage, MessageResponseHelper <IQMessage> .OnTimeoutHandler onTimeout)
        {
            MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CONNECTION, onMessage, onTimeout);
            RequestRoomConfigurationMessage   msg    = new RequestRoomConfigurationMessage(roomJid, configLevel);

            helper.start(msg);
            return(helper);
        }
 //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
 #region --Constructors--
 /// <summary>
 /// Basic Constructor
 /// </summary>
 /// <history>
 /// 07/02/2018 Created [Fabian Sauter]
 /// </history>
 public RequestRoomConfigurationMessage(string to, MUCAffiliation senderAffiliation) : base(null, to, GET, getRandomId())
 {
     SENDER_AFFILIATION = senderAffiliation;
 }
Example #10
0
 //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
 #region --Constructors--
 /// <summary>
 /// Basic Constructor
 /// </summary>
 /// <history>
 /// 12/03/2018 Created [Fabian Sauter]
 /// </history>
 public BanedUser(string jid, string reason, MUCAffiliation affiliation)
 {
     this.jid         = jid;
     this.reason      = reason;
     this.affiliation = affiliation;
 }
Example #11
0
        /// <summary>
        /// Sends a RoomInfoMessage and saves the given room configuration.
        /// </summary>
        /// <param name="roomJid">The bare JID if the room you would like to save the room configuration for. e.g. '*****@*****.**'</param>
        /// <param name="roomConfiguration">The new room configuration.</param>
        /// <param name="configLevel">The requested configuration level (the senders affiliation).</param>
        /// <param name="onMessage">The method that should get executed once the helper receives a new valid message.</param>
        /// <param name="onTimeout">The method that should get executed once the helper timeout gets triggered.</param>
        /// <returns>Returns a MessageResponseHelper listening for RoomInfoMessage answers.</returns>
        public MessageResponseHelper <IQMessage> saveRoomConfiguration(string roomJid, DataForm roomConfiguration, MUCAffiliation configLevel, Func <IQMessage, bool> onMessage, Action onTimeout)
        {
            MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CLIENT, onMessage, onTimeout);
            RoomInfoMessage msg = new RoomInfoMessage(CLIENT.getXMPPAccount().getIdDomainAndResource(), roomJid, roomConfiguration, configLevel);

            helper.start(msg);
            return(helper);
        }
Example #12
0
        /// <summary>
        /// Sends a RequestRoomConfigurationMessage and requests the current room configuration.
        /// </summary>
        /// <param name="roomJid">The bare JID if the room you would like to request the room configuration for. e.g. '*****@*****.**'</param>
        /// <param name="configLevel">The requested configuration level (the senders affiliation).</param>
        /// <param name="onMessage">The method that should get executed once the helper receives a new valid message.</param>
        /// <param name="onTimeout">The method that should get executed once the helper timeout gets triggered.</param>
        /// <returns>Returns a MessageResponseHelper listening for RequestRoomConfigurationMessage answers.</returns>
        public MessageResponseHelper <IQMessage> requestRoomConfiguration(string roomJid, MUCAffiliation configLevel, Func <IQMessage, bool> onMessage, Action onTimeout)
        {
            MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CLIENT, onMessage, onTimeout);
            RequestRoomConfigurationMessage   msg    = new RequestRoomConfigurationMessage(roomJid, configLevel);

            helper.start(msg);
            return(helper);
        }