Skip to content

Commit

Permalink
featrue: basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Nov 14, 2023
1 parent 27e7916 commit 6b081b4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand 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),
])
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const publicChannelsSlice = createSlice({
createChannel: (state, _action: PayloadAction<CreateChannelPayload>) => state,
deleteChannel: (state, _action: PayloadAction<DeleteChannelPayload>) => state,
completeChannelDeletion: (state, _action) => state,
sendUnregisteredInfoMessage: state => state,
channelDeletionResponse: (state, _action: PayloadAction<ChannelDeletionResponsePayload>) => state,
deleteChannelFromStore: (state, action: PayloadAction<DeleteChannelFromStorePayload>) => {
const { channelId } = action.payload
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)`

0 comments on commit 6b081b4

Please sign in to comment.