Skip to content

Commit

Permalink
fix: Move dmKey generation to prevent UI delay during joining
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Leblow committed Mar 27, 2024
1 parent 799256f commit 26d6a83
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { socketSelectors } from '../../../sagas/socket/socket.selectors'
import { communities, identity } from '@quiet/state-manager'
import { CommunityOwnership, CreateNetworkPayload } from '@quiet/types'
import { CommunityOwnership, AddCommunityPayload } from '@quiet/types'
import PerformCommunityActionComponent from '../PerformCommunityActionComponent'
import { ModalName } from '../../../sagas/modals/modals.types'
import { useModal } from '../../../containers/hooks'
Expand All @@ -25,11 +25,11 @@ const CreateCommunity = () => {
}, [currentCommunity])

const handleCommunityAction = (name: string) => {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.Owner,
name: name,
}
dispatch(communities.actions.createNetwork(payload))
dispatch(communities.actions.addCommunity(payload))
}

// From 'You can join a community instead' link
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { socketSelectors } from '../../../sagas/socket/socket.selectors'
import { CommunityOwnership, CreateNetworkPayload, InvitationData, InvitationPair } from '@quiet/types'
import { CommunityOwnership, AddCommunityPayload, InvitationData, InvitationPair } from '@quiet/types'
import { communities, identity, connection, network } from '@quiet/state-manager'
import PerformCommunityActionComponent from '../../../components/CreateJoinCommunity/PerformCommunityActionComponent'
import { ModalName } from '../../../sagas/modals/modals.types'
Expand Down Expand Up @@ -39,13 +39,13 @@ const JoinCommunity = () => {
}, [currentCommunity])

const handleCommunityAction = (data: InvitationData) => {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: data.pairs,
psk: data.psk,
ownerOrbitDbIdentity: data.ownerOrbitDbIdentity,
}
dispatch(communities.actions.createNetwork(payload))
dispatch(communities.actions.addCommunity(payload))
}

// From 'You can create a new community instead' link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ const CreateUsername = () => {
}, [currentIdentity, currentCommunity])

const registerUsername = (nickname: string) => {
dispatch(
identity.actions.registerUsername({
nickname,
})
)

dispatch(identity.actions.registerUsername({ nickname }))
dispatch(network.actions.setLoadingPanelType(LoadingPanelType.Joining))
loadingPanelModal.handleOpen()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { communities, getFactory, Store } from '@quiet/state-manager'
import { Community, CommunityOwnership, CreateNetworkPayload, InvitationData } from '@quiet/types'
import { Community, CommunityOwnership, AddCommunityPayload, InvitationData } from '@quiet/types'
import { FactoryGirl } from 'factory-girl'
import { expectSaga } from 'redux-saga-test-plan'
import { customProtocolSaga } from './customProtocol.saga'
Expand Down Expand Up @@ -32,21 +32,21 @@ describe('Handle invitation code', () => {
})

it('creates network if code is valid', async () => {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: validInvitationData.pairs,
psk: validInvitationData.psk,
ownerOrbitDbIdentity: validInvitationData.ownerOrbitDbIdentity,
}
await expectSaga(customProtocolSaga, communities.actions.customProtocol(validInvitationData))
.withState(store.getState())
.put(communities.actions.createNetwork(payload))
.put(communities.actions.addCommunity(payload))
.run()
})

it('does not try to create network if user is already in community', async () => {
community = await factory.create<ReturnType<typeof communities.actions.addNewCommunity>['payload']>('Community')
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: validInvitationData.pairs,
psk: validInvitationData.psk,
Expand All @@ -63,12 +63,12 @@ describe('Handle invitation code', () => {
},
})
)
.not.put(communities.actions.createNetwork(payload))
.not.put(communities.actions.addCommunity(payload))
.run()
})

it('does not try to create network if code is missing addresses', async () => {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: [],
}
Expand All @@ -92,12 +92,12 @@ describe('Handle invitation code', () => {
},
})
)
.not.put(communities.actions.createNetwork(payload))
.not.put(communities.actions.addCommunity(payload))
.run()
})

