Skip to content

Commit

Permalink
fix: deep linking issues (#2154)
Browse files Browse the repository at this point in the history
* fix: mark redux store ready after leaving community #1970

* test: fix deepLink tests

* chore: fix lint

* chore: cleanup

* chore: update CHANGELOG.md

* chore: add debugging logs

* fix: reset deep link flag

* chore: cleanup iOS

* fix: correct redux cleanup order

* chore: comment out persistor flushing

* chore: add debug log for launching application

* chore: log socket id on its lifecycle callbacks

* fix: deep link redirection

* fix: undo comment out persistor cleanup

* fix: tests

* fix: lint

* chore: undo CHANGELOG.md changes

* chore: update CHANGELOG.md

* chore: cleanup

* chore: cleanup
  • Loading branch information
siepra authored Jan 30, 2024
1 parent 20ef074 commit 2867264
Show file tree
Hide file tree
Showing 16 changed files with 192 additions and 101 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[2.1.1] - unreleased

# Fixes:

* Opening the mobile app with joining links has been corrected.

[2.1.0]

# New features:
Expand Down
Binary file modified packages/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 986ea3b4bace0fe04a792347f3dc6f060797e84d

COCOAPODS: 1.13.0
COCOAPODS: 1.14.3
4 changes: 3 additions & 1 deletion packages/mobile/ios/Quiet/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 0 additions & 4 deletions packages/mobile/ios/TorHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
6 changes: 5 additions & 1 deletion packages/mobile/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { useEffect } from 'react'
import { useDispatch } from 'react-redux'

import { LogBox, StatusBar } from 'react-native'
Expand Down Expand Up @@ -74,6 +74,10 @@ function App(): JSX.Element {

const confirmationBox = useConfirmationBox()

useEffect(() => {
console.log('LAUNCHED APPLICATION: ', (Math.random() + 1).toString(36).substring(7))
}, [])

return (
<SafeAreaProvider>
<SafeAreaView style={{ flex: 1 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
132 changes: 70 additions & 62 deletions packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -59,14 +59,7 @@ describe('deepLinkSaga', () => {
await expectSaga(deepLinkSaga, initActions.deepLink(validCode))
.withReducer(reducer)
.withState(store.getState())
.put(
navigationActions.replaceScreen({
screen: ScreenNames.JoinCommunityScreen,
params: {
code: validCode,
},
})
)
.put(initActions.resetDeepLink())
.put(
communities.actions.createNetwork({
ownership: CommunityOwnership.User,
Expand All @@ -75,9 +68,15 @@ describe('deepLinkSaga', () => {
ownerOrbitDbIdentity: validData.ownerOrbitDbIdentity,
})
)
.put(
navigationActions.replaceScreen({
screen: ScreenNames.UsernameRegistrationScreen,
})
)
.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({
Expand All @@ -86,7 +85,13 @@ 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
Expand All @@ -99,11 +104,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,
Expand All @@ -123,9 +123,19 @@ 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))

const reducer = combineReducers(reducers)
await expectSaga(deepLinkSaga, initActions.deepLink(validCode))
.withReducer(reducer)
Expand All @@ -135,10 +145,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",
},
},
},
})
Expand All @@ -153,6 +159,50 @@ 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.like({
action: {
type: communities.actions.createNetwork.type,
payload: {
ownership: CommunityOwnership.User,
peers: validData.pairs,
psk: validData.psk,
},
},
})
.run()
})

test('displays error if invitation code is invalid', async () => {
const invalidData: InvitationData = {
pairs: [
Expand Down Expand Up @@ -197,46 +247,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()
})
})
Loading

0 comments on commit 2867264

Please sign in to comment.