Skip to content

Commit

Permalink
refactor: pass whole InvitationData through joining/creating process;…
Browse files Browse the repository at this point in the history
… save it in Community
  • Loading branch information
EmiM committed Apr 17, 2024
1 parent 4c66c72 commit 3961b17
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import {
ChannelsReplicatedPayload,
Community,
CommunityMetadata,
CommunityOwnership,
ConnectionProcessInfo,
CreateChannelPayload,
CreateChannelResponse,
CreateNetworkPayload,
DeleteFilesFromChannelSocketPayload,
DownloadStatus,
ErrorMessages,
FileMetadata,
GetMessagesPayload,
InitCommunityPayload,
InvitationDataV2,
InvitationDataVersion,
MessagesLoadedPayload,
NetworkDataPayload,
NetworkInfo,
Expand All @@ -39,7 +39,6 @@ import {
SaveCSRPayload,
SendCertificatesResponse,
SendMessagePayload,
ServerInvitationData,
SocketActionTypes,
UploadFilePayload,
type DeleteChannelResponse,
Expand Down Expand Up @@ -393,7 +392,7 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
return community
}

public async downloadCommunityData(inviteData: ServerInvitationData) {
public async downloadCommunityData(inviteData: InvitationDataV2) {
this.logger('Downloading invite data', inviteData)
this.storageServerProxyService.setServerAddress(inviteData.serverAddress)
let downloadedData: ServerStoredCommunityMetadata
Expand All @@ -420,17 +419,21 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI

const inviteData = payload.inviteData
if (inviteData) {
const downloadedData = await this.downloadCommunityData(inviteData)
if (!downloadedData) {
emitError(this.serverIoProvider.io, {
type: SocketActionTypes.LAUNCH_COMMUNITY,
message: ErrorMessages.STORAGE_SERVER_CONNECTION_FAILED,
})
return
this.logger(`Joining community: inviteData version: ${inviteData.version}`)
switch (inviteData.version) {
case InvitationDataVersion.v2:
const downloadedData = await this.downloadCommunityData(inviteData)
if (!downloadedData) {
emitError(this.serverIoProvider.io, {
type: SocketActionTypes.LAUNCH_COMMUNITY,
message: ErrorMessages.STORAGE_SERVER_CONNECTION_FAILED,
})
return
}
metadata = downloadedData
break
}
metadata = downloadedData
}
this.logger('Joining community: metadata:', metadata)

if (!metadata.peers || metadata.peers.length === 0) {
this.logger.error('Joining community: Peers required')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('createNetwork', () => {
...community,
psk: inviteData.psk,
ownerOrbitDbIdentity: inviteData.ownerOrbitDbIdentity,
inviteData,
}

const reducer = combineReducers(reducers)
Expand Down Expand Up @@ -136,6 +137,7 @@ describe('createNetwork', () => {
name: 'rockets',
CA,
rootCa: CA.rootCertString,
inviteData: undefined,
}

const reducer = combineReducers(reducers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function* createNetworkSaga(
name: payload.name,
CA,
rootCa: CA?.rootCertString,
inviteData: payload.inviteData,
}

if (payload.inviteData) {
Expand All @@ -66,9 +67,6 @@ export function* createNetworkSaga(
yield* put(communitiesActions.setInvitationCodes(invitationPeers))
}
break
case InvitationDataVersion.v2:
community.inviteData = payload.inviteData
break
}
}

Expand Down
15 changes: 3 additions & 12 deletions packages/types/src/community.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type HiddenService, type PeerId, type Identity, type UserCsr } from './identity'
import { InvitationData, InvitationDataV2, InvitationPair } from './network'
import { InvitationData } from './network'

export interface Community {
id: string
Expand All @@ -13,7 +13,7 @@ export interface Community {
onionAddress?: string
ownerCertificate?: string
psk?: string
inviteData?: InvitationDataV2
inviteData?: InvitationData | null
ownerOrbitDbIdentity?: string
}

Expand All @@ -25,18 +25,9 @@ export enum CommunityOwnership {
export interface CreateNetworkPayload {
ownership: CommunityOwnership
name?: string
// peers?: InvitationPair[]
// psk?: string
// ownerOrbitDbIdentity?: string
inviteData?: InvitationData
}

export interface ServerInvitationData {
serverAddress: string
cid: string
token?: string
}

export interface NetworkInfo {
hiddenService: HiddenService
peerId: PeerId
Expand Down Expand Up @@ -64,7 +55,7 @@ export interface InitCommunityPayload {
psk?: string
ownerOrbitDbIdentity?: string
ownerCsr?: UserCsr
inviteData?: ServerInvitationData
inviteData?: InvitationData | null
}

export interface StorePeerListPayload {
Expand Down

0 comments on commit 3961b17

Please sign in to comment.