-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucas Leblow
committed
Mar 8, 2024
1 parent
c17cb0d
commit a8db4ee
Showing
27 changed files
with
180 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/state-manager/src/sagas/communities/createCommunity/createCommunity.saga.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { type Socket, applyEmitParams } from '../../../types' | ||
import { select, apply, put } from 'typed-redux-saga' | ||
import { type PayloadAction } from '@reduxjs/toolkit' | ||
import { identityActions } from '../../identity/identity.slice' | ||
import { communitiesSelectors } from '../communities.selectors' | ||
import { communitiesActions } from '../communities.slice' | ||
import { identitySelectors } from '../../identity/identity.selectors' | ||
import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' | ||
import { type Community, type InitCommunityPayload, SocketActionTypes } from '@quiet/types' | ||
|
||
export function* createCommunitySaga( | ||
socket: Socket, | ||
action: PayloadAction<ReturnType<typeof communitiesActions.createCommunity>['payload']> | ||
): Generator { | ||
let communityId: string = action.payload | ||
|
||
if (!communityId) { | ||
communityId = yield* select(communitiesSelectors.currentCommunityId) | ||
} | ||
|
||
const community = yield* select(communitiesSelectors.selectById(communityId)) | ||
const identity = yield* select(identitySelectors.selectById(communityId)) | ||
|
||
if (!identity) return | ||
|
||
const payload: InitCommunityPayload = { | ||
id: communityId, | ||
name: community?.name, | ||
peerId: identity.peerId, | ||
hiddenService: identity.hiddenService, | ||
CA: community?.CA, | ||
rootCa: community?.rootCa, | ||
// Type mismatch between `userCsr | null` in Identity and `ownerCsr?` in | ||
// InitCommunityPayload | ||
ownerCsr: identity.userCsr ?? undefined, | ||
} | ||
|
||
const createdCommunity: Community | undefined = yield* apply( | ||
socket, | ||
socket.emitWithAck, | ||
applyEmitParams(SocketActionTypes.CREATE_COMMUNITY, payload) | ||
) | ||
|
||
if (!createdCommunity || !createdCommunity.ownerCertificate) return | ||
|
||
yield* put(communitiesActions.updateCommunityData(createdCommunity)) | ||
|
||
yield* put( | ||
identityActions.storeUserCertificate({ | ||
communityId: createdCommunity.id, | ||
userCertificate: createdCommunity.ownerCertificate, | ||
}) | ||
) | ||
|
||
// TODO: Community metadata should already exist on the backend after creating | ||
// the community. | ||
yield* put(communitiesActions.sendCommunityMetadata()) | ||
yield* put(publicChannelsActions.createGeneralChannel()) | ||
// TODO: We can likely refactor this a bit. Currently, we issue the owner's | ||
// certificate before creating the community, but then we add the owner's CSR | ||
// to the OrbitDB store after creating the community (in the following saga). | ||
// We can likely add the owner's CSR when creating the community or decouple | ||
// community creation from CSR/certificate creation and create the community | ||
// first and then add the owner's CSR and issue their certificate. | ||
yield* put(identityActions.saveUserCsr()) | ||
} |
Oops, something went wrong.