예제 #1
0
 //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
 #region --Constructors--
 /// <summary>
 /// Basic Constructor
 /// </summary>
 /// <history>
 /// 10/08/2018 Created [Fabian Sauter]
 /// </history>
 internal OmemoSessionBuildHelper(string chatJid, string bareAccountJid, string fullAccountJid, Action <OmemoSessionBuildHelper, OmemoSessionBuildResult> onSessionResult, XMPPConnection2 connection, OmemoHelper omemoHelper)
 {
     this.CONNECTION              = connection;
     this.ON_SESSION_RESULT       = onSessionResult;
     this.CHAT_JID                = chatJid;
     this.BARE_ACCOUNT_JID        = bareAccountJid;
     this.FULL_ACCOUNT_JID        = fullAccountJid;
     this.OMEMO_HELPER            = omemoHelper;
     this.STATE                   = OmemoSessionBuildHelperState.NOT_STARTED;
     this.requestDeviceListHelper = null;
     this.requestBundleInfoHelper = null;
     this.SESSION                 = new OmemoSession(chatJid);
     this.curAddress              = null;
 }
예제 #2
0
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--
        public async Task <OmemoSessionBuildResult> buildSessionAsync(OmemoDeviceListSubscriptionState subscriptionState)
        {
            sessionBuildResult = null;
            IList <SignalProtocolAddress> devicesOwn    = getOwnOmemoDevices();
            IList <SignalProtocolAddress> devicesRemote = null;

            if (subscriptionState == OmemoDeviceListSubscriptionState.SUBSCRIBED)
            {
                // Because we are subscribed, the device list should be up to date:
                devicesRemote = OMEMO_HELPER.OMEMO_STORE.LoadDevices(CHAT_JID);
            }

            if (devicesRemote is null || devicesRemote.Count <= 0)
            {
                // Request devices and try to subscribe to list:
                devicesRemote = await requestDeviceListAsync();

                if (devicesRemote is null)
                {
                    return(sessionBuildResult);
                }

                // Does not have to be successful:
                await subscribeToDeviceListAsync();
            }

            // Build sessions for all devices:
            OmemoSession session = new OmemoSession(CHAT_JID);

            await buildSessionForDevicesAsync(session.DEVICE_SESSIONS_REMOTE, devicesRemote);

            if (session.DEVICE_SESSIONS_REMOTE.Count > 0)
            {
                await buildSessionForDevicesAsync(session.DEVICE_SESSIONS_OWN, devicesOwn);

                sessionBuildResult = new OmemoSessionBuildResult(session);
            }
            else
            {
                Logger.Error("Failed to establish OMEMO session with: " + CHAT_JID + ". Target does not support OMEMO - not enough OMEMO sessions!");
                sessionBuildResult = new OmemoSessionBuildResult(OmemoSessionBuildError.TARGET_DOES_NOT_SUPPORT_OMEMO);
            }

            return(sessionBuildResult);
        }