Skip to content

Commit

Permalink
first changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Oct 3, 2023
1 parent 99fbe03 commit ee6d53d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 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,13 @@ export function* saveCommunityMetadataSaga(
ownerCertificate: action.payload.ownerCertificate,
})
)

const community = yield* select(communitiesSelectors.currentCommunity)
if (!community) return
const isOwner = community.CA
console.log({ isOwner })
if (!isOwner) {
console.log('why not run')
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,42 @@
import { type PayloadAction } from '@reduxjs/toolkit'
import { put, select, call } from 'typed-redux-saga'
import { messagesActions } from '../../messages/messages.slice'
import { generalChannel, publicChannelsSelectors } from '../publicChannels.selectors'
import { publicChannelsActions } from '../publicChannels.slice'
import { WriteMessagePayload, MessageType } from '@quiet/types'
import { communitiesSelectors } from '../../communities/communities.selectors'
import { identitySelectors } from '../../identity/identity.selectors'
import { usersSelectors } from '../../users/users.selectors'

export function* sendUnregisteredInfoMessage(): Generator {
// action: PayloadAction<ReturnType<typeof publicChannelsActions.sendUnregisteredInfoMessage>['payload']>
// const { username } = action.payload

const community = yield* select(communitiesSelectors.currentCommunity)
const identity = yield* select(identitySelectors.currentIdentity)

console.log({ community, identity })
if (!community?.name || !identity) return

const nickname = identity.nickname
const communityName = community.name

const generalChannel = yield* select(publicChannelsSelectors.generalChannel)
console.log({ generalChannel })
if (!generalChannel) return

const ownerData = yield* select(usersSelectors.ownerData)
const ownerNickname = ownerData.username

const message = `@${nickname} has joined ${communityName}! 🎉
Note: @${nickname} is not yet registered, so they'll have the "unregistered" badge until the community creator (@${ownerNickname}) registers them, which will happen automatically when @${ownerNickname} next appears online. [Learn more]`

const payload: WriteMessagePayload = {
type: MessageType.Info,
message,
channelId: generalChannel.id,
}
console.log('endddd')
yield* put(messagesActions.sendMessage(payload))
}

0 comments on commit ee6d53d

Please sign in to comment.