コード例 #1
0
        /// <summary>
        /// Sends a OmemoRequestDeviceListMessage to requests the OMEMO device list of the given target.
        /// </summary>
        /// <param name="to">The bare JID of the target you want to request the OMEMO device list from. e.g. 'conference.jabber.org'</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 OmemoRequestDeviceListMessage answers.</returns>
        public MessageResponseHelper <IQMessage> requestDeviceList(string to, Func <IQMessage, bool> onMessage, Action onTimeout)
        {
            MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CLIENT, onMessage, onTimeout);
            OmemoRequestDeviceListMessage     msg    = new OmemoRequestDeviceListMessage(CLIENT.getXMPPAccount().getIdDomainAndResource(), to);

            helper.start(msg);
            return(helper);
        }
コード例 #2
0
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--


        #endregion

        #region --Misc Methods (Private)--
        private void requestDisoInfo()
        {
            CONNECTION.account.CONNECTION_INFO.msgCarbonsState = MessageCarbonsState.DISABLED;
            if (discoMessageResponseHelper != null)
            {
                discoMessageResponseHelper.Dispose();
            }
            discoMessageResponseHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onDiscoMessage, onDiscoTimeout);
            discoMessageResponseHelper.start(new DiscoRequestMessage(CONNECTION.account.getFullJid(), CONNECTION.account.user.domainPart, DiscoType.INFO));
        }
コード例 #3
0
        /// <summary>
        /// Sends a MUCChangeNicknameMessage for changing your own MUC nickname.
        /// </summary>
        /// <param name="roomJid">The bare JID if the room you would like to change your nickname for. e.g. '*****@*****.**'</param>
        /// <param name="newNickname">The new nickname for the given room.</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 MUCChangeNicknameMessage answers.</returns>
        public MessageResponseHelper <PresenceMessage> changeNickname(string roomJid, string newNickname, MessageResponseHelper <PresenceMessage> .OnMessageHandler onMessage, MessageResponseHelper <PresenceMessage> .OnTimeoutHandler onTimeout)
        {
            MessageResponseHelper <PresenceMessage> helper = new MessageResponseHelper <PresenceMessage>(CONNECTION, onMessage, onTimeout)
            {
                matchId = false
            };
            MUCChangeNicknameMessage msg = new MUCChangeNicknameMessage(CONNECTION.account.getFullJid(), roomJid, newNickname);

            helper.start(msg);
            return(helper);
        }
コード例 #4
0
        /// <summary>
        /// Sends a MUCChangeNicknameMessage for changing your own MUC nickname.
        /// </summary>
        /// <param name="roomJid">The bare JID if the room you would like to change your nickname for. e.g. '*****@*****.**'</param>
        /// <param name="newNickname">The new nickname for the given room.</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 MUCChangeNicknameMessage answers.</returns>
        public MessageResponseHelper <PresenceMessage> changeNickname(string roomJid, string newNickname, Func <PresenceMessage, bool> onMessage, Action onTimeout)
        {
            MessageResponseHelper <PresenceMessage> helper = new MessageResponseHelper <PresenceMessage>(CLIENT, onMessage, onTimeout)
            {
                matchId = false
            };
            MUCChangeNicknameMessage msg = new MUCChangeNicknameMessage(CLIENT.getXMPPAccount().getIdDomainAndResource(), roomJid, newNickname);

            helper.start(msg);
            return(helper);
        }
コード例 #5
0
        private void announceBundleInfo()
        {
            setState(OmemoHelperState.ANNOUNCING_BUNDLE_INFO);
            Logger.Info("[OMEMO HELPER](" + CONNECTION.account.getIdAndDomain() + ") Announcing bundle information for: " + CONNECTION.account.omemoDeviceId);
            if (announceBundleInfoHelper != null)
            {
                announceBundleInfoHelper.Dispose();
            }
            announceBundleInfoHelper = new MessageResponseHelper <IQMessage>(CONNECTION, announceBundleInfoMsg, onTimeout);
            OmemoSetBundleInformationMessage msg = new OmemoSetBundleInformationMessage(CONNECTION.account.getIdDomainAndResource(), CONNECTION.account.getOmemoBundleInformation(), CONNECTION.account.omemoDeviceId);

            announceBundleInfoHelper.start(msg);
        }