it('does not try to create network if code is missing psk', async () => {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: [],
}
Expand All @@ -121,7 +121,7 @@ describe('Handle invitation code', () => {
},
})
)
.not.put(communities.actions.createNetwork(payload))
.not.put(communities.actions.addCommunity(payload))
.run()
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PayloadAction } from '@reduxjs/toolkit'
import { select, put, delay } from 'typed-redux-saga'
import { CommunityOwnership, CreateNetworkPayload } from '@quiet/types'
import { CommunityOwnership, AddCommunityPayload } from '@quiet/types'
import { communities } from '@quiet/state-manager'
import { socketSelectors } from '../socket/socket.selectors'
import { ModalName } from '../modals/modals.types'
Expand Down Expand Up @@ -32,13 +32,13 @@ export function* customProtocolSaga(
}
const invitationData = action.payload
if (invitationData && invitationData.pairs.length > 0 && invitationData.psk && invitationData.ownerOrbitDbIdentity) {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: invitationData.pairs,
psk: invitationData.psk,
ownerOrbitDbIdentity: invitationData.ownerOrbitDbIdentity,
}
yield* put(communities.actions.createNetwork(payload))
yield* put(communities.actions.addCommunity(payload))
} else {
yield* put(communities.actions.clearInvitationCodes())
yield* put(
Expand Down
14 changes: 7 additions & 7 deletions packages/integration-tests/src/integrationTests/appActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
connection,
publicChannels,
RegisterCertificatePayload,
CreateNetworkPayload,
AddCommunityPayload,
CommunityOwnership,
TestStore,
ChannelMessage,
Expand Down Expand Up @@ -76,12 +76,12 @@ export async function createCommunity({ userName, store }: CreateCommunity) {
const timeout = 20_000
const communityName = 'CommunityName'

const createNetworkPayload: CreateNetworkPayload = {
const addCommunityPayload: AddCommunityPayload = {
ownership: CommunityOwnership.Owner,
name: communityName,
}

store.dispatch(communities.actions.createNetwork(createNetworkPayload))
store.dispatch(communities.actions.addCommunity(addCommunityPayload))

await waitForExpect(() => {
expect(store.getState().Identity.identities.ids).toHaveLength(1)
Expand Down Expand Up @@ -126,11 +126,11 @@ export async function registerUsername(payload: Register) {
// Give it a huge timeout, it should never fail, but sometimes takes more time, depending on tor.
const timeout = 600_000

const createNetworkPayload: CreateNetworkPayload = {
const addCommunityPayload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
}

store.dispatch(communities.actions.createNetwork(createNetworkPayload))
store.dispatch(communities.actions.addCommunity(addCommunityPayload))

await waitForExpect(() => {
expect(store.getState().Identity.identities.ids).toHaveLength(1)
Expand Down Expand Up @@ -265,11 +265,11 @@ export const sendRegistrationRequest = async (payload: SendRegistrationRequest)

const timeout = 600_000

const createNetworkPayload: CreateNetworkPayload = {
const addCommunityPayload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
}

store.dispatch(communities.actions.createNetwork(createNetworkPayload))
store.dispatch(communities.actions.addCommunity(addCommunityPayload))

await waitForExpect(() => {
expect(store.getState().Identity.identities.ids).toHaveLength(1)
Expand Down
12 changes: 6 additions & 6 deletions packages/integration-tests/src/testUtils/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
ChannelMessage,
communities,
CommunityOwnership,
CreateNetworkPayload,
AddCommunityPayload,
identity,
publicChannels,
messages,
Expand All @@ -19,11 +19,11 @@ const timeout = 120_000
export async function registerUsername(payload: Register) {
const { userName, store } = payload

const createNetworkPayload: CreateNetworkPayload = {
const addCommunityPayload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
}
log(`User ${userName} starts creating network`)
store.dispatch(communities.actions.createNetwork(createNetworkPayload))
log(`User ${userName} starts adding community`)
store.dispatch(communities.actions.addCommunity(addCommunityPayload))

await waitForExpect(() => {
assert.equal(store.getState().Identity.identities.ids.length, 1)
Expand All @@ -46,12 +46,12 @@ export async function registerUsername(payload: Register) {
}

export const createCommunity = async ({ username, communityName, store }): Promise<string> => {
const createNetworkPayload: CreateNetworkPayload = {
const addCommunityPayload: AddCommunityPayload = {
ownership: CommunityOwnership.Owner,
name: communityName,
}

store.dispatch(communities.actions.createNetwork(createNetworkPayload))
store.dispatch(communities.actions.addCommunity(addCommunityPayload))
await waitForExpect(() => {
assert.strictEqual(store.getState().Identity.identities.ids.length, 1)
}, timeout)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, useCallback } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { identity, communities } from '@quiet/state-manager'
import { CommunityOwnership, CreateNetworkPayload } from '@quiet/types'
import { CommunityOwnership, AddCommunityPayload } from '@quiet/types'
import { initSelectors } from '../../store/init/init.selectors'
import { navigationActions } from '../../store/navigation/navigation.slice'
import { ScreenNames } from '../../const/ScreenNames.enum'
Expand All @@ -19,11 +19,11 @@ export const CreateCommunityScreen: FC = () => {

const createCommunityAction = useCallback(
(name: string) => {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.Owner,
name,
}
dispatch(communities.actions.createNetwork(payload))
dispatch(communities.actions.addCommunity(payload))
dispatch(
navigationActions.navigation({
screen: ScreenNames.UsernameRegistrationScreen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { FC, useCallback, useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { identity, communities } from '@quiet/state-manager'
import { CommunityOwnership, CreateNetworkPayload, InvitationData, InvitationPair } from '@quiet/types'
import { CommunityOwnership, AddCommunityPayload, InvitationData, InvitationPair } from '@quiet/types'
import { JoinCommunity } from '../../components/JoinCommunity/JoinCommunity.component'
import { navigationActions } from '../../store/navigation/navigation.slice'
import { ScreenNames } from '../../const/ScreenNames.enum'
Expand Down Expand Up @@ -36,13 +36,13 @@ export const JoinCommunityScreen: FC<JoinCommunityScreenProps> = ({ route }) =>

const joinCommunityAction = useCallback(
(data: InvitationData) => {
const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: data.pairs,
psk: data.psk,
ownerOrbitDbIdentity: data.ownerOrbitDbIdentity,
}
dispatch(communities.actions.createNetwork(payload))
dispatch(communities.actions.addCommunity(payload))
dispatch(
navigationActions.navigation({
screen: ScreenNames.UsernameRegistrationScreen,
Expand Down
10 changes: 5 additions & 5 deletions packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('deepLinkSaga', () => {
.withState(store.getState())
.put(initActions.resetDeepLink())
.put(
communities.actions.createNetwork({
communities.actions.addCommunity({
ownership: CommunityOwnership.User,
peers: validData.pairs,
psk: validData.psk,
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('deepLinkSaga', () => {
.withReducer(reducer)
.withState(store.getState())
.not.put(
communities.actions.createNetwork({
communities.actions.addCommunity({
ownership: CommunityOwnership.User,
peers: validData.pairs,
psk: validData.psk,
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('deepLinkSaga', () => {
},
})
.not.put(
communities.actions.createNetwork({
communities.actions.addCommunity({
ownership: CommunityOwnership.User,
peers: validData.pairs,
psk: validData.psk,
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('deepLinkSaga', () => {
})
.put.like({
action: {
type: communities.actions.createNetwork.type,
type: communities.actions.addCommunity.type,
payload: {
ownership: CommunityOwnership.User,
peers: validData.pairs,
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('deepLinkSaga', () => {
},
})
.not.put(
communities.actions.createNetwork({
communities.actions.addCommunity({
ownership: CommunityOwnership.User,
peers: validData.pairs,
psk: validData.psk,
Expand Down
6 changes: 3 additions & 3 deletions packages/mobile/src/store/init/deepLink/deepLink.saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initSelectors } from '../init.selectors'
import { initActions } from '../init.slice'
import { appImages } from '../../../assets'
import { replaceScreen } from '../../../RootNavigation'
import { CommunityOwnership, CreateNetworkPayload, InvitationData } from '@quiet/types'
import { CommunityOwnership, AddCommunityPayload, InvitationData } from '@quiet/types'
import { areObjectsEqual } from '../../../utils/functions/areObjectsEqual/areObjectsEqual'

export function* deepLinkSaga(action: PayloadAction<ReturnType<typeof initActions.deepLink>['payload']>): Generator {
Expand Down Expand Up @@ -127,14 +127,14 @@ export function* deepLinkSaga(action: PayloadAction<ReturnType<typeof initAction
return
}

const payload: CreateNetworkPayload = {
const payload: AddCommunityPayload = {
ownership: CommunityOwnership.User,
peers: data.pairs,
psk: data.psk,
ownerOrbitDbIdentity: data.ownerOrbitDbIdentity,
}

yield* put(communities.actions.createNetwork(payload))
yield* put(communities.actions.addCommunity(payload))

console.log('INIT_NAVIGATION: Switching to the username registration screen.')

Expand Down
Loading

0 comments on commit 26d6a83

Please sign in to comment.