コード例 #1
0
        public async Task sendOmemoMessageAsync(OmemoMessageMessage msg, string chatJid, string accountJid)
        {
            // Check if already trying to build a new session:
            if (MESSAGE_CACHE.ContainsKey(chatJid))
            {
                MESSAGE_CACHE[chatJid].Item1.Add(msg);
            }
            else
            {
                // If not start a new session build helper:
                OmemoSessionBuildHelper sessionHelper = new OmemoSessionBuildHelper(chatJid, accountJid, CONNECTION.account.getFullJid(), CONNECTION, this);
                MESSAGE_CACHE[chatJid] = new Tuple <List <OmemoMessageMessage>, OmemoSessionBuildHelper>(new List <OmemoMessageMessage>(), sessionHelper);
                MESSAGE_CACHE[chatJid].Item1.Add(msg);
                Tuple <OmemoDeviceListSubscriptionState, DateTime> subscription = OMEMO_STORE.LoadDeviceListSubscription(chatJid);

                OmemoSessionBuildResult result = await sessionHelper.buildSessionAsync(subscription.Item1);

                if (result.SUCCESS)
                {
                    OMEMO_SESSIONS[result.SESSION.CHAT_JID] = result.SESSION;
                    await sendAllOutstandingMessagesAsync(result.SESSION);
                }
                else
                {
                    OmemoSessionBuildErrorEventArgs args = new OmemoSessionBuildErrorEventArgs(chatJid, result.ERROR, MESSAGE_CACHE[chatJid]?.Item1 ?? new List <OmemoMessageMessage>());
                    MESSAGE_CACHE.Remove(chatJid);
                    CONNECTION.OnOmemoSessionBuildError(args);
                    Logger.Error("Failed to build OMEMO session for: " + chatJid + " with: " + result.ERROR);
                }
            }
        }
コード例 #2
0
ファイル: OmemoHelper.cs プロジェクト: Echolon/UWPX-Client
        public async Task sendOmemoMessageAsync(OmemoEncryptedMessage msg, string srcBareJid, string dstBareJid, bool trustedSrcKeysOnly, bool trustedDstKeysOnly)
        {
            // Check if already trying to build a new session:
            if (MESSAGE_CACHE.ContainsKey(dstBareJid))
            {
                MESSAGE_CACHE[dstBareJid].Item1.Add(msg);
            }
            else
            {
                // If not start a new session build helper:
                OmemoSessionBuildHelper sessionHelper = new OmemoSessionBuildHelper(srcBareJid, dstBareJid, CONNECTION, this, trustedSrcKeysOnly, trustedDstKeysOnly);
                MESSAGE_CACHE[dstBareJid] = new Tuple <List <OmemoEncryptedMessage>, OmemoSessionBuildHelper>(new List <OmemoEncryptedMessage>(), sessionHelper);
                MESSAGE_CACHE[dstBareJid].Item1.Add(msg);
                Tuple <OmemoDeviceListSubscriptionState, DateTime> subscription = OMEMO_STORAGE.LoadDeviceListSubscription(dstBareJid);

                OmemoSessionBuildResult result = await sessionHelper.buildSessionAsync(subscription.Item1);

                if (result.SUCCESS)
                {
                    OMEMO_SESSIONS[dstBareJid] = result.SESSIONS;
                    await sendAllOutstandingMessagesAsync(result.SESSIONS);
                }
                else
                {
                    OmemoSessionBuildErrorEventArgs args = new OmemoSessionBuildErrorEventArgs(dstBareJid, result.ERROR, MESSAGE_CACHE[dstBareJid]?.Item1 ?? new List <OmemoEncryptedMessage>());
                    MESSAGE_CACHE.Remove(dstBareJid);
                    CONNECTION.OnOmemoSessionBuildError(args);
                    Logger.Error("Failed to build OMEMO session for: " + dstBareJid + " with: " + result.ERROR);
                }
            }
        }