コード例 #6
0
        private void requestDeviceList()
        {
            setState(OmemoHelperState.REQUESTING_DEVICE_LIST);
            Logger.Info("[OMEMO HELPER](" + CONNECTION.account.getIdAndDomain() + ") Requesting device list.");
            if (requestDeviceListHelper != null)
            {
                requestDeviceListHelper.Dispose();
            }
            requestDeviceListHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onRequestDeviceListMsg, onTimeout);
            OmemoRequestDeviceListMessage msg = new OmemoRequestDeviceListMessage(CONNECTION.account.getIdDomainAndResource(), null);

            requestDeviceListHelper.start(msg);
        }
コード例 #7
0
        private void deleteDeviceListNode()
        {
            if (resetDeviceListStatelessHelper != null)
            {
                resetDeviceListStatelessHelper.Dispose();
                resetDeviceListStatelessHelper = null;
            }

            resetDeviceListStatelessHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onDeleteDeviceListNodeMessage, onDeleteDeviceListNodeTimeout);
            PubSubDeleteNodeMessage msg = new PubSubDeleteNodeMessage(CONNECTION.account.getIdDomainAndResource(), null, Consts.XML_XEP_0384_DEVICE_LIST_NODE);

            resetDeviceListStatelessHelper.start(msg);
        }
コード例 #8
0
        private bool onDiscoMessage(MessageResponseHelper <IQMessage> helper, IQMessage msg)
        {
            if (msg is DiscoResponseMessage disco)
            {
                switch (disco.DISCO_TYPE)
                {
                case DiscoType.ITEMS:
                    break;

                case DiscoType.INFO:
                    bool foundCarbons = false;
                    foreach (DiscoFeature f in disco.FEATURES)
                    {
                        if (string.Equals(f.VAR, Consts.XML_XEP_0280_NAMESPACE))
                        {
                            foundCarbons = true;
                            if (CONNECTION.account.connectionConfiguration.disableMessageCarbons)
                            {
                                CONNECTION.account.CONNECTION_INFO.msgCarbonsState = MessageCarbonsState.DISABLED;
                            }
                            else if (CONNECTION.account.CONNECTION_INFO.msgCarbonsState != MessageCarbonsState.ENABLED)
                            {
                                Logger.Info("Enabling message carbons for " + CONNECTION.account.getBareJid() + " ...");
                                carbonsMessageResponseHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onCarbonsMessage, onCarbonsTimeout);
                                carbonsMessageResponseHelper.start(new CarbonsEnableMessage(CONNECTION.account.getFullJid()));
                            }
                            break;
                        }
                    }

                    if (!foundCarbons)
                    {
                        Logger.Warn("Unable to enable message carbons for " + CONNECTION.account.getBareJid() + " - not available.");
                        CONNECTION.account.CONNECTION_INFO.msgCarbonsState = MessageCarbonsState.UNAVAILABLE;
                    }
                    break;

                default:
                    break;
                }
                return(true);
            }
            else if (msg is IQErrorMessage errMsg)
            {
                CONNECTION.account.CONNECTION_INFO.msgCarbonsState = MessageCarbonsState.UNAVAILABLE;
                Logger.Error("Failed to request initial server disco for " + CONNECTION.account.getBareJid() + ": " + errMsg.ERROR_OBJ.ToString());
                return(true);
            }
            return(false);
        }
コード例 #9
0
        private void requestDeviceList()
        {
            setState(OmemoSessionBuildHelperState.REQUESTING_DEVICE_LIST);
            if (requestDeviceListHelper != null)
            {
                requestDeviceListHelper?.Dispose();
                requestDeviceListHelper = null;
            }

            requestDeviceListHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onRequestDeviceListMessage, onTimeout);
            OmemoRequestDeviceListMessage msg = new OmemoRequestDeviceListMessage(BARE_ACCOUNT_JID, CHAT_JID);

            requestDeviceListHelper.start(msg);
        }
コード例 #10
0
        private void requestBundleInformation()
        {
            setState(OmemoSessionBuildHelperState.REQUESTING_BUNDLE_INFORMATION);
            if (requestBundleInfoHelper != null)
            {
                requestBundleInfoHelper?.Dispose();
                requestBundleInfoHelper = null;
            }

            requestBundleInfoHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onRequestBundleInformationMessage, onTimeout);
            OmemoRequestBundleInformationMessage msg = new OmemoRequestBundleInformationMessage(FULL_ACCOUNT_JID, curAddress.getName(), curAddress.getDeviceId());

            requestBundleInfoHelper.start(msg);
        }
