From 6b081b4ea5b9661a8cbfe47ba37c1c4e013da53c Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 14 Nov 2023 09:54:42 +0100 Subject: [PATCH] featrue: basic functionality --- .../saveCommunityMetadata.saga.ts | 9 +++++++ .../publicChannels.master.saga.ts | 2 ++ .../publicChannels/publicChannels.slice.ts | 1 + .../sendUnregisteredInfoMessage.saga.ts | 24 +++++++++++++++++++ .../startConnection/startConnection.saga.ts | 10 ++++---- packages/types/src/message.ts | 3 +++ 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 packages/state-manager/src/sagas/publicChannels/sendUnregisteredInfoMessage/sendUnregisteredInfoMessage.saga.ts diff --git a/packages/state-manager/src/sagas/communities/saveCommunityMetadata/saveCommunityMetadata.saga.ts b/packages/state-manager/src/sagas/communities/saveCommunityMetadata/saveCommunityMetadata.saga.ts index 630b270bc0..d30541e0a4 100644 --- a/packages/state-manager/src/sagas/communities/saveCommunityMetadata/saveCommunityMetadata.saga.ts +++ b/packages/state-manager/src/sagas/communities/saveCommunityMetadata/saveCommunityMetadata.saga.ts @@ -1,6 +1,7 @@ import { type PayloadAction } from '@reduxjs/toolkit' import { put, select } from 'typed-redux-saga' import { type Socket } from '../../../types' +import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { communitiesSelectors } from '../communities.selectors' import { communitiesActions } from '../communities.slice' @@ -22,4 +23,12 @@ export function* saveCommunityMetadataSaga( ownerCertificate: action.payload.ownerCertificate, }) ) + + const community = yield* select(communitiesSelectors.currentCommunity) + if (!community) return + const isOwner = community.CA + + if (!isOwner) { + yield* put(publicChannelsActions.sendUnregisteredInfoMessage()) + } } diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.master.saga.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.master.saga.ts index 30d8e32aeb..9bb506d4b7 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.master.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.master.saga.ts @@ -9,6 +9,7 @@ import { sendNewUserInfoMessageSaga } from './sendNewUserInfoMessage/sendNewUser import { clearUnreadChannelsSaga } from './markUnreadChannels/markUnreadChannels.saga' import { channelsReplicatedSaga } from './channelsReplicated/channelsReplicated.saga' import { channelDeletionResponseSaga } from './channelDeletionResponse/channelDeletionResponse.saga' +import { sendUnregisteredInfoMessage } from './sendUnregisteredInfoMessage/sendUnregisteredInfoMessage.saga' export function* publicChannelsMasterSaga(socket: Socket): Generator { yield all([ @@ -20,5 +21,6 @@ export function* publicChannelsMasterSaga(socket: Socket): Generator { takeEvery(publicChannelsActions.channelsReplicated.type, channelsReplicatedSaga), takeEvery(publicChannelsActions.setCurrentChannel.type, clearUnreadChannelsSaga), takeEvery(publicChannelsActions.sendNewUserInfoMessage.type, sendNewUserInfoMessageSaga), + takeEvery(publicChannelsActions.sendUnregisteredInfoMessage.type, sendUnregisteredInfoMessage), ]) } diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index 07c0fd34aa..9b1d9ccbeb 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -53,6 +53,7 @@ export const publicChannelsSlice = createSlice({ createChannel: (state, _action: PayloadAction) => state, deleteChannel: (state, _action: PayloadAction) => state, completeChannelDeletion: (state, _action) => state, + sendUnregisteredInfoMessage: state => state, channelDeletionResponse: (state, _action: PayloadAction) => state, deleteChannelFromStore: (state, action: PayloadAction) => { const { channelId } = action.payload diff --git a/packages/state-manager/src/sagas/publicChannels/sendUnregisteredInfoMessage/sendUnregisteredInfoMessage.saga.ts b/packages/state-manager/src/sagas/publicChannels/sendUnregisteredInfoMessage/sendUnregisteredInfoMessage.saga.ts new file mode 100644 index 0000000000..4c68cef933 --- /dev/null +++ b/packages/state-manager/src/sagas/publicChannels/sendUnregisteredInfoMessage/sendUnregisteredInfoMessage.saga.ts @@ -0,0 +1,24 @@ +import { put, select } from 'typed-redux-saga' +import { messagesActions } from '../../messages/messages.slice' +import { publicChannelsSelectors } from '../publicChannels.selectors' +import { WriteMessagePayload, MessageType, userJoinedMessage } from '@quiet/types' +import { communitiesSelectors } from '../../communities/communities.selectors' +import { identitySelectors } from '../../identity/identity.selectors' + +export function* sendUnregisteredInfoMessage(): Generator { + const community = yield* select(communitiesSelectors.currentCommunity) + const identity = yield* select(identitySelectors.currentIdentity) + const generalChannel = yield* select(publicChannelsSelectors.generalChannel) + + if (!community?.name || !identity || !generalChannel) return + + const message = userJoinedMessage(identity.nickname) + + const payload: WriteMessagePayload = { + type: MessageType.Info, + message, + channelId: generalChannel.id, + } + + yield* put(messagesActions.sendMessage(payload)) +} 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 1bcef1e1da..84e2f43ae0 100644 --- a/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts +++ b/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts @@ -201,11 +201,11 @@ export function subscribe(socket: Socket) { emit(usersActions.storeCsrs(payload)) }) socket.on(SocketActionTypes.RESPONSE_GET_CERTIFICATES, (payload: SendCertificatesResponse) => { - emit( - publicChannelsActions.sendNewUserInfoMessage({ - certificates: payload.certificates, - }) - ) + // emit( + // publicChannelsActions.sendNewUserInfoMessage({ + // certificates: payload.certificates, + // }) + // ) emit(usersActions.responseSendCertificates(payload)) }) socket.on(SocketActionTypes.SEND_USER_CERTIFICATE, (payload: SendOwnerCertificatePayload) => { diff --git a/packages/types/src/message.ts b/packages/types/src/message.ts index 19f0969194..f19ba1aa0c 100644 --- a/packages/types/src/message.ts +++ b/packages/types/src/message.ts @@ -100,3 +100,6 @@ export interface TestMessage { identity: Identity verifyAutomatically: boolean } + +export const userJoinedMessage = (username: string) => + `**@${username}** has joined and will be registered soon. 🎉 [Learn more](https://github.com/TryQuiet/quiet/wiki/Quiet-FAQ#how-does-username-registration-work)`