Skip to content

Commit

Permalink
refactor: Remove SET_COMMUNITY_METADATA event (#2408)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Leblow authored Apr 10, 2024
1 parent c089c68 commit 7855f00
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 179 deletions.
25 changes: 16 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
[unreleased]

* Refactored package.json to have consistent license "GPL-3.0-or-later"

# Refactorings:
# New features:

* Use ack for CREATE_NETWORK and simplify
# Refactorings:

# Fixes
# Fixes:

* Allow JPEG and GIF files as profile photos ([#2332](https://github.com/TryQuiet/quiet/issues/2332))
* Fixes issues with recreating general channel when deleted while offline ([#2334](https://github.com/TryQuiet/quiet/issues/2334))
[2.2.0]

# New features
# New features:

* Add utilities for emoji detection in messages and make all-emoji message larger font size ([#519](https://github.com/TryQuiet/quiet/issues/519))

# Refactorings:

* Use ack for CREATE_NETWORK and simplify
* Move Community model to the backend

# Fixes:

* Allow JPEG and GIF files as profile photos ([#2332](https://github.com/TryQuiet/quiet/issues/2332))
* Fix issues with recreating general channel when deleted while offline ([#2334](https://github.com/TryQuiet/quiet/issues/2334))
* Fix package.json license inconsistency

[2.1.2]

# Refactorings:
Expand Down Expand Up @@ -274,4 +282,3 @@
* C4 for Quiet architecture. Context and Container diagrams.

* Invite tab as default in settings

Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI

const localAddress = createLibp2pAddress(payload.hiddenService.onionAddress, payload.peerId.id)

const community = {
let community: Community = {
id: payload.id,
name: payload.name,
CA: payload.CA,
Expand All @@ -371,6 +371,22 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
await this.localDbService.setNetworkInfo(network)

await this.launchCommunity({ community, network })

const meta = await this.storageService.updateCommunityMetadata({
id: community.id,
rootCa: community.rootCa as string,
ownerCertificate: community.ownerCertificate as string,
})
const currentCommunity = await this.localDbService.getCurrentCommunity()

if (meta && currentCommunity) {
community = {
...currentCommunity,
ownerOrbitDbIdentity: meta.ownerOrbitDbIdentity,
}
await this.localDbService.setCommunity(community)
}

this.logger(`Created and launched community ${community.id}`)

return community
Expand Down Expand Up @@ -535,7 +551,15 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
// service for now. Both object construction and object
// initialization need to happen in order based on dependencies.
await this.registrationService.init(this.storageService)
this.logger('storage initialized')

if (community.CA) {
this.registrationService.setPermsData({
certificate: community.CA.rootCertString,
privKey: community.CA.rootKeyString,
})
}

this.logger('Storage initialized')

this.serverIoProvider.io.emit(
SocketActionTypes.CONNECTION_PROCESS_INFO,
Expand All @@ -559,7 +583,6 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
this.socketService.on(SocketActionTypes.CONNECTION, async () => {
// Update Frontend with Initialized Communities
if (this.communityId) {
console.log('Hunting for heisenbug: Backend initialized community and sent event to state manager')
this.serverIoProvider.io.emit(SocketActionTypes.COMMUNITY_LAUNCHED, { id: this.communityId })
console.log('this.libp2pService.connectedPeers', this.libp2pService.connectedPeers)
console.log('this.libp2pservice', this.libp2pService)
Expand Down Expand Up @@ -595,26 +618,6 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
callback(await this.joinCommunity(args))
}
)
// TODO: With the Community model on the backend, there is no need to call
// SET_COMMUNITY_METADATA anymore. We can call updateCommunityMetadata when
// creating the community.
this.socketService.on(
SocketActionTypes.SET_COMMUNITY_METADATA,
async (payload: CommunityMetadata, callback: (response: CommunityMetadata | undefined) => void) => {
const meta = await this.storageService.updateCommunityMetadata(payload)
const community = await this.localDbService.getCurrentCommunity()

if (meta && community) {
const updatedCommunity = {
...community,
ownerOrbitDbIdentity: meta.ownerOrbitDbIdentity,
}
await this.localDbService.setCommunity(updatedCommunity)
this.serverIoProvider.io.emit(SocketActionTypes.COMMUNITY_UPDATED, updatedCommunity)
}
callback(meta)
}
)
this.socketService.on(SocketActionTypes.LEAVE_COMMUNITY, async () => {
await this.leaveCommunity()
})
Expand All @@ -624,13 +627,6 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
this.logger(`socketService - ${SocketActionTypes.ADD_CSR}`)
await this.storageService?.saveCSR(payload)
})
// TODO: With the Community model on the backend, there is no need to call
// SET_COMMUNITY_CA_DATA anymore. We can call setPermsData when
// creating the community.
this.socketService.on(SocketActionTypes.SET_COMMUNITY_CA_DATA, async (payload: PermsData) => {
this.logger(`socketService - ${SocketActionTypes.SET_COMMUNITY_CA_DATA}`)
this.registrationService.setPermsData(payload)
})

// Public Channels
this.socketService.on(
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/nest/socket/socket.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ describe('SocketService', () => {
SocketActionTypes.LAUNCH_COMMUNITY.valueOf(),
SocketActionTypes.REGISTER_USER_CERTIFICATE.valueOf(),
SocketActionTypes.ADD_CSR.valueOf(),
SocketActionTypes.SET_COMMUNITY_METADATA.valueOf(),
]

fragile.forEach(event => {
Expand Down
11 changes: 0 additions & 11 deletions packages/backend/src/nest/socket/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,6 @@ export class SocketService extends EventEmitter implements OnModuleInit {
this.emit(SocketActionTypes.LIBP2P_PSK_STORED, payload)
})

socket.on(
SocketActionTypes.SET_COMMUNITY_METADATA,
(payload: CommunityMetadata, callback: (response: CommunityMetadata | undefined) => void) => {
this.emit(SocketActionTypes.SET_COMMUNITY_METADATA, payload, callback)
}
)

socket.on(SocketActionTypes.SET_COMMUNITY_CA_DATA, (payload: PermsData) => {
this.emit(SocketActionTypes.SET_COMMUNITY_CA_DATA, payload)
})

// ====== Users ======

socket.on(SocketActionTypes.SET_USER_PROFILE, (profile: UserProfile) => {
Expand Down
12 changes: 4 additions & 8 deletions packages/desktop/src/rtl-tests/community.create.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ import {
type NetworkInfo,
SavedOwnerCertificatePayload,
SocketActionTypes,
type ChannelsReplicatedPayload,
type RegisterOwnerCertificatePayload,
type ResponseLaunchCommunityPayload,
} from '@quiet/types'
import {
ChannelsReplicatedPayload,
publicChannels,
RegisterOwnerCertificatePayload,
ResponseLaunchCommunityPayload,
} from '@quiet/state-manager'
import { publicChannels } from '@quiet/state-manager'
import Channel from '../renderer/components/Channel/Channel'
import LoadingPanel from '../renderer/components/LoadingPanel/LoadingPanel'
import { AnyAction } from 'redux'
Expand Down Expand Up @@ -167,7 +165,6 @@ describe('User', () => {
"Modals/openModal",
"Identity/registerCertificate",
"Communities/createCommunity",
"Communities/sendCommunityCaData",
"Files/checkForMissingFiles",
"Network/addInitializedCommunity",
"Communities/clearInvitationCodes",
Expand All @@ -176,7 +173,6 @@ describe('User', () => {
"PublicChannels/addChannel",
"Identity/storeUserCertificate",
"Messages/addPublicChannelsMessagesBase",
"Communities/sendCommunityMetadata",
"PublicChannels/createGeneralChannel",
"PublicChannels/createChannel",
"Identity/saveUserCsr",
Expand Down
1 change: 0 additions & 1 deletion packages/desktop/src/rtl-tests/community.join.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ describe('User', () => {
"Modals/openModal",
"Identity/registerCertificate",
"Communities/launchCommunity",
"Communities/sendCommunityCaData",
"Files/checkForMissingFiles",
"Network/addInitializedCommunity",
"Communities/clearInvitationCodes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import { connectionActions } from '../appConnection/connection.slice'
import { createCommunitySaga } from './createCommunity/createCommunity.saga'
import { initCommunities, launchCommunitySaga } from './launchCommunity/launchCommunity.saga'
import { createNetworkSaga } from './createNetwork/createNetwork.saga'
import { sendCommunityMetadataSaga } from './updateCommunityMetadata/updateCommunityMetadata.saga'
import { sendCommunityCaDataSaga } from './sendCommunityCaData/sendCommunityCaData.saga'

export function* communitiesMasterSaga(socket: Socket): Generator {
yield all([
takeEvery(communitiesActions.createNetwork.type, createNetworkSaga, socket),
takeEvery(connectionActions.torBootstrapped.type, initCommunities),
takeEvery(communitiesActions.createCommunity.type, createCommunitySaga, socket),
takeEvery(communitiesActions.launchCommunity.type, launchCommunitySaga, socket),
takeEvery(communitiesActions.sendCommunityMetadata.type, sendCommunityMetadataSaga, socket),
takeEvery(communitiesActions.sendCommunityCaData.type, sendCommunityCaDataSaga, socket),
])
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export const communitiesSlice = createSlice({
},
})
},
sendCommunityCaData: state => state,
sendCommunityMetadata: state => state,
createNetwork: (state, _action: PayloadAction<CreateNetworkPayload>) => state,
resetApp: (state, _action) => state,
createCommunity: (state, _action: PayloadAction<string>) => state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export function* createCommunitySaga(
})
)

// 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
Expand Down

This file was deleted.

This file was deleted.

23 changes: 0 additions & 23 deletions packages/state-manager/src/sagas/identity/identity.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,6 @@ export interface RegisterUserCertificatePayload {
serviceAddress: string
}

export interface PermsData {
certificate: string
privKey: string
}

export interface RegisterOwnerCertificatePayload {
communityId: string
userCsr: UserCsr
permsData: PermsData
}

export interface SaveCertificatePayload {
certificate: string
rootPermsData: PermsData
}

export interface SaveOwnerCertificatePayload {
id: string
peerId: string
certificate: string
permsData: PermsData
}

export interface StoreUserCertificatePayload {
userCertificate: string
communityId: string
Expand Down
1 change: 0 additions & 1 deletion packages/state-manager/src/sagas/network/network.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const networkSlice = createSlice({
name: StoreKeys.Network,
reducers: {
addInitializedCommunity: (state, action: PayloadAction<CommunityId>) => {
console.log('Hunting for heisenbug: adding initialized community ', action.payload)
state.initializedCommunities = {
...state.initializedCommunities,
[action.payload]: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export function subscribe(socket: Socket) {
| ReturnType<typeof communitiesActions.clearInvitationCodes>
| ReturnType<typeof identityActions.saveUserCsr>
| ReturnType<typeof connectionActions.setTorInitialized>
| ReturnType<typeof communitiesActions.sendCommunityMetadata>
| ReturnType<typeof communitiesActions.sendCommunityCaData>
| ReturnType<typeof usersActions.setUserProfiles>
| ReturnType<typeof appActions.loadMigrationData>
>(emit => {
Expand Down Expand Up @@ -140,10 +138,6 @@ export function subscribe(socket: Socket) {
// Community

socket.on(SocketActionTypes.COMMUNITY_LAUNCHED, (payload: ResponseLaunchCommunityPayload) => {
console.log('Hunting for heisenbug: Community event received in state-manager')
// TODO: We can send this once when creating the community and
// store it in the backend.
emit(communitiesActions.sendCommunityCaData())
emit(filesActions.checkForMissingFiles(payload.id))
emit(networkActions.addInitializedCommunity(payload.id))
emit(communitiesActions.clearInvitationCodes())
Expand Down
5 changes: 0 additions & 5 deletions packages/state-manager/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ export interface EmitEvents {
[SocketActionTypes.LEAVE_COMMUNITY]: () => void
[SocketActionTypes.CREATE_NETWORK]: EmitEvent<string, (response: NetworkInfo | undefined) => void>
[SocketActionTypes.ADD_CSR]: EmitEvent<SaveCSRPayload>
[SocketActionTypes.SET_COMMUNITY_METADATA]: EmitEvent<
CommunityMetadata,
(response: CommunityMetadata | undefined) => void
>
[SocketActionTypes.SET_COMMUNITY_CA_DATA]: EmitEvent<PermsData>
[SocketActionTypes.SET_USER_PROFILE]: EmitEvent<UserProfile>
[SocketActionTypes.LOAD_MIGRATION_DATA]: EmitEvent<Record<string, any>>
}
Expand Down
2 changes: 0 additions & 2 deletions packages/types/src/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export enum SocketActionTypes {
CREATE_COMMUNITY = 'createCommunity',
LAUNCH_COMMUNITY = 'launchCommunity',
LEAVE_COMMUNITY = 'leaveCommunity',
SET_COMMUNITY_CA_DATA = 'setCommunityCaData',
SET_COMMUNITY_METADATA = 'setCommunityMetadata',

// ====== Channels ======

Expand Down

0 comments on commit 7855f00

Please sign in to comment.