public OmemoDeviceListSubscriptionTable(string accountId, string name, OmemoDeviceListSubscriptionState state, DateTime lastUpdateReceived) { id = generateId(accountId, name); this.accountId = accountId; this.name = name; this.state = state; this.lastUpdateReceived = lastUpdateReceived; }
public OmemoDeviceListSubscriptionTable(string chatJid, string accountId, OmemoDeviceListSubscriptionState state, DateTime lastUpdateReceived) { this.id = generateId(chatJid, accountId); this.chatJid = chatJid; this.accountId = accountId; this.state = state; this.lastUpdateReceived = lastUpdateReceived; }
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- public void start(OmemoDeviceListSubscriptionState subscriptionState) { switch (subscriptionState) { case OmemoDeviceListSubscriptionState.SUBSCRIBED: // Because we are subscribed, the device list should be up to date: List <uint> devices = OmemoDeviceDBManager.INSTANCE.getDeviceIds(CHAT_JID, BARE_ACCOUNT_JID); createSessionsForDevices(devices); break; default: requestDeviceList(); break; } }
//--------------------------------------------------------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); }
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- public async Task <OmemoSessionBuildResult> buildSessionAsync(OmemoDeviceListSubscriptionState subscriptionState) { sessionBuildResult = null; List <Tuple <OmemoProtocolAddress, string> > devicesOwn = getOwnOmemoDevices(); List <Tuple <OmemoProtocolAddress, string> > devicesRemote = null; if (subscriptionState == OmemoDeviceListSubscriptionState.SUBSCRIBED) { // Because we are subscribed, the device list should be up to date: devicesRemote = OMEMO_HELPER.OMEMO_STORAGE.LoadDevices(DST_BARE_JID); } if (devicesRemote is null || devicesRemote.Count <= 0) { // Request devices and try to subscribe to list: devicesRemote = await requestDeviceListAsync(DST_BARE_JID); if (devicesRemote is null) { return(sessionBuildResult); } // Does not have to be successful: await subscribeToDeviceListAsync(DST_BARE_JID); } // Build sessions for all devices: OmemoSessions sessions = new OmemoSessions(new OmemoDeviceGroup(SRC_BARE_JID), new OmemoDeviceGroup(DST_BARE_JID)); await buildSessionForDevicesAsync(sessions.DST_DEVICE_GROUP, devicesRemote); if (sessions.DST_DEVICE_GROUP.SESSIONS.Count > 0) { await buildSessionForDevicesAsync(sessions.SRC_DEVICE_GROUP, devicesOwn); sessionBuildResult = new OmemoSessionBuildResult(sessions); } else { Logger.Error("Failed to establish OMEMO session with: " + SRC_BARE_JID + ". Target does not support OMEMO - not enough OMEMO sessions!"); sessionBuildResult = new OmemoSessionBuildResult(OmemoSessionBuildError.TARGET_DOES_NOT_SUPPORT_OMEMO); } return(sessionBuildResult); }