/// <summary> /// If the OMEMO device list got changed and does not contain the local device id update it and add it again. /// </summary> /// <param name="msg">The received OmemoDeviceListEventMessage.</param> private async Task onOmemoDeviceListEventMessageAsync(OmemoDeviceListEventMessage msg) { string senderBareJid = Utils.getBareJidFromFullJid(msg.getFrom()); if (string.Equals(senderBareJid, CONNECTION.account.getBareJid())) { if (CONNECTION.account.omemoDeviceId != 0) { if (!msg.DEVICES.DEVICES.Any(d => d.ID == CONNECTION.account.omemoDeviceId)) { msg.DEVICES.DEVICES.Add(new OmemoXmlDevice(CONNECTION.account.omemoDeviceId, CONNECTION.account.omemoDeviceLabel)); OmemoSetDeviceListMessage setMsg = new OmemoSetDeviceListMessage(CONNECTION.account.getFullJid(), msg.DEVICES); await CONNECTION.SendAsync(setMsg, false); } DEVICES = msg.DEVICES; } else { return; } } OMEMO_STORAGE.StoreDevices(msg.DEVICES.toOmemoProtocolAddress(senderBareJid), senderBareJid); OMEMO_STORAGE.StoreDeviceListSubscription(senderBareJid, new Tuple <OmemoDeviceListSubscriptionState, DateTime>(OmemoDeviceListSubscriptionState.SUBSCRIBED, DateTime.Now)); }
/// <summary> /// Sends an OmemoSetDeviceListMessage to update your OMEMO device list with the given devices. /// </summary> /// <param name="devices">The new OMEMO device list.</param> /// <returns>The OmemoSetDeviceListMessage result.</returns> public Task <MessageResponseHelperResult <IQMessage> > setDeviceListAsync(OmemoXmlDevices devices) { Predicate <IQMessage> predicate = (x) => { return(true); }; AsyncMessageResponseHelper <IQMessage> helper = new AsyncMessageResponseHelper <IQMessage>(CONNECTION, predicate); OmemoSetDeviceListMessage msg = new OmemoSetDeviceListMessage(CONNECTION.account.getFullJid(), devices); return(helper.startAsync(msg)); }
/// <summary> /// If the OMEMO device list got changed and does not contain the local device id update it and add it again. /// </summary> /// <param name="msg">The received OmemoDeviceListEventMessage.</param> private async Task onOmemoDeviceListEventMessageAsync(OmemoDeviceListEventMessage msg) { if (!msg.DEVICES.DEVICES.Contains(CONNECTION.account.omemoDeviceId)) { msg.DEVICES.DEVICES.Add(CONNECTION.account.omemoDeviceId); OmemoSetDeviceListMessage setMsg = new OmemoSetDeviceListMessage(CONNECTION.account.getIdDomainAndResource(), msg.DEVICES); await CONNECTION.sendAsync(setMsg, false, false); } }
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); }
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; }
/// <summary> /// If the OMEMO device list got changed and does not contain the local device id update it and add it again. /// </summary> /// <param name="msg">The received OmemoDeviceListEventMessage.</param> private async Task onOmemoDeviceListEventMessageAsync(OmemoDeviceListEventMessage msg) { string senderBareJid = Utils.getBareJidFromFullJid(msg.getFrom()); if (string.Equals(senderBareJid, CONNECTION.account.getBareJid())) { if (!msg.DEVICES.IDS.Contains(CONNECTION.account.omemoDeviceId)) { msg.DEVICES.IDS.Add(CONNECTION.account.omemoDeviceId); OmemoSetDeviceListMessage setMsg = new OmemoSetDeviceListMessage(CONNECTION.account.getFullJid(), msg.DEVICES); await CONNECTION.SendAsync(setMsg, false); } DEVICES = msg.DEVICES; } OMEMO_STORE.StoreDevices(msg.DEVICES.toSignalProtocolAddressList(senderBareJid)); OMEMO_STORE.StoreDeviceListSubscription(senderBareJid, new Tuple <OmemoDeviceListSubscriptionState, DateTime>(OmemoDeviceListSubscriptionState.SUBSCRIBED, DateTime.Now)); }