コード例 #11
0
        private void subscribeToDeviceList()
        {
            setState(OmemoSessionBuildHelperState.SUBSCRIBING_TO_DEVICE_LIST);
            if (subscribeToDeviceListHelper != null)
            {
                subscribeToDeviceListHelper?.Dispose();
                subscribeToDeviceListHelper = null;
            }

            subscribeToDeviceListHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onSubscribeToDeviceListMessage, onTimeout);
            OmemoSubscribeToDeviceListMessage msg = new OmemoSubscribeToDeviceListMessage(FULL_ACCOUNT_JID, BARE_ACCOUNT_JID, CHAT_JID);

            subscribeToDeviceListHelper.start(msg);
        }
コード例 #12
0
        public void requestDeviceListStateless(Action <bool, OmemoDevices> onResult)
        {
            requestDeviceListStatelessOnResult = onResult;

            if (requestDeviceListStatelessHelper != null)
            {
                requestDeviceListStatelessHelper.Dispose();
                requestDeviceListStatelessHelper = null;
            }
            requestDeviceListStatelessHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onRequestDeviceListStatelessMessage, onRequestDeviceListStatelessTimeout);
            OmemoRequestDeviceListMessage msg = new OmemoRequestDeviceListMessage(CONNECTION.account.getIdDomainAndResource(), null);

            requestDeviceListStatelessHelper.start(msg);
        }
コード例 #13
0
        private void setDeviceListToOwnDevice()
        {
            if (resetDeviceListStatelessHelper != null)
            {
                resetDeviceListStatelessHelper.Dispose();
                resetDeviceListStatelessHelper = null;
            }
            OmemoDevices devices = new OmemoDevices();

            devices.DEVICES.Add(CONNECTION.account.omemoDeviceId);
            resetDeviceListStatelessHelper = new MessageResponseHelper <IQMessage>(CONNECTION, onResetDeviceListStatelessMessage, onResetDeviceListStatelessTimeout);
            OmemoSetDeviceListMessage msg = new OmemoSetDeviceListMessage(CONNECTION.account.getIdDomainAndResource(), devices);

            resetDeviceListStatelessHelper.start(msg);
        }
コード例 #14
0
        private void updateDevicesIfNeeded(OmemoDevices devicesRemote)
        {
            if (devicesRemote == null)
            {
                devicesRemote = new OmemoDevices();
            }

            bool updateDeviceList = false;

            // Device id hasn't been set. Pick a random, unique one:
            if (CONNECTION.account.omemoDeviceId == 0)
            {
                tmpDeviceId = CryptoUtils.generateOmemoDeviceIds(devicesRemote.DEVICES);
                devicesRemote.DEVICES.Add(tmpDeviceId);
                updateDeviceList = true;
            }
            else
            {
                if (!devicesRemote.DEVICES.Contains(CONNECTION.account.omemoDeviceId))
                {
                    devicesRemote.DEVICES.Add(CONNECTION.account.omemoDeviceId);
                    updateDeviceList = true;
                }
            }

            if (updateDeviceList)
            {
                setState(OmemoHelperState.UPDATING_DEVICE_LIST);
                Logger.Info("[OMEMO HELPER](" + CONNECTION.account.getIdAndDomain() + ") Updating device list.");
                if (updateDeviceListHelper != null)
                {
                    updateDeviceListHelper.Dispose();
                }
                updateDeviceListHelper = new MessageResponseHelper <IQMessage>(CONNECTION, updateDevicesIfNeededMsg, onTimeout);
                OmemoSetDeviceListMessage msg = new OmemoSetDeviceListMessage(CONNECTION.account.getIdDomainAndResource(), devicesRemote);
                updateDeviceListHelper.start(msg);
            }
            else if (!CONNECTION.account.omemoBundleInfoAnnounced)
            {
                announceBundleInfo();
            }
            else
            {
                setState(OmemoHelperState.ENABLED);
            }
            DEVICES = devicesRemote;
        }