From c079202d90c358231d01ed42885b21f5add7b0ed Mon Sep 17 00:00:00 2001 From: siepra Date: Fri, 8 Dec 2023 13:45:29 +0100 Subject: [PATCH 01/20] fix: mark redux store ready after leaving community #1970 --- packages/mobile/ios/Podfile.lock | 2 +- .../store/init/deepLink/deepLink.saga.test.ts | 44 ++++++++++- .../src/store/init/deepLink/deepLink.saga.ts | 78 ++++++++++++++----- .../leaveCommunity/leaveCommunity.saga.ts | 5 ++ .../areObjectsEqual/areObjectsEqual.ts | 3 + 5 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 packages/mobile/src/utils/functions/areObjectsEqual/areObjectsEqual.ts diff --git a/packages/mobile/ios/Podfile.lock b/packages/mobile/ios/Podfile.lock index 201e5c9a3b..6d0a4dac61 100644 --- a/packages/mobile/ios/Podfile.lock +++ b/packages/mobile/ios/Podfile.lock @@ -615,4 +615,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 986ea3b4bace0fe04a792347f3dc6f060797e84d -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.3 diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts index 2fa8e09743..a2f3a5764f 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -3,7 +3,7 @@ import { combineReducers } from '@reduxjs/toolkit' import { reducers } from '../../root.reducer' import { Store } from '../../store.types' import { prepareStore } from '../../../tests/utils/prepareStore' -import { communities, connection, identity } from '@quiet/state-manager' +import { communities, connection, getInvitationCodes, identity } from '@quiet/state-manager' import { initActions } from '../init.slice' import { navigationActions } from '../../navigation/navigation.slice' import { ScreenNames } from '../../../const/ScreenNames.enum' @@ -129,6 +129,7 @@ describe('deepLinkSaga', () => { store.dispatch(communities.actions.addNewCommunity(community)) store.dispatch(communities.actions.setCurrentCommunity(community.id)) + const reducer = combineReducers(reducers) await expectSaga(deepLinkSaga, initActions.deepLink(validCode)) .withReducer(reducer) @@ -155,6 +156,47 @@ describe('deepLinkSaga', () => { .run() }) + test('doesn\'t display error if user is connecting with the same community', async () => { + store.dispatch( + initActions.setWebsocketConnected({ + dataPort: 5001, + socketIOSecret: 'secret', + }) + ) + + store.dispatch(communities.actions.addNewCommunity(community)) + + store.dispatch(communities.actions.setCurrentCommunity(community.id)) + + const invitationCodes = getInvitationCodes(validCode) + store.dispatch(communities.actions.setInvitationCodes(invitationCodes.pairs)) + + const reducer = combineReducers(reducers) + await expectSaga(deepLinkSaga, initActions.deepLink(validCode)) + .withReducer(reducer) + .withState(store.getState()) + .not.put.like({ + action: { + type: navigationActions.replaceScreen.type, + payload: { + screen: ScreenNames.ErrorScreen, + params: { + title: 'You already belong to a community', + message: "We're sorry but for now you can only be a member of a single community at a time", + }, + }, + }, + }) + .put( + communities.actions.createNetwork({ + ownership: CommunityOwnership.User, + peers: validData.pairs, + psk: validData.psk, + }) + ) + .run() + }) + test('displays error if invitation code is invalid', async () => { const invalidData: InvitationData = { pairs: [ diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index 5228b617b9..55369f5c2f 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -8,6 +8,7 @@ import { initActions } from '../init.slice' import { appImages } from '../../../assets' import { replaceScreen } from '../../../RootNavigation' import { CommunityOwnership, CreateNetworkPayload, InvitationData } from '@quiet/types' +import { areObjectsEqual } from '../../../utils/functions/areObjectsEqual/areObjectsEqual' export function* deepLinkSaga(action: PayloadAction['payload']>): Generator { const code = action.payload @@ -24,41 +25,80 @@ export function* deepLinkSaga(action: PayloadAction replaceScreen(ScreenNames.ChannelListScreen), + onPress: () => replaceScreen(ScreenNames.JoinCommunityScreen), icon: appImages.quiet_icon_round, - title: 'You already belong to a community', - message: "We're sorry but for now you can only be a member of a single community at a time", + title: 'Invalid invitation link', + message: 'Please check your invitation link and try again', }, }) ) return } - let data: InvitationData - try { - data = getInvitationCodes(code) - } catch (e) { - console.warn(e.message) + const community = yield* select(communities.selectors.currentCommunity) + + const storedInvitationCodes = yield* select(communities.selectors.invitationCodes) + const currentInvitationCodes = data.pairs + + console.log('Stored invitation codes', storedInvitationCodes) + console.log('Current invitation codes', currentInvitationCodes) + + let isInvitationDataValid: boolean = false + + if (storedInvitationCodes.length === 0) { + isInvitationDataValid = true + } else { + isInvitationDataValid = storedInvitationCodes.some(storedCode => + currentInvitationCodes.some(currentCode => areObjectsEqual(storedCode, currentCode)) + ); + } + + console.log('Is invitation data valid', isInvitationDataValid) + + const isAlreadyConnected = Boolean(community?.name) + + const alreadyBelongsWithAnotherCommunity = !isInvitationDataValid + const alreadyConnectedWithCurrentCommunity = isInvitationDataValid && isAlreadyConnected + const connectingWithCurrentCommunity = isInvitationDataValid && !isAlreadyConnected + + if (alreadyBelongsWithAnotherCommunity) { + console.log('INIT_NAVIGATION: ABORTING: Already belongs with another community.') + } + + if (alreadyConnectedWithCurrentCommunity) { + console.log('INIT_NAVIGATION: ABORTING: Already connected with the current community.') + } + + if (connectingWithCurrentCommunity) { + console.log('INIT_NAVIGATION: Proceeding with connection to the community.') + } + + // Link opened mid registration + // TODO: Check if csr is already saved to db (redux store) + + // User already belongs to a community + if (alreadyBelongsWithAnotherCommunity || alreadyConnectedWithCurrentCommunity) { + console.log('INIT_NAVIGATION: Displaying error (user already belongs to a community).') + + const destination = (alreadyBelongsWithAnotherCommunity || alreadyConnectedWithCurrentCommunity) ? ScreenNames.ChannelListScreen : ScreenNames.JoinCommunityScreen + yield* put( navigationActions.replaceScreen({ screen: ScreenNames.ErrorScreen, params: { - onPress: () => replaceScreen(ScreenNames.JoinCommunityScreen), + onPress: () => replaceScreen(destination), icon: appImages.quiet_icon_round, - title: 'Invalid invitation link', - message: 'Please check your invitation link and try again', + title: 'You already belong to a community', + message: "We're sorry but for now you can only be a member of a single community at a time", }, }) ) diff --git a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts index ca5c669fc3..41e8bf4349 100644 --- a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts +++ b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts @@ -8,6 +8,8 @@ import { navigationActions } from '../../navigation/navigation.slice' import { ScreenNames } from '../../../../src/const/ScreenNames.enum' export function* leaveCommunitySaga(): Generator { + console.log('Leaving community') + // Restart backend yield* put(app.actions.closeServices()) @@ -31,5 +33,8 @@ export function* clearReduxStore(): Generator { // Resume persistor yield* call(persistor.persist) + // Restarting persistor doesn't mark store as ready automatically + yield* put(initActions.setStoreReady()) + yield* put(navigationActions.replaceScreen({ screen: ScreenNames.JoinCommunityScreen })) } diff --git a/packages/mobile/src/utils/functions/areObjectsEqual/areObjectsEqual.ts b/packages/mobile/src/utils/functions/areObjectsEqual/areObjectsEqual.ts new file mode 100644 index 0000000000..445fb29486 --- /dev/null +++ b/packages/mobile/src/utils/functions/areObjectsEqual/areObjectsEqual.ts @@ -0,0 +1,3 @@ +export const areObjectsEqual = (obj1: any, obj2: any): boolean => { + return JSON.stringify(obj1) === JSON.stringify(obj2); +} From a536922079dd384ae6f4e894b2954207ecc40f3d Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 14 Dec 2023 12:25:57 +0100 Subject: [PATCH 02/20] test: fix deepLink tests --- .../store/init/deepLink/deepLink.saga.test.ts | 42 +++++++++++-------- .../src/store/init/deepLink/deepLink.saga.ts | 1 + 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts index c3a0ae1589..f4a3713a44 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -83,6 +83,7 @@ describe('deepLinkSaga', () => { .run() }) + // FIXME: Currently there's no way to actually check whether the redirection destionation is correct test.skip('opens channel list screen if the same url has been used', async () => { store.dispatch( initActions.setWebsocketConnected({ @@ -91,7 +92,11 @@ describe('deepLinkSaga', () => { }) ) - store.dispatch(communities.actions.addNewCommunity(community)) + store.dispatch(communities.actions.setInvitationCodes(validData.pairs)) + store.dispatch(communities.actions.addNewCommunity({ + ...community, + name: 'rockets' + })) store.dispatch( // @ts-expect-error @@ -104,11 +109,6 @@ describe('deepLinkSaga', () => { await expectSaga(deepLinkSaga, initActions.deepLink(validCode)) .withReducer(reducer) .withState(store.getState()) - .put( - navigationActions.replaceScreen({ - screen: ScreenNames.ChannelListScreen, - }) - ) .not.put( communities.actions.createNetwork({ ownership: CommunityOwnership.User, @@ -128,7 +128,14 @@ describe('deepLinkSaga', () => { }) ) - store.dispatch(communities.actions.addNewCommunity(community)) + // Store other communitys' invitation data in redux + const invitationData = getValidInvitationUrlTestData(validInvitationCodeTestData[1]) + store.dispatch(communities.actions.setInvitationCodes(invitationData.data.pairs)) + + store.dispatch(communities.actions.addNewCommunity({ + ...community, + name: 'rockets', + })) store.dispatch(communities.actions.setCurrentCommunity(community.id)) @@ -141,10 +148,6 @@ describe('deepLinkSaga', () => { type: navigationActions.replaceScreen.type, payload: { screen: ScreenNames.ErrorScreen, - params: { - title: 'You already belong to a community', - message: "We're sorry but for now you can only be a member of a single community at a time", - }, }, }, }) @@ -190,13 +193,16 @@ describe('deepLinkSaga', () => { }, }, }) - .put( - communities.actions.createNetwork({ - ownership: CommunityOwnership.User, - peers: validData.pairs, - psk: validData.psk, - }) - ) + .put.like({ + action: { + type: communities.actions.createNetwork.type, + payload: { + ownership: CommunityOwnership.User, + peers: validData.pairs, + psk: validData.psk, + } + } + }) .run() }) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index f2b2f0500b..5605ab387b 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -102,6 +102,7 @@ export function* deepLinkSaga(action: PayloadAction Date: Thu, 14 Dec 2023 12:27:05 +0100 Subject: [PATCH 03/20] chore: fix lint --- .../store/init/deepLink/deepLink.saga.test.ts | 26 +++++++++++-------- .../src/store/init/deepLink/deepLink.saga.ts | 9 ++++--- .../areObjectsEqual/areObjectsEqual.ts | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts index f4a3713a44..fdb014d947 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -93,10 +93,12 @@ describe('deepLinkSaga', () => { ) store.dispatch(communities.actions.setInvitationCodes(validData.pairs)) - store.dispatch(communities.actions.addNewCommunity({ - ...community, - name: 'rockets' - })) + store.dispatch( + communities.actions.addNewCommunity({ + ...community, + name: 'rockets', + }) + ) store.dispatch( // @ts-expect-error @@ -132,10 +134,12 @@ describe('deepLinkSaga', () => { const invitationData = getValidInvitationUrlTestData(validInvitationCodeTestData[1]) store.dispatch(communities.actions.setInvitationCodes(invitationData.data.pairs)) - store.dispatch(communities.actions.addNewCommunity({ - ...community, - name: 'rockets', - })) + store.dispatch( + communities.actions.addNewCommunity({ + ...community, + name: 'rockets', + }) + ) store.dispatch(communities.actions.setCurrentCommunity(community.id)) @@ -162,7 +166,7 @@ describe('deepLinkSaga', () => { .run() }) - test('doesn\'t display error if user is connecting with the same community', async () => { + test("doesn't display error if user is connecting with the same community", async () => { store.dispatch( initActions.setWebsocketConnected({ dataPort: 5001, @@ -200,8 +204,8 @@ describe('deepLinkSaga', () => { ownership: CommunityOwnership.User, peers: validData.pairs, psk: validData.psk, - } - } + }, + }, }) .run() }) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index 5605ab387b..958fed41bc 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -52,14 +52,14 @@ export function* deepLinkSaga(action: PayloadAction currentInvitationCodes.some(currentCode => areObjectsEqual(storedCode, currentCode)) - ); + ) } console.log('Is invitation data valid', isInvitationDataValid) @@ -89,7 +89,10 @@ export function* deepLinkSaga(action: PayloadAction { - return JSON.stringify(obj1) === JSON.stringify(obj2); + return JSON.stringify(obj1) === JSON.stringify(obj2) } From 3f05e9306ebede249b3d14e4036be88956d26676 Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 14 Dec 2023 13:09:06 +0100 Subject: [PATCH 04/20] chore: cleanup --- .../store/init/deepLink/deepLink.saga.test.ts | 42 ------------------- .../src/store/init/deepLink/deepLink.saga.ts | 3 -- 2 files changed, 45 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts index fdb014d947..13f9499b1d 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -254,46 +254,4 @@ describe('deepLinkSaga', () => { ) .run() }) - - test.todo('continues if link used mid registration') - - test.skip('continues if link used mid registration and locks input while waiting for server response', async () => { - store.dispatch( - initActions.setWebsocketConnected({ - dataPort: 5001, - socketIOSecret: 'secret', - }) - ) - - store.dispatch(communities.actions.addNewCommunity(community)) - - store.dispatch( - // @ts-expect-error - identity.actions.addNewIdentity({ ..._identity, userCertificate: null }) - ) - - store.dispatch(communities.actions.setCurrentCommunity(community.id)) - - store.dispatch(connection.actions.setConnectionProcess(ConnectionProcessInfo.REGISTERING_USER_CERTIFICATE)) - - const reducer = combineReducers(reducers) - await expectSaga(deepLinkSaga, initActions.deepLink(validCode)) - .withReducer(reducer) - .withState(store.getState()) - .put( - navigationActions.replaceScreen({ - screen: ScreenNames.UsernameRegistrationScreen, - params: { fetching: true }, - }) - ) - .not.put( - communities.actions.createNetwork({ - ownership: CommunityOwnership.User, - peers: validData.pairs, - psk: validData.psk, - ownerOrbitDbIdentity: validData.ownerOrbitDbIdentity, - }) - ) - .run() - }) }) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index 958fed41bc..1caa58681c 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -82,9 +82,6 @@ export function* deepLinkSaga(action: PayloadAction Date: Thu, 14 Dec 2023 13:16:02 +0100 Subject: [PATCH 05/20] chore: update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ad5a52e03..18698f9310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +[unreleased] + +* Fix: joining with QR code after leaving community on mobile + [2.0.3-alpha.15] * Fix: construct all stores before initializing them - initializing community metadata store sets metadata in certificates store From 77044dba4b78be836b08bf8c8fbd89e07a6f11be Mon Sep 17 00:00:00 2001 From: siepra Date: Wed, 3 Jan 2024 08:30:07 +0100 Subject: [PATCH 06/20] chore: add debugging logs --- .DS_Store | Bin 6148 -> 6148 bytes packages/.DS_Store | Bin 8196 -> 6148 bytes packages/mobile/ios/Quiet/AppDelegate.m | 4 +++- packages/mobile/ios/TorHandler.swift | 4 ++-- .../blindConnection/blindConnection.saga.ts | 9 ++++++++- .../restoreConnection.saga.ts | 5 ++++- .../startConnection/startConnection.saga.ts | 7 ++++++- 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index 31ef813956be0676b361b18778c58f9025623f7e..13659620daf080d8b26750f60d9594ce9f9fc0e7 100644 GIT binary patch delta 31 ncmZoMXfc@J&&azmU^g=(?_?g9?9E$Qf|w^Z*llL#_{$Ffo~#NF delta 80 zcmZoMXfc@J&&aniU^g=(-(((^Y-4_g9EMbeB8EJMLw#Era}G-^^JaFAzx)9H=@O3s diff --git a/packages/.DS_Store b/packages/.DS_Store index bfe08eb44a46166782f3c12869e7a444a3efa7ed..0d635ae46e83e031e99b7dd60f7cff65bc5f4775 100644 GIT binary patch delta 103 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jG}fU^g=(?`9r>rOXq{!WOf0 pa0oI36##(%H;`}zsohxkoq009j3-DZ0~5p)kiiU_<9X&V0{~}Z5D5SP delta 202 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMA$hR?IH}hr%jz7$c**Q2SHn1@A zZRTNF${er6P{NSPPz)rK84?-NfNWicB!(h}e1>wMXeyAU%TNI3moa2Aq(DVd8FGNE zWS}mP$~@1U{N$vZ{3MW#KO9Yxxg@xOg03JJZ5HJC&ODi4#B;Jg R4+jS$#IX#U<9X&V0{{SuElL0Y diff --git a/packages/mobile/ios/Quiet/AppDelegate.m b/packages/mobile/ios/Quiet/AppDelegate.m index 7706f61020..032ea7a268 100644 --- a/packages/mobile/ios/Quiet/AppDelegate.m +++ b/packages/mobile/ios/Quiet/AppDelegate.m @@ -113,14 +113,16 @@ - (void) spinupBackend:(BOOL)init { // (1/6) Find ports to use in tor and backend configuration - FindFreePort *findFreePort = [FindFreePort new]; Utils *utils = [Utils new]; if (self.socketIOSecret == nil) { self.socketIOSecret = [utils generateSecretWithLength:(20)]; } + FindFreePort *findFreePort = [FindFreePort new]; + self.dataPort = [findFreePort getFirstStartingFromPort:11000]; + uint16_t socksPort = [findFreePort getFirstStartingFromPort:12000]; uint16_t controlPort = [findFreePort getFirstStartingFromPort:14000]; uint16_t httpTunnelPort = [findFreePort getFirstStartingFromPort:16000]; diff --git a/packages/mobile/ios/TorHandler.swift b/packages/mobile/ios/TorHandler.swift index 801284c106..8370278010 100644 --- a/packages/mobile/ios/TorHandler.swift +++ b/packages/mobile/ios/TorHandler.swift @@ -129,7 +129,7 @@ class TorHandler: NSObject { } guard let cookie = auth else { - print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") + // print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") return nil } @@ -148,7 +148,7 @@ class TorHandler: NSObject { } guard let cookie = auth else { - print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") + // print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") return nil } diff --git a/packages/mobile/src/store/init/blindConnection/blindConnection.saga.ts b/packages/mobile/src/store/init/blindConnection/blindConnection.saga.ts index 0da964a9e7..44571067c0 100644 --- a/packages/mobile/src/store/init/blindConnection/blindConnection.saga.ts +++ b/packages/mobile/src/store/init/blindConnection/blindConnection.saga.ts @@ -3,6 +3,13 @@ import { initSelectors } from '../init.selectors' import { initActions } from '../init.slice' export function* blindConnectionSaga(): Generator { + const isWebsocketConnected = yield* select(initSelectors.isWebsocketConnected) const lastKnownSocketIOData = yield* select(initSelectors.lastKnownSocketIOData) - yield* put(initActions.startWebsocketConnection(lastKnownSocketIOData)) + + console.log('WEBSOCKET', 'Entered blind connection saga', isWebsocketConnected, lastKnownSocketIOData) + + if (!isWebsocketConnected && lastKnownSocketIOData.dataPort !== 0) { + console.log('WEBSOCKET', 'Hooking up blindly at last known data port: ', lastKnownSocketIOData.dataPort) + yield* put(initActions.startWebsocketConnection(lastKnownSocketIOData)) + } } diff --git a/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts b/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts index b7dde652ff..dd7cb639e4 100644 --- a/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts +++ b/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts @@ -7,11 +7,14 @@ const WEBSOCKET_CONNECTION_DELAY = 5000 export function* restoreConnectionSaga(): Generator { // Give the worker time to init websocket connection yield* delay(WEBSOCKET_CONNECTION_DELAY + 1000) - + const isWebsocketConnected = yield* select(initSelectors.isWebsocketConnected) const socketIOData = yield* select(initSelectors.lastKnownSocketIOData) + console.log('WEBSOCKET', 'Entered restore connection saga', isWebsocketConnected, socketIOData) + if (!isWebsocketConnected && socketIOData.dataPort !== 0) { + console.log('WEBSOCKET', 'Restoring connection with data port: ', socketIOData.dataPort) yield* put(initActions.startWebsocketConnection(socketIOData)) } } diff --git a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts index 7911de1d62..5acfad31f0 100644 --- a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts +++ b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts @@ -1,14 +1,18 @@ import { io, Socket } from 'socket.io-client' -import { put, call, cancel, fork, takeEvery, FixedTask } from 'typed-redux-saga' +import { select, put, call, cancel, fork, takeEvery, FixedTask } from 'typed-redux-saga' import { PayloadAction } from '@reduxjs/toolkit' import { socket as stateManager } from '@quiet/state-manager' import { encodeSecret } from '@quiet/common' +import { initSelectors } from '../init.selectors' import { initActions, WebsocketConnectionPayload } from '../init.slice' import { eventChannel } from 'redux-saga' export function* startConnectionSaga( action: PayloadAction['payload']> ): Generator { + const isWebsocketConnected = yield* select(initSelectors.isWebsocketConnected) + console.log('WEBSOCKET', 'Entered start connection saga', isWebsocketConnected) + const { dataPort, socketIOSecret } = action.payload let _dataPort = dataPort @@ -33,6 +37,7 @@ export function* startConnectionSaga( function* setConnectedSaga(socket: Socket): Generator { const task = yield* fork(stateManager.useIO, socket) + console.log('WEBSOCKET', 'Forking state-manager sagas', task) // Handle suspending current connection yield* takeEvery(initActions.suspendWebsocketConnection, cancelRootTaskSaga, task) } From 2b0af5de087ee402d168e4ca6e9736dd7bb3b1fd Mon Sep 17 00:00:00 2001 From: siepra Date: Wed, 3 Jan 2024 13:42:23 +0100 Subject: [PATCH 07/20] fix: reset deep link flag --- packages/mobile/src/store/init/deepLink/deepLink.saga.ts | 3 +++ packages/mobile/src/store/init/init.slice.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index 3420fb198d..067dd961c8 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -24,6 +24,9 @@ export function* deepLinkSaga(action: PayloadAction) => { state.deepLinking = true }, + resetDeepLink: state => { + state.deepLinking = false + } }, }) From 02f720f71b8707d16ec3f146d721a9e137233aa2 Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 25 Jan 2024 15:59:36 +0100 Subject: [PATCH 08/20] chore: cleanup iOS --- packages/mobile/ios/Podfile.lock | 2 +- packages/mobile/ios/TorHandler.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mobile/ios/Podfile.lock b/packages/mobile/ios/Podfile.lock index 201e5c9a3b..6d0a4dac61 100644 --- a/packages/mobile/ios/Podfile.lock +++ b/packages/mobile/ios/Podfile.lock @@ -615,4 +615,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 986ea3b4bace0fe04a792347f3dc6f060797e84d -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.3 diff --git a/packages/mobile/ios/TorHandler.swift b/packages/mobile/ios/TorHandler.swift index 801284c106..8370278010 100644 --- a/packages/mobile/ios/TorHandler.swift +++ b/packages/mobile/ios/TorHandler.swift @@ -129,7 +129,7 @@ class TorHandler: NSObject { } guard let cookie = auth else { - print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") + // print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") return nil } @@ -148,7 +148,7 @@ class TorHandler: NSObject { } guard let cookie = auth else { - print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") + // print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") return nil } From dc8dd580d579d67ac13ac13f9b0250a228ce6f41 Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 25 Jan 2024 16:00:24 +0100 Subject: [PATCH 09/20] fix: correct redux cleanup order --- packages/mobile/src/store/init/init.slice.ts | 1 + .../src/store/init/startConnection/startConnection.saga.ts | 7 ++++--- .../nativeServices/leaveCommunity/leaveCommunity.saga.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/mobile/src/store/init/init.slice.ts b/packages/mobile/src/store/init/init.slice.ts index dd204eddb2..8c6f32788e 100644 --- a/packages/mobile/src/store/init/init.slice.ts +++ b/packages/mobile/src/store/init/init.slice.ts @@ -83,6 +83,7 @@ export const initSlice = createSlice({ resetDeepLink: state => { state.deepLinking = false }, + canceledRootTask: state => state }, }) diff --git a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts index 7911de1d62..4d998f3482 100644 --- a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts +++ b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts @@ -49,11 +49,11 @@ function subscribeSocketLifecycle(socket: Socket, socketIOData: WebsocketConnect ReturnType | ReturnType >(emit => { socket.on('connect', async () => { - console.log('websocket connected') + console.log('client: Websocket connected') emit(initActions.setWebsocketConnected(socketIOData)) }) socket.on('disconnect', () => { - console.log('closing socket connection') + console.log('client: Closing socket connection') emit(initActions.suspendWebsocketConnection()) }) return () => {} @@ -61,6 +61,7 @@ function subscribeSocketLifecycle(socket: Socket, socketIOData: WebsocketConnect } function* cancelRootTaskSaga(task: FixedTask): Generator { - console.log('canceling root task') + console.log('Canceling root task') yield* cancel(task) + yield* put (initActions.canceledRootTask()) } diff --git a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts index ca5c669fc3..35f723f2ac 100644 --- a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts +++ b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts @@ -11,7 +11,7 @@ export function* leaveCommunitySaga(): Generator { // Restart backend yield* put(app.actions.closeServices()) - yield takeLeading(initActions.suspendWebsocketConnection.type, clearReduxStore) + yield takeLeading(initActions.canceledRootTask.type, clearReduxStore) } export function* clearReduxStore(): Generator { From c5de55de03b1610f2d42baf526ddcb8f3ee40f2d Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 25 Jan 2024 16:01:01 +0100 Subject: [PATCH 10/20] chore: comment out persistor flushing --- .../nativeServices/leaveCommunity/leaveCommunity.saga.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts index 35f723f2ac..99ac163b34 100644 --- a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts +++ b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts @@ -21,15 +21,15 @@ export function* clearReduxStore(): Generator { console.info('Clearing redux store') // Stop persistor - yield* call(persistor.pause) - yield* call(persistor.flush) - yield* call(persistor.purge) + // yield* call(persistor.pause) + // yield* call(persistor.flush) + // yield* call(persistor.purge) // Clear redux store yield* put(nativeServicesActions.resetApp()) // Resume persistor - yield* call(persistor.persist) + // yield* call(persistor.persist) yield* put(navigationActions.replaceScreen({ screen: ScreenNames.JoinCommunityScreen })) } From 85fdeca1d77474ce7da7ece12338303a35747378 Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 25 Jan 2024 16:27:25 +0100 Subject: [PATCH 11/20] chore: add debug log for launching application --- packages/mobile/src/App.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/mobile/src/App.tsx b/packages/mobile/src/App.tsx index eb97b611f3..b3c64c879b 100644 --- a/packages/mobile/src/App.tsx +++ b/packages/mobile/src/App.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect } from 'react' import { useDispatch } from 'react-redux' import { LogBox, StatusBar } from 'react-native' @@ -74,6 +74,10 @@ function App(): JSX.Element { const confirmationBox = useConfirmationBox() + useEffect(() => { + console.log('LAUNCHED APPLICATION: ', (Math.random() + 1).toString(36).substring(7)) + }, []) + return ( From f4d695e3934aa49b1d1053437d3de401fd3d2202 Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 25 Jan 2024 16:40:28 +0100 Subject: [PATCH 12/20] chore: log socket id on its lifecycle callbacks --- .../src/store/init/startConnection/startConnection.saga.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts index 4d998f3482..0cb816c9d7 100644 --- a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts +++ b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts @@ -45,15 +45,17 @@ function* handleSocketLifecycleActions(socket: Socket, socketIOData: WebsocketCo } function subscribeSocketLifecycle(socket: Socket, socketIOData: WebsocketConnectionPayload) { + let socket_id: string return eventChannel< ReturnType | ReturnType >(emit => { socket.on('connect', async () => { - console.log('client: Websocket connected') + socket_id = socket.id + console.log('client: Websocket connected', socket_id) emit(initActions.setWebsocketConnected(socketIOData)) }) socket.on('disconnect', () => { - console.log('client: Closing socket connection') + console.log('client: Closing socket connection', socket_id) emit(initActions.suspendWebsocketConnection()) }) return () => {} From fb2744a35fe5993314fd151fa200a6ac525597f0 Mon Sep 17 00:00:00 2001 From: siepra Date: Mon, 29 Jan 2024 14:47:26 +0100 Subject: [PATCH 13/20] fix: deep link redirection --- .../src/store/init/deepLink/deepLink.saga.ts | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index 6a17b7e56b..1f75b97341 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -69,15 +69,20 @@ export function* deepLinkSaga(action: PayloadAction replaceScreen(ScreenNames.UsernameRegistrationScreen), + icon: appImages.quiet_icon_round, + title: 'You already started to connect to another community', + message: "We're sorry but for now you can only be a member of a single community at a time", + }, + }) + ) + + return + } + + // console.log('INIT_NAVIGATION: Switching to the join community screen.') + + // yield* put( + // navigationActions.replaceScreen({ + // screen: ScreenNames.JoinCommunityScreen, + // params: { + // code, + // }, + // }) + // ) const payload: CreateNetworkPayload = { ownership: CommunityOwnership.User, @@ -130,9 +153,10 @@ export function* deepLinkSaga(action: PayloadAction Date: Mon, 29 Jan 2024 15:55:36 +0100 Subject: [PATCH 14/20] fix: undo comment out persistor cleanup --- .../nativeServices/leaveCommunity/leaveCommunity.saga.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts index f79906b5ae..33df360946 100644 --- a/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts +++ b/packages/mobile/src/store/nativeServices/leaveCommunity/leaveCommunity.saga.ts @@ -23,15 +23,15 @@ export function* clearReduxStore(): Generator { console.info('Clearing redux store') // Stop persistor - // yield* call(persistor.pause) - // yield* call(persistor.flush) - // yield* call(persistor.purge) + yield* call(persistor.pause) + yield* call(persistor.flush) + yield* call(persistor.purge) // Clear redux store yield* put(nativeServicesActions.resetApp()) // Resume persistor - // yield* call(persistor.persist) + yield* call(persistor.persist) // Restarting persistor doesn't mark store as ready automatically yield* put(initActions.setStoreReady()) From a3471ba0f2a9d6e442f2f7185b0818f99f8ccbbe Mon Sep 17 00:00:00 2001 From: siepra Date: Mon, 29 Jan 2024 17:11:08 +0100 Subject: [PATCH 15/20] fix: tests --- .../src/store/init/deepLink/deepLink.saga.test.ts | 12 ++++++------ packages/mobile/src/tests/deep.linking.test.tsx | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts index cd3d3cfb61..da33a05414 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -60,12 +60,7 @@ describe('deepLinkSaga', () => { .withReducer(reducer) .withState(store.getState()) .put( - navigationActions.replaceScreen({ - screen: ScreenNames.JoinCommunityScreen, - params: { - code: validCode, - }, - }) + initActions.resetDeepLink() ) .put( communities.actions.createNetwork({ @@ -75,6 +70,11 @@ describe('deepLinkSaga', () => { ownerOrbitDbIdentity: validData.ownerOrbitDbIdentity, }) ) + .put( + navigationActions.replaceScreen({ + screen: ScreenNames.UsernameRegistrationScreen + }) + ) .run() }) diff --git a/packages/mobile/src/tests/deep.linking.test.tsx b/packages/mobile/src/tests/deep.linking.test.tsx index f1dde19c5e..c4825e4f48 100644 --- a/packages/mobile/src/tests/deep.linking.test.tsx +++ b/packages/mobile/src/tests/deep.linking.test.tsx @@ -50,13 +50,15 @@ describe('Deep linking', () => { [ "Init/deepLink", "Init/resetDeepLink", - "Navigation/replaceScreen", "Communities/createNetwork", "Communities/setInvitationCodes", + "Navigation/replaceScreen", "Communities/savePSK", "Communities/addNewCommunity", "Communities/setCurrentCommunity", "Init/deepLink", + "Init/resetDeepLink", + "Navigation/replaceScreen", ] `) From 640bf91a26292efb059c5a35fb3263c9031a51dd Mon Sep 17 00:00:00 2001 From: siepra Date: Mon, 29 Jan 2024 17:12:16 +0100 Subject: [PATCH 16/20] fix: lint --- .../mobile/src/store/init/deepLink/deepLink.saga.test.ts | 6 ++---- packages/mobile/src/store/init/init.slice.ts | 2 +- .../restoreConnection/restoreConnection.saga.ts | 2 +- .../src/store/init/startConnection/startConnection.saga.ts | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts index da33a05414..b019eb86c7 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -59,9 +59,7 @@ describe('deepLinkSaga', () => { await expectSaga(deepLinkSaga, initActions.deepLink(validCode)) .withReducer(reducer) .withState(store.getState()) - .put( - initActions.resetDeepLink() - ) + .put(initActions.resetDeepLink()) .put( communities.actions.createNetwork({ ownership: CommunityOwnership.User, @@ -72,7 +70,7 @@ describe('deepLinkSaga', () => { ) .put( navigationActions.replaceScreen({ - screen: ScreenNames.UsernameRegistrationScreen + screen: ScreenNames.UsernameRegistrationScreen, }) ) .run() diff --git a/packages/mobile/src/store/init/init.slice.ts b/packages/mobile/src/store/init/init.slice.ts index 8c6f32788e..f256964c22 100644 --- a/packages/mobile/src/store/init/init.slice.ts +++ b/packages/mobile/src/store/init/init.slice.ts @@ -83,7 +83,7 @@ export const initSlice = createSlice({ resetDeepLink: state => { state.deepLinking = false }, - canceledRootTask: state => state + canceledRootTask: state => state, }, }) diff --git a/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts b/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts index dd7cb639e4..7b7195b2be 100644 --- a/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts +++ b/packages/mobile/src/store/init/startConnection/restoreConnection/restoreConnection.saga.ts @@ -7,7 +7,7 @@ const WEBSOCKET_CONNECTION_DELAY = 5000 export function* restoreConnectionSaga(): Generator { // Give the worker time to init websocket connection yield* delay(WEBSOCKET_CONNECTION_DELAY + 1000) - + const isWebsocketConnected = yield* select(initSelectors.isWebsocketConnected) const socketIOData = yield* select(initSelectors.lastKnownSocketIOData) diff --git a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts index 853b77fd92..3b45ea7dd9 100644 --- a/packages/mobile/src/store/init/startConnection/startConnection.saga.ts +++ b/packages/mobile/src/store/init/startConnection/startConnection.saga.ts @@ -70,5 +70,5 @@ function subscribeSocketLifecycle(socket: Socket, socketIOData: WebsocketConnect function* cancelRootTaskSaga(task: FixedTask): Generator { console.log('Canceling root task') yield* cancel(task) - yield* put (initActions.canceledRootTask()) + yield* put(initActions.canceledRootTask()) } From 65656603172655e93acb6ba8e10b40880be5a59e Mon Sep 17 00:00:00 2001 From: siepra Date: Mon, 29 Jan 2024 17:49:01 +0100 Subject: [PATCH 17/20] chore: undo CHANGELOG.md changes --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e91cfbf4..1f583ad97b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,8 +75,6 @@ * Fix: mobile app crashing on restart -* Fix: joining with QR code after leaving community on mobile - * Refactor: backend, storage module - extracting OrbitDB as another provider, refactor of CertificatesRequestsStore, CommunityMetadataStore, CertificatesStore as Nest providers, store tests adjustments, file structure [2.0.3-alpha.15] From 93cfa03b6fd20099ffff91612a0d85fb88371297 Mon Sep 17 00:00:00 2001 From: siepra Date: Mon, 29 Jan 2024 17:52:47 +0100 Subject: [PATCH 18/20] chore: update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f583ad97b..0c3816eb24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +[2.1.1] - unreleased + +# Fixes: + +* Opening the mobile app with joining links has been corrected. + [2.1.0] # New features: From 5ad5eb150346ce3702ca5e8d992b04bc283c4abf Mon Sep 17 00:00:00 2001 From: siepra Date: Mon, 29 Jan 2024 17:54:36 +0100 Subject: [PATCH 19/20] chore: cleanup --- packages/mobile/ios/TorHandler.swift | 4 ---- .../src/store/init/deepLink/deepLink.saga.ts | 14 -------------- 2 files changed, 18 deletions(-) diff --git a/packages/mobile/ios/TorHandler.swift b/packages/mobile/ios/TorHandler.swift index 8370278010..1a62ade0f4 100644 --- a/packages/mobile/ios/TorHandler.swift +++ b/packages/mobile/ios/TorHandler.swift @@ -129,8 +129,6 @@ class TorHandler: NSObject { } guard let cookie = auth else { - // print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") - return nil } @@ -148,8 +146,6 @@ class TorHandler: NSObject { } guard let cookie = auth else { - // print("[\(String(describing: type(of: self)))] Could not connect to Tor - cookie unreadable!") - return nil } diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index 1f75b97341..b8d5ece16f 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -132,17 +132,6 @@ export function* deepLinkSaga(action: PayloadAction Date: Tue, 30 Jan 2024 14:58:52 +0100 Subject: [PATCH 20/20] chore: cleanup --- packages/mobile/src/store/init/deepLink/deepLink.saga.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index b8d5ece16f..4c98593786 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -94,16 +94,11 @@ export function* deepLinkSaga(action: PayloadAction replaceScreen(destination), + onPress: () => replaceScreen(ScreenNames.ChannelListScreen), icon: appImages.quiet_icon_round, title: 'You already belong to a community', message: "We're sorry but for now you can only be a member of a single community at a time",