Пример #1
0
        private async Task updateDevicesIfNeededAsync(OmemoXmlDevices devicesRemote)
        {
            if (devicesRemote is null)
            {
                devicesRemote = new OmemoXmlDevices();
            }

            bool updateDeviceList = false;

            /**
             * Device id hasn't been set or we have an invalid one. Pick a random, unique one.
             * Versions of UWPX < v.0.41.0.0 had an invalid one.
             * OMEMO allows only device IDs between 1 and (2^31 - 1)
             * https://xmpp.org/extensions/xep-0384.html#usecases-setup
             **/
            if (CONNECTION.account.omemoDeviceId == 0 || CONNECTION.account.omemoDeviceId > 0x7FFFFFFF)
            {
                tmpDeviceId = CryptoUtils.GenerateUniqueDeviceId(devicesRemote.DEVICES.Select(d => d.ID).ToList());
                devicesRemote.DEVICES.Add(new OmemoXmlDevice(tmpDeviceId, CONNECTION.account.omemoDeviceLabel));
                updateDeviceList = true;
            }
            else
            {
                tmpDeviceId = CONNECTION.account.omemoDeviceId;
                OmemoXmlDevice remoteDevice = devicesRemote.DEVICES.Where(d => d.ID == tmpDeviceId).FirstOrDefault();
                // Device does not exist:
                if (remoteDevice is null)
                {
                    devicesRemote.DEVICES.Add(new OmemoXmlDevice(tmpDeviceId, CONNECTION.account.omemoDeviceLabel));
                    updateDeviceList = true;
                }
                // Device label changed:
                else if (!string.Equals(remoteDevice.label, CONNECTION.account.omemoDeviceLabel))
                {
                    remoteDevice.label = CONNECTION.account.omemoDeviceLabel;
                    updateDeviceList   = true;
                }
            }

            if (updateDeviceList)
            {
                await updateDeviceListAsync(devicesRemote);
            }
            else if (!CONNECTION.account.omemoBundleInfoAnnounced || updateDeviceList)
            {
                await announceBundleInfoAsync();
            }
            else
            {
                setState(OmemoHelperState.ENABLED);
            }
            DEVICES = devicesRemote;
            // Store the new list in the DB:
            OMEMO_STORAGE.StoreDevices(DEVICES.toOmemoProtocolAddress(CONNECTION.account.getBareJid()), CONNECTION.account.getBareJid());
        }
Пример #2
0
        public async Task refreshDevicesAsync()
        {
            MessageResponseHelperResult <IQMessage> result = await CONNECTION.OMEMO_COMMAND_HELPER.requestDeviceListAsync(CONNECTION.account.getBareJid());

            if (result.STATE == MessageResponseHelperResultState.SUCCESS)
            {
                if (result.RESULT is OmemoDeviceListResultMessage devMsg)
                {
                    DEVICES = devMsg.DEVICES;
                    // Store the new list in the DB:
                    OMEMO_STORAGE.StoreDevices(DEVICES.toOmemoProtocolAddress(CONNECTION.account.getBareJid()), CONNECTION.account.getBareJid());
                }
                else if (result.RESULT is IQErrorMessage errMsg)
                {
                    Logger.Error("[OMEMO HELPER](" + CONNECTION.account.getBareJid() + ") Failed to request OMEMO device list form: " + CONNECTION.account.user.domainPart + "\n" + errMsg.ERROR_OBJ.ToString());
                }
            }
            else
            {
                Logger.Error("[OMEMO HELPER](" + CONNECTION.account.getBareJid() + ") Failed to request OMEMO device list form: " + CONNECTION.account.user.domainPart + " with: " + result.STATE);
            }
        }