Esempio n. 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);
                }
            }
        }