From 7855f009e0541f5086d5b1b9ae84f9eceb285ef5 Mon Sep 17 00:00:00 2001 From: Lucas Leblow Date: Tue, 9 Apr 2024 20:06:44 -0700 Subject: [PATCH] refactor: Remove SET_COMMUNITY_METADATA event (#2408) --- CHANGELOG.md | 25 ++++++--- .../connections-manager.service.ts | 56 +++++++++---------- .../src/nest/socket/socket.service.spec.ts | 1 - .../backend/src/nest/socket/socket.service.ts | 11 ---- .../src/rtl-tests/community.create.test.tsx | 12 ++-- .../src/rtl-tests/community.join.test.tsx | 1 - .../communities/communities.master.saga.ts | 4 -- .../sagas/communities/communities.slice.ts | 2 - .../createCommunity/createCommunity.saga.ts | 3 - .../sendCommunityCaData.saga.ts | 30 ---------- .../updateCommunityMetadata.saga.ts | 43 -------------- .../src/sagas/identity/identity.types.ts | 23 -------- .../src/sagas/network/network.slice.ts | 1 - .../startConnection/startConnection.saga.ts | 6 -- packages/state-manager/src/types.ts | 5 -- packages/types/src/socket.ts | 2 - 16 files changed, 46 insertions(+), 179 deletions(-) delete mode 100644 packages/state-manager/src/sagas/communities/sendCommunityCaData/sendCommunityCaData.saga.ts delete mode 100644 packages/state-manager/src/sagas/communities/updateCommunityMetadata/updateCommunityMetadata.saga.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 59c0741d0f..e5ad80e5c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: @@ -274,4 +282,3 @@ * C4 for Quiet architecture. Context and Container diagrams. * Invite tab as default in settings - diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.ts index b3b29e226e..07353b6fa0 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.ts @@ -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, @@ -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 @@ -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, @@ -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) @@ -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() }) @@ -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( diff --git a/packages/backend/src/nest/socket/socket.service.spec.ts b/packages/backend/src/nest/socket/socket.service.spec.ts index 56d30c1275..58fe9f5d82 100644 --- a/packages/backend/src/nest/socket/socket.service.spec.ts +++ b/packages/backend/src/nest/socket/socket.service.spec.ts @@ -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 => { diff --git a/packages/backend/src/nest/socket/socket.service.ts b/packages/backend/src/nest/socket/socket.service.ts index 32d99659fd..d126eb3be1 100644 --- a/packages/backend/src/nest/socket/socket.service.ts +++ b/packages/backend/src/nest/socket/socket.service.ts @@ -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) => { diff --git a/packages/desktop/src/rtl-tests/community.create.test.tsx b/packages/desktop/src/rtl-tests/community.create.test.tsx index 44653b7730..446409f0e2 100644 --- a/packages/desktop/src/rtl-tests/community.create.test.tsx +++ b/packages/desktop/src/rtl-tests/community.create.test.tsx @@ -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' @@ -167,7 +165,6 @@ describe('User', () => { "Modals/openModal", "Identity/registerCertificate", "Communities/createCommunity", - "Communities/sendCommunityCaData", "Files/checkForMissingFiles", "Network/addInitializedCommunity", "Communities/clearInvitationCodes", @@ -176,7 +173,6 @@ describe('User', () => { "PublicChannels/addChannel", "Identity/storeUserCertificate", "Messages/addPublicChannelsMessagesBase", - "Communities/sendCommunityMetadata", "PublicChannels/createGeneralChannel", "PublicChannels/createChannel", "Identity/saveUserCsr", diff --git a/packages/desktop/src/rtl-tests/community.join.test.tsx b/packages/desktop/src/rtl-tests/community.join.test.tsx index 26a5c6ea57..0d6f4c1af9 100644 --- a/packages/desktop/src/rtl-tests/community.join.test.tsx +++ b/packages/desktop/src/rtl-tests/community.join.test.tsx @@ -181,7 +181,6 @@ describe('User', () => { "Modals/openModal", "Identity/registerCertificate", "Communities/launchCommunity", - "Communities/sendCommunityCaData", "Files/checkForMissingFiles", "Network/addInitializedCommunity", "Communities/clearInvitationCodes", diff --git a/packages/state-manager/src/sagas/communities/communities.master.saga.ts b/packages/state-manager/src/sagas/communities/communities.master.saga.ts index 599e9eeee1..c5e1e1a275 100644 --- a/packages/state-manager/src/sagas/communities/communities.master.saga.ts +++ b/packages/state-manager/src/sagas/communities/communities.master.saga.ts @@ -5,8 +5,6 @@ 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([ @@ -14,7 +12,5 @@ export function* communitiesMasterSaga(socket: Socket): Generator { 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), ]) } diff --git a/packages/state-manager/src/sagas/communities/communities.slice.ts b/packages/state-manager/src/sagas/communities/communities.slice.ts index c8b49e072b..dae53ca209 100644 --- a/packages/state-manager/src/sagas/communities/communities.slice.ts +++ b/packages/state-manager/src/sagas/communities/communities.slice.ts @@ -35,8 +35,6 @@ export const communitiesSlice = createSlice({ }, }) }, - sendCommunityCaData: state => state, - sendCommunityMetadata: state => state, createNetwork: (state, _action: PayloadAction) => state, resetApp: (state, _action) => state, createCommunity: (state, _action: PayloadAction) => state, diff --git a/packages/state-manager/src/sagas/communities/createCommunity/createCommunity.saga.ts b/packages/state-manager/src/sagas/communities/createCommunity/createCommunity.saga.ts index 2c7768a47c..ebed5ee240 100644 --- a/packages/state-manager/src/sagas/communities/createCommunity/createCommunity.saga.ts +++ b/packages/state-manager/src/sagas/communities/createCommunity/createCommunity.saga.ts @@ -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 diff --git a/packages/state-manager/src/sagas/communities/sendCommunityCaData/sendCommunityCaData.saga.ts b/packages/state-manager/src/sagas/communities/sendCommunityCaData/sendCommunityCaData.saga.ts deleted file mode 100644 index c0810903f3..0000000000 --- a/packages/state-manager/src/sagas/communities/sendCommunityCaData/sendCommunityCaData.saga.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { apply, select } from 'typed-redux-saga' -import { type PayloadAction } from '@reduxjs/toolkit' - -import { applyEmitParams, type Socket } from '../../../types' -import { communitiesSelectors } from '../communities.selectors' -import { type communitiesActions } from '../communities.slice' -import { type PermsData, SocketActionTypes } from '@quiet/types' - -export function* sendCommunityCaDataSaga( - socket: Socket, - _action: PayloadAction['payload']> -): Generator { - const community = yield* select(communitiesSelectors.currentCommunity) - - if (!community) { - console.error('Cannot send community metadata, no community') - return - } - - if (!community.CA) { - console.log('Cannot send community metadata, no CA in community') - return - } - - const payload: PermsData = { - certificate: community.CA.rootCertString, - privKey: community.CA.rootKeyString, - } - yield* apply(socket, socket.emit, applyEmitParams(SocketActionTypes.SET_COMMUNITY_CA_DATA, payload)) -} diff --git a/packages/state-manager/src/sagas/communities/updateCommunityMetadata/updateCommunityMetadata.saga.ts b/packages/state-manager/src/sagas/communities/updateCommunityMetadata/updateCommunityMetadata.saga.ts deleted file mode 100644 index b3efe67cde..0000000000 --- a/packages/state-manager/src/sagas/communities/updateCommunityMetadata/updateCommunityMetadata.saga.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { CommunityMetadata, SocketActionTypes } from '@quiet/types' -import { type PayloadAction } from '@reduxjs/toolkit' -import { apply, select, put, take } from 'typed-redux-saga' -import { channel } from 'redux-saga' -import { applyEmitParams, type Socket } from '../../../types' -import { communitiesSelectors } from '../communities.selectors' -import { communitiesActions } from '../communities.slice' -import { identitySelectors } from '../../identity/identity.selectors' - -export function* sendCommunityMetadataSaga( - socket: Socket, - _action: PayloadAction['payload']> -): Generator { - const identity = yield* select(identitySelectors.currentIdentity) - const community = yield* select(communitiesSelectors.currentCommunity) - - if (!identity?.userCertificate) { - console.error('Cannot send community metadata, no owner certificate') - return - } - - if (!community) { - console.error('Cannot send community metadata, no community') - return - } - - if (!community.rootCa || !community.CA) { - console.log('Cannot send community metadata, no rootCa or CA in community') - return - } - - const communityMetadataPayload: CommunityMetadata = { - id: community.id, - ownerCertificate: identity.userCertificate, - rootCa: community.rootCa, - } - - yield* apply( - socket, - socket.emitWithAck, - applyEmitParams(SocketActionTypes.SET_COMMUNITY_METADATA, communityMetadataPayload) - ) -} diff --git a/packages/state-manager/src/sagas/identity/identity.types.ts b/packages/state-manager/src/sagas/identity/identity.types.ts index 31420aa396..74819b8aee 100644 --- a/packages/state-manager/src/sagas/identity/identity.types.ts +++ b/packages/state-manager/src/sagas/identity/identity.types.ts @@ -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 diff --git a/packages/state-manager/src/sagas/network/network.slice.ts b/packages/state-manager/src/sagas/network/network.slice.ts index 7a491e4037..ace82febd3 100644 --- a/packages/state-manager/src/sagas/network/network.slice.ts +++ b/packages/state-manager/src/sagas/network/network.slice.ts @@ -14,7 +14,6 @@ export const networkSlice = createSlice({ name: StoreKeys.Network, reducers: { addInitializedCommunity: (state, action: PayloadAction) => { - console.log('Hunting for heisenbug: adding initialized community ', action.payload) state.initializedCommunities = { ...state.initializedCommunities, [action.payload]: true, diff --git a/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts b/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts index b900613ae6..9c908f13ee 100644 --- a/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts +++ b/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts @@ -84,8 +84,6 @@ export function subscribe(socket: Socket) { | ReturnType | ReturnType | ReturnType - | ReturnType - | ReturnType | ReturnType | ReturnType >(emit => { @@ -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()) diff --git a/packages/state-manager/src/types.ts b/packages/state-manager/src/types.ts index f0d3ba0499..44260530d5 100644 --- a/packages/state-manager/src/types.ts +++ b/packages/state-manager/src/types.ts @@ -50,11 +50,6 @@ export interface EmitEvents { [SocketActionTypes.LEAVE_COMMUNITY]: () => void [SocketActionTypes.CREATE_NETWORK]: EmitEvent void> [SocketActionTypes.ADD_CSR]: EmitEvent - [SocketActionTypes.SET_COMMUNITY_METADATA]: EmitEvent< - CommunityMetadata, - (response: CommunityMetadata | undefined) => void - > - [SocketActionTypes.SET_COMMUNITY_CA_DATA]: EmitEvent [SocketActionTypes.SET_USER_PROFILE]: EmitEvent [SocketActionTypes.LOAD_MIGRATION_DATA]: EmitEvent> } diff --git a/packages/types/src/socket.ts b/packages/types/src/socket.ts index 45495c829a..573fb1a313 100644 --- a/packages/types/src/socket.ts +++ b/packages/types/src/socket.ts @@ -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 ======