From 6cc6f1ef4db31a7df3ba4a20a980708fce75fcee Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Mon, 15 May 2023 09:47:19 +0200 Subject: [PATCH 01/35] initial change --- .../renderer/components/Channel/CreateChannel/CreateChannel.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx b/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx index 659533be25..247a72bb31 100644 --- a/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx +++ b/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx @@ -66,6 +66,7 @@ export const CreateChannel = () => { ) return } + // Move to state manager // Create channel const channel: PublicChannel = { name: name, From 7f848e5e06429186ff90b034be060ba2996a6dad Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Mon, 15 May 2023 14:54:49 +0200 Subject: [PATCH 02/35] use address as main id --- packages/common/src/channelAddress.ts | 4 +++ packages/common/src/index.ts | 1 + .../renderer/components/Channel/Channel.tsx | 5 ++-- .../components/Channel/ChannelComponent.tsx | 2 +- .../Channel/CreateChannel/CreateChannel.tsx | 3 ++- .../DeleteChannel/DeleteChannel.test.tsx | 2 +- .../Channel/DeleteChannel/DeleteChannel.tsx | 4 +-- .../DeleteChannel/DeleteChannelComponent.tsx | 6 ++--- .../ChannelsPanel/ChannelsListItem.tsx | 2 +- .../channels/ChannelInput/ChannelInput.tsx | 1 + .../sagas/notifications/notifications.saga.ts | 4 ++- .../DeleteChannel/DeleteChannel.screen.tsx | 4 +-- .../autoDownloadFiles.saga.test.ts | 3 ++- .../broadcastHostedFile.saga.test.ts | 3 ++- .../updateMessageMedia.test.ts | 3 ++- .../files/uploadFile/uploadFile.saga.test.ts | 3 ++- .../incomingMessages.saga.test.ts | 5 ++-- .../sendDeletionMessage.saga.test.ts | 3 ++- .../sendDeletionMessage.saga.ts | 9 ++++--- .../sendMessage/sendMessage.saga.test.ts | 3 ++- .../channelDeletionResponse.saga.test.ts | 11 ++++---- .../channelDeletionResponse.saga.ts | 10 ++++--- .../channelsReplicated.saga.test.ts | 5 ++-- .../channelsReplicated.saga.ts | 3 ++- .../createChannel/createChannel.saga.test.ts | 3 ++- .../createGeneralChannel.saga.test.ts | 27 ++++++++++--------- .../createGeneralChannel.saga.ts | 8 ++++-- .../sendInitialChannelMessage.saga.test.ts | 3 ++- .../sendInitialChannelMessage.saga.ts | 4 ++- .../deleteChannel/deleteChannel.saga.test.ts | 13 ++++----- .../deleteChannel/deleteChannel.saga.ts | 15 ++++++----- .../markUnreadChannels.saga.test.ts | 3 ++- .../publicChannels.selectors.test.ts | 3 ++- .../publicChannels.selectors.ts | 5 ++-- .../publicChannels/publicChannels.slice.ts | 1 + .../publicChannels/publicChannels.types.ts | 4 +-- .../updateNewestMessage.saga.test.ts | 3 ++- 37 files changed, 117 insertions(+), 74 deletions(-) create mode 100644 packages/common/src/channelAddress.ts diff --git a/packages/common/src/channelAddress.ts b/packages/common/src/channelAddress.ts new file mode 100644 index 0000000000..9f40994521 --- /dev/null +++ b/packages/common/src/channelAddress.ts @@ -0,0 +1,4 @@ +import crypto from 'crypto' + +export const generateChannelAddress = (channelName: String) => + `${channelName}_${crypto.randomBytes(16).toString('hex')}` diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index ca4a8ab172..e2bfdd4163 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -4,3 +4,4 @@ export * from './capitalize' export * from './process' export * from './helpers' export * from './sortPeers' +export * from './channelAddress' diff --git a/packages/desktop/src/renderer/components/Channel/Channel.tsx b/packages/desktop/src/renderer/components/Channel/Channel.tsx index 995fbb0087..aca96e59e3 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.tsx @@ -42,11 +42,11 @@ const Channel = () => { const currentChannelMessagesCount = useSelector( publicChannels.selectors.currentChannelMessagesCount ) - +console.log({currentChannelMessagesCount}) const currentChannelDisplayableMessages = useSelector( publicChannels.selectors.currentChannelMessagesMergedBySender ) - + console.log({currentChannelDisplayableMessages}) const newestCurrentChannelMessage = useSelector( publicChannels.selectors.newestCurrentChannelMessage ) @@ -59,6 +59,7 @@ const Channel = () => { const isCommunityInitialized = Boolean(initializedCommunities[community?.id]) const pendingGeneralChannelRecreationSelector = useSelector(publicChannels.selectors.pendingGeneralChannelRecreation) + // !! KACPER const pendingGeneralChannelRecreation = pendingGeneralChannelRecreationSelector && currentChannelAddress === 'general' && currentChannelMessagesCount === 0 let enableContextMenu: boolean = false diff --git a/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx b/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx index 392c0c146e..cfcc23ffcb 100644 --- a/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx +++ b/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx @@ -214,7 +214,7 @@ export const ChannelComponent: React.FC< useEffect(() => { scrollBottom() }, [channelAddress]) - +console.log(isCommunityInitialized, messages.count) return ( diff --git a/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx b/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx index 247a72bb31..c2c7defdb0 100644 --- a/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx +++ b/packages/desktop/src/renderer/components/Channel/CreateChannel/CreateChannel.tsx @@ -15,6 +15,7 @@ import { DateTime } from 'luxon' import { useModal } from '../../../containers/hooks' import { ModalName } from '../../../sagas/modals/modals.types' import { flushSync } from 'react-dom' +import { generateChannelAddress } from '@quiet/common' export const CreateChannel = () => { const dispatch = useDispatch() @@ -72,7 +73,7 @@ export const CreateChannel = () => { name: name, description: `Welcome to #${name}`, owner: user.nickname, - address: name, + address: generateChannelAddress(name), timestamp: DateTime.utc().valueOf() } flushSync(() => { diff --git a/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.test.tsx b/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.test.tsx index 637f0aa20d..63cb9d4884 100644 --- a/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.test.tsx +++ b/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.test.tsx @@ -6,7 +6,7 @@ describe('LeaveCommunity', () => { it('renders component', () => { const result = renderComponent( { const dispatch = useDispatch() const deleteChannel = useCallback(() => { - dispatch(publicChannels.actions.deleteChannel({ channel: channel.name })) + dispatch(publicChannels.actions.deleteChannel({ channelAddress: channel.address })) modal.handleClose() // Close self }, [modal]) - return + return } export default DeleteChannel diff --git a/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannelComponent.tsx b/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannelComponent.tsx index 82d00076e9..83d8046665 100644 --- a/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannelComponent.tsx +++ b/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannelComponent.tsx @@ -80,14 +80,14 @@ const StyledGrid = styled(Grid)(({ theme }) => ({ })) export interface DeleteChannelProps { - channel: string + channelName: string deleteChannel: () => void } export const DeleteChannelComponent: React.FC & DeleteChannelProps> = ({ open, handleClose, - channel, + channelName, deleteChannel }) => { return ( @@ -111,7 +111,7 @@ export const DeleteChannelComponent: React.FC & Dele justifyContent='center'> Delete{' '} - #{channel}? This cannot be undone. + #{channelName}? This cannot be undone. diff --git a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx index 491aad5af8..0793be2a51 100644 --- a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx @@ -99,7 +99,7 @@ export const ChannelsListItem: React.FC = ({ ref={ref} disableGutters onClick={() => { - setCurrentChannel(channel.name) + setCurrentChannel(channel.address) }} className={classNames(classes.root, { [classes.selected]: selected, diff --git a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx index 57ef63c000..aa16fdc2a7 100644 --- a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx +++ b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx @@ -235,6 +235,7 @@ export const ChannelInputComponent: React.FC = ({ handleClipboardFiles, handleOpenFiles }) => { + console.log({inputState}) const [_anchorEl, setAnchorEl] = React.useState(null) const [mentionsToSelect, setMentionsToSelect] = React.useState([]) const messageRef = React.useRef() diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts index 15ea297068..618d351e2e 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts @@ -34,8 +34,9 @@ export function* displayMessageNotificationSaga( action: PayloadAction['payload']> ): Generator { const incomingMessages = action.payload.messages - + console.log({ incomingMessages }) const currentChannel = yield* select(publicChannels.selectors.currentChannel) + console.log({ currentChannel }) const currentIdentity = yield* select(identity.selectors.currentIdentity) const certificatesMapping = yield* select(users.selectors.certificatesMapping) @@ -47,6 +48,7 @@ export function* displayMessageNotificationSaga( const notificationsSound = yield* select(settings.selectors.getNotificationsSound) for (const message of incomingMessages) { + console.log({ message }) const focused = yield* call(isWindowFocused) // Do not display notifications for active channel (when the app is in foreground) diff --git a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx index 0a8b6799ce..6637223b50 100644 --- a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx +++ b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx @@ -9,7 +9,7 @@ import { navigationSelectors } from '../../store/navigation/navigation.selectors export const DeleteChannelScreen: FC = ({ route }) => { const dispatch = useDispatch() - +// KACPER const { channel } = route.params const channels = useSelector(publicChannels.selectors.publicChannels) @@ -27,7 +27,7 @@ export const DeleteChannelScreen: FC = ({ route }) => const deleteChannel = useCallback(() => { dispatch( publicChannels.actions.deleteChannel({ - channel: channel + channelAddress: channel }) ) }, [dispatch]) diff --git a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts index 0b8a84e847..f833960afa 100644 --- a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts +++ b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts @@ -19,6 +19,7 @@ import { publicChannelsActions } from '../../publicChannels/publicChannels.slice import { DateTime } from 'luxon' import { FileMetadata } from '../files.types' import { AUTODOWNLOAD_SIZE_LIMIT } from '../../../constants' +import { generateChannelAddress } from '@quiet/common' describe('downloadFileSaga', () => { let store: Store @@ -53,7 +54,7 @@ describe('downloadFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: 'sailing' + address: generateChannelAddress('sailing') } } )).channel diff --git a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts index 2092204235..3f2672eea1 100644 --- a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts +++ b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts @@ -16,6 +16,7 @@ import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' import { FileMetadata } from '../files.types' +import { generateChannelAddress } from '@quiet/common' describe('downloadFileSaga', () => { let store: Store @@ -51,7 +52,7 @@ describe('downloadFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: 'sailing' + address: generateChannelAddress('sailing') } } ) diff --git a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts index 038ec42e37..7fea3bae44 100644 --- a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts +++ b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts @@ -14,6 +14,7 @@ import { updateMessageMediaSaga } from './updateMessageMedia' import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' +import { generateChannelAddress } from '@quiet/common' describe('downloadedFileSaga', () => { let store: Store @@ -49,7 +50,7 @@ describe('downloadedFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: 'sailing' + address: generateChannelAddress('sailing') } } ) diff --git a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts index 22f174ea9e..53414f664c 100644 --- a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts +++ b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts @@ -22,6 +22,7 @@ import { filesActions } from '../files.slice' import { generateMessageId } from '../../messages/utils/message.utils' import { DateTime } from 'luxon' import { messagesActions } from '../../messages/messages.slice' +import { generateChannelAddress } from '@quiet/common' describe('uploadFileSaga', () => { let store: Store @@ -58,7 +59,7 @@ describe('uploadFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: 'sailing' + address: generateChannelAddress('sailing') } } )).channel diff --git a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts index 47b7040a1d..f868e839c1 100644 --- a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts @@ -19,6 +19,7 @@ import { incomingMessagesSaga } from './incomingMessages.saga' import { messagesActions } from '../messages.slice' import { reducers } from '../../reducers' import { FileMetadata } from '../../files/files.types' +import { generateChannelAddress } from '@quiet/common' describe('incomingMessagesSaga', () => { let store: Store @@ -58,7 +59,7 @@ describe('incomingMessagesSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: 'sailing' + address: generateChannelAddress('sailing') } } ) @@ -73,7 +74,7 @@ describe('incomingMessagesSaga', () => { description: 'Welcome to #barbeque', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: 'barbeque' + address: generateChannelAddress('barbeque') } } ) diff --git a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts index 80f06f88db..485b3e0b6d 100644 --- a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts @@ -14,6 +14,7 @@ import { messagesActions } from '../../messages/messages.slice' import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { sendDeletionMessageSaga } from './sendDeletionMessage.saga' +import { generateChannelAddress } from '@quiet/common' describe('sendDeletionMessage', () => { let store: Store @@ -51,7 +52,7 @@ describe('sendDeletionMessage', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: 'photo' + address: generateChannelAddress('photo') } } ) diff --git a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts index 8cd4c19e9c..957e68a0e1 100644 --- a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts +++ b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts @@ -1,6 +1,7 @@ import { PayloadAction } from '@reduxjs/toolkit' import { put, select } from 'typed-redux-saga' import { communitiesSelectors } from '../../communities/communities.selectors' +import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' import { messagesActions } from '../messages.slice' import { WriteMessagePayload, MessageType } from '../messages.types' @@ -8,18 +9,20 @@ export function* sendDeletionMessageSaga( action: PayloadAction['payload']> ): Generator { const { channelAddress } = action.payload - const isGeneral = channelAddress === 'general' + const generalChannel = yield* select(publicChannelsSelectors.generalChannel) + + const isGeneral = channelAddress === generalChannel.address const ownerNickname = yield* select(communitiesSelectors.ownerNickname) const community = yield* select(communitiesSelectors.currentCommunity) const isOwner = Boolean(community?.CA) - +// KACPER const payload: WriteMessagePayload = { type: MessageType.Info, message: `@${ownerNickname} deleted #${channelAddress}`, - channelAddress: 'general' + channelAddress: generalChannel.address } if (isOwner && !isGeneral) { diff --git a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts index 2a824e53a8..57d9194f3a 100644 --- a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts @@ -25,6 +25,7 @@ import { currentChannelAddress } from '../../publicChannels/publicChannels.selec import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' +import { generateChannelAddress } from '@quiet/common' describe('sendMessageSaga', () => { let store: Store @@ -59,7 +60,7 @@ describe('sendMessageSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: 'sailing' + address: generateChannelAddress('sailing') } } )).channel diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts index 2d5f1a87f8..0e270b984f 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts @@ -14,6 +14,7 @@ import { DateTime } from 'luxon' import { publicChannelsSelectors } from '../publicChannels.selectors' import { messagesActions } from '../../messages/messages.slice' import { channelDeletionResponseSaga } from './channelDeletionResponse.saga' +import { generateChannelAddress } from '@quiet/common' describe('channelDeletionResponseSaga', () => { let store: Store @@ -51,7 +52,7 @@ describe('channelDeletionResponseSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: 'photo' + address: generateChannelAddress('photo') } } ) @@ -65,7 +66,7 @@ describe('channelDeletionResponseSaga', () => { await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channel: channelAddress + channelAddress }) ) .withReducer(reducer) @@ -84,7 +85,7 @@ describe('channelDeletionResponseSaga', () => { await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channel: channelAddress + channelAddress }) ) .withReducer(reducer) @@ -113,7 +114,7 @@ describe('channelDeletionResponseSaga', () => { await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channel: channelAddress + channelAddress }) ) .withReducer(reducer) @@ -131,7 +132,7 @@ describe('channelDeletionResponseSaga', () => { await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channel: channelAddress + channelAddress }) ) .withReducer(reducer) diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts index 9d5c21e3de..9ff5e35dce 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts @@ -4,16 +4,20 @@ import logger from '../../../utils/logger' import { put, delay, select } from 'typed-redux-saga' import { messagesActions } from '../../messages/messages.slice' import { communitiesSelectors } from '../../communities/communities.selectors' +import { publicChannelsSelectors } from '../publicChannels.selectors' const log = logger('publicChannels') export function* channelDeletionResponseSaga( action: PayloadAction['payload']> ): Generator { - log(`Deleted channel ${action.payload.channel} saga`) + log(`Deleted channel ${action.payload.channelAddress} saga`) - const channelAddress = action.payload.channel - const isGeneral = channelAddress === 'general' + const { channelAddress } = action.payload + + const generalChannel = yield* select(publicChannelsSelectors.generalChannel) + + const isGeneral = channelAddress === generalChannel.address if (isGeneral) { yield* put(publicChannelsActions.startGeneralRecreation()) diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts index b9c340ef67..2f806f4531 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts @@ -14,6 +14,7 @@ import { channelsReplicatedSaga } from './channelsReplicated.saga' import { DateTime } from 'luxon' import { publicChannelsSelectors } from '../publicChannels.selectors' import { messagesActions } from '../../messages/messages.slice' +import { generateChannelAddress } from '@quiet/common' describe('channelsReplicatedSaga', () => { let store: Store @@ -51,7 +52,7 @@ describe('channelsReplicatedSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: 'owner', - address: 'sailing' + address: generateChannelAddress('sailing') } }) ).payload.channel @@ -250,7 +251,7 @@ describe('channelsReplicatedSaga', () => { channel: sailingChannel }) ) - .put(publicChannelsActions.deleteChannel({ channel: photoChannel.address })) + .put(publicChannelsActions.deleteChannel({ channelAddress: photoChannel.address })) .run() }) }) diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts index 808ac63a4e..7368646606 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts @@ -21,6 +21,7 @@ export function* channelsReplicatedSaga( const databaseStoredChannelsAddresses = databaseStoredChannels.map(channel => channel.address) console.log({ locallyStoredChannels, databaseStoredChannelsAddresses }) // Upserting channels to local storage + // KACPER!!! for (const channel of databaseStoredChannels) { if (!locallyStoredChannels.includes(channel.address)) { log(`ADDING #${channel.name} TO LOCAL STORAGE`) @@ -42,7 +43,7 @@ export function* channelsReplicatedSaga( if (!databaseStoredChannelsAddresses.includes(channelAddress)) { console.log({ channelAddress }) log(`REMOVING #${channelAddress} FROM STORE`) - yield* put(publicChannelsActions.deleteChannel({ channel: channelAddress })) + yield* put(publicChannelsActions.deleteChannel({ channelAddress })) } } diff --git a/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts index 9258fb1c95..71af1d68b5 100644 --- a/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts @@ -23,6 +23,7 @@ import { FactoryGirl } from 'factory-girl' import { setupCrypto } from '@quiet/identity' import { prepareStore } from '../../../utils/tests/prepareStore' import { getFactory } from '../../../utils/tests/factories' +import { generateChannelAddress } from '@quiet/common' describe('createChannelSaga', () => { let store: Store @@ -41,7 +42,7 @@ describe('createChannelSaga', () => { description: 'desc', owner: 'Howdy', timestamp: Date.now(), - address: 'address' + address: generateChannelAddress('general') } test('ask for missing messages', async () => { diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts index 50c24a55b1..96c42c8c73 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts @@ -12,6 +12,7 @@ import { Identity } from '../../identity/identity.types' import { identityActions } from '../../identity/identity.slice' import { createGeneralChannelSaga, getChannelTimestamp } from './createGeneralChannel.saga' import { communitiesActions, Community } from '../../communities/communities.slice' +import { generateChannelAddress } from '@quiet/common' describe('createGeneralChannelSaga', () => { let store: Store @@ -27,7 +28,7 @@ describe('createGeneralChannelSaga', () => { factory = await getFactory(store) community = await factory.create< - ReturnType['payload'] + ReturnType['payload'] >('Community') alice = await factory.create['payload']>( @@ -38,26 +39,28 @@ describe('createGeneralChannelSaga', () => { test('create general channel', async () => { const reducer = combineReducers(reducers) + const generalAddress = generateChannelAddress('general') + const channel = { + name: 'general', + description: 'Welcome to #general', + owner: alice.nickname, + address: generalAddress, + timestamp: 0 + } + console.log({ channel }) await expectSaga(createGeneralChannelSaga) .withReducer(reducer) .withState(store.getState()) - .provide([ - [call.fn(getChannelTimestamp), 0] - ]) + .provide([[call.fn(getChannelTimestamp), 0]]) + .provide([[call.fn(generateChannelAddress), generalAddress]]) .put( publicChannelsActions.createChannel({ - channel: { - name: 'general', - description: 'Welcome to #general', - owner: alice.nickname, - address: 'general', - timestamp: 0 - } + channel }) ) .put( publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalAddress }) ) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts index 842105b1b2..9b7e6ee48c 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts @@ -5,6 +5,7 @@ import { identitySelectors } from '../../identity/identity.selectors' import { DateTime } from 'luxon' import { PublicChannel } from '../publicChannels.types' import logger from '../../../utils/logger' +import { generateChannelAddress } from '@quiet/common' const log = logger('publicChannels') @@ -13,15 +14,18 @@ export function* createGeneralChannelSaga(): Generator { log(`Creating general channel for ${identity.nickname}`) const timestamp = yield* call(getChannelTimestamp) - + const address = yield* call(generateChannelAddress, 'general') + console.log({ address }) const channel: PublicChannel = { name: 'general', description: 'Welcome to #general', owner: identity.nickname, - address: 'general', + address, timestamp: timestamp } + console.log({ channel }) + yield* put( publicChannelsActions.createChannel({ channel: channel diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts index 55638a8618..243d701a1a 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts @@ -14,6 +14,7 @@ import { DateTime } from 'luxon' import { publicChannelsSelectors } from '../publicChannels.selectors' import { combineReducers } from '@reduxjs/toolkit' import { reducers } from '../../reducers' +import { generateChannelAddress } from '@quiet/common' describe('sendInitialChannelMessageSaga', () => { let store: Store @@ -52,7 +53,7 @@ describe('sendInitialChannelMessageSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: 'photo' + address: generateChannelAddress('photo'), } } ) diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts index 389f025707..8186efb654 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts @@ -12,7 +12,9 @@ export function* sendInitialChannelMessageSaga( > ): Generator { const { channelName, channelAddress } = action.payload - const isGeneral = channelAddress === 'general' + const generalChannel = yield* select(publicChannelsSelectors.generalChannel) + + const isGeneral = channelAddress === generalChannel.address const pendingGeneralChannelRecreation = yield* select( publicChannelsSelectors.pendingGeneralChannelRecreation diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts index 84d90a180e..41f7a1dde0 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts @@ -1,11 +1,7 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' import { prepareStore } from '../../../utils/tests/prepareStore' -import { - getFactory, - PublicChannel, - SocketActionTypes, -} from '../../..' +import { getFactory, PublicChannel, SocketActionTypes } from '../../..' import { FactoryGirl } from 'factory-girl' import { combineReducers } from 'redux' import { reducers } from '../../reducers' @@ -19,6 +15,7 @@ import { publicChannelsSelectors } from '../publicChannels.selectors' import { messagesActions } from '../../messages/messages.slice' import { deleteChannelSaga } from './deleteChannel.saga' import { Socket } from 'socket.io-client' +import { generateChannelAddress } from '@quiet/common' describe('deleteChannelSaga', () => { let store: Store @@ -58,7 +55,7 @@ describe('deleteChannelSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: 'photo' + address: generateChannelAddress('photo') } } ) @@ -72,7 +69,7 @@ describe('deleteChannelSaga', () => { await expectSaga( deleteChannelSaga, socket, - publicChannelsActions.deleteChannel({ channel: channelAddress }) + publicChannelsActions.deleteChannel({ channelAddress }) ) .withReducer(reducer) .withState(store.getState()) @@ -94,7 +91,7 @@ describe('deleteChannelSaga', () => { await expectSaga( deleteChannelSaga, socket, - publicChannelsActions.deleteChannel({ channel: channelAddress }) + publicChannelsActions.deleteChannel({ channelAddress }) ) .withReducer(reducer) .withState(store.getState()) diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts index 23b54c7dfb..64d8daa58f 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts @@ -1,30 +1,33 @@ import { PayloadAction } from '@reduxjs/toolkit' import { publicChannelsActions } from '../publicChannels.slice' import { SocketActionTypes } from '../../socket/const/actionTypes' -import { apply, put } from 'typed-redux-saga' +import { apply, put, select } from 'typed-redux-saga' import { Socket, applyEmitParams } from '../../../types' - import logger from '../../../utils/logger' + +import { publicChannelsSelectors } from '../publicChannels.selectors' const log = logger('publicChannels') export function* deleteChannelSaga( socket: Socket, action: PayloadAction['payload']> ): Generator { - const channelAddress = action.payload.channel - const isGeneral = channelAddress === 'general' + const channelAddress = action.payload.channelAddress + const generalChannel = yield* select(publicChannelsSelectors.generalChannel) + + const isGeneral = channelAddress === generalChannel.address log(`Deleting channel ${channelAddress}`) yield* apply( socket, socket.emit, applyEmitParams(SocketActionTypes.DELETE_CHANNEL, { - channel: channelAddress + channelAddress }) ) if (!isGeneral) { - yield* put(publicChannelsActions.setCurrentChannel({ channelAddress: 'general' })) + yield* put(publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address })) yield* put(publicChannelsActions.disableChannel({ channelAddress })) } } diff --git a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts index f5e88e5279..c6642c1ca5 100644 --- a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts @@ -12,6 +12,7 @@ import { identityActions } from '../../identity/identity.slice' import { DateTime } from 'luxon' import { markUnreadChannelsSaga } from './markUnreadChannels.saga' import { messagesActions } from '../../messages/messages.slice' +import { generateChannelAddress } from '@quiet/common' describe('markUnreadChannelsSaga', () => { let store: Store @@ -49,7 +50,7 @@ describe('markUnreadChannelsSaga', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: name + address: generateChannelAddress(name) } } ) diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts index a781a2d601..6a0e4a897b 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts @@ -22,6 +22,7 @@ import { } from '../../utils/functions/dates/formatMessageDisplayDate' import { displayableMessage } from '../../utils/functions/dates/formatDisplayableMessage' import { DateTime } from 'luxon' +import { generateChannelAddress } from '@quiet/common' describe('publicChannelsSelectors', () => { let store: Store @@ -70,7 +71,7 @@ describe('publicChannelsSelectors', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: name + address: generateChannelAddress(name) } } ) diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts index 071e4657d6..f103674aa8 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts @@ -46,7 +46,7 @@ export const subscribedChannels = createSelector( // Serves for testing purposes only export const selectGeneralChannel = createSelector(selectChannels, channels => { - const draft = channels.find(item => item.address === 'general') + const draft = channels.find(item => item.name === 'general') const channel: PublicChannel = { name: draft.name, description: draft.description, @@ -287,5 +287,6 @@ export const publicChannelsSelectors = { channelsStatusSorted, dynamicSearchedChannels, sortedChannels, - pendingGeneralChannelRecreation + pendingGeneralChannelRecreation, + generalChannel } diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index 1bb9dd60d7..eea0e3dfe0 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -71,6 +71,7 @@ export const publicChannelsSlice = createSlice({ }, clearMessagesCache: (state, action: PayloadAction) => { const { channelAddress } = action.payload + console.log('clearMessagesCache', action.payload) channelMessagesAdapter.setAll(state.channels.entities[channelAddress].messages, []) }, startGeneralRecreation: state => { diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts index 7284b46fcd..433749c3b9 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts @@ -59,10 +59,10 @@ export interface CreateChannelPayload { } export interface DeleteChannelPayload { - channel: string + channelAddress: string } export interface ChannelDeletionResponsePayload { - channel: string + channelAddress: string } export interface CreatedChannelResponse { diff --git a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts index 8a8d69d9d9..7e4c92291c 100644 --- a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts @@ -12,6 +12,7 @@ import { identityActions } from '../../identity/identity.slice' import { DateTime } from 'luxon' import { updateNewestMessageSaga } from './updateNewestMessage.saga' import { messagesActions } from '../../messages/messages.slice' +import { generateChannelAddress } from '@quiet/common' describe('markUnreadChannelsSaga', () => { let store: Store @@ -48,7 +49,7 @@ describe('markUnreadChannelsSaga', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: name + address: generateChannelAddress(name) } } ) From bfd8d92593a4986c2c6e87b5d52343d973b40ac0 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Mon, 15 May 2023 15:55:33 +0200 Subject: [PATCH 03/35] general channel selector --- .../desktop/src/renderer/components/Channel/Channel.tsx | 5 +++-- .../sendDeletionMessage/sendDeletionMessage.saga.ts | 4 ++-- .../sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/desktop/src/renderer/components/Channel/Channel.tsx b/packages/desktop/src/renderer/components/Channel/Channel.tsx index aca96e59e3..00c74a2a2e 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.tsx @@ -59,8 +59,9 @@ console.log({currentChannelMessagesCount}) const isCommunityInitialized = Boolean(initializedCommunities[community?.id]) const pendingGeneralChannelRecreationSelector = useSelector(publicChannels.selectors.pendingGeneralChannelRecreation) - // !! KACPER - const pendingGeneralChannelRecreation = pendingGeneralChannelRecreationSelector && currentChannelAddress === 'general' && currentChannelMessagesCount === 0 + const generalChannel = useSelector(publicChannels.selectors.generalChannel) + + const pendingGeneralChannelRecreation = pendingGeneralChannelRecreationSelector && currentChannelAddress === generalChannel.address && currentChannelMessagesCount === 0 let enableContextMenu: boolean = false if (community) { diff --git a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts index 957e68a0e1..a87eeb6641 100644 --- a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts +++ b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts @@ -18,10 +18,10 @@ export function* sendDeletionMessageSaga( const community = yield* select(communitiesSelectors.currentCommunity) const isOwner = Boolean(community?.CA) -// KACPER + const payload: WriteMessagePayload = { type: MessageType.Info, - message: `@${ownerNickname} deleted #${channelAddress}`, + message: `@${ownerNickname} deleted #${channelAddress.slice(0, channelAddress.indexOf('_'))}`, // TEMPORARY channelAddress: generalChannel.address } diff --git a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts index d79c295057..b1561bc519 100644 --- a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts @@ -13,8 +13,7 @@ import { publicChannelsActions } from '../publicChannels.slice' import { usersSelectors } from '../../users/users.selectors' import { identitySelectors } from '../../identity/identity.selectors' import { communitiesSelectors } from '../../communities/communities.selectors' - -import { MAIN_CHANNEL } from '../../../constants' +import { publicChannelsSelectors } from '../publicChannels.selectors' export function* sendNewUserInfoMessageSaga( action: PayloadAction['payload']> @@ -28,6 +27,7 @@ export function* sendNewUserInfoMessageSaga( const incomingCertificates = action.payload.certificates const knownCertificates = yield* select(usersSelectors.certificates) + const generalChannel = yield* select(publicChannelsSelectors.generalChannel) const newCertificates = incomingCertificates.filter(cert => { const _cert = keyFromCertificate(parseCertificate(cert)) @@ -49,7 +49,7 @@ export function* sendNewUserInfoMessageSaga( const payload: WriteMessagePayload = { type: MessageType.Info, message: `@${user} has joined ${communityName}! 🎉`, - channelAddress: MAIN_CHANNEL + channelAddress: generalChannel.address } yield* put(messagesActions.sendMessage(payload)) From 0932580b8630489585f211fb6ec6d6e3427e12f2 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 16 May 2023 11:11:24 +0200 Subject: [PATCH 04/35] next part of state manager refactor --- .../renderer/components/Channel/Channel.tsx | 44 ++++++++++++------- .../components/Channel/ChannelComponent.tsx | 2 +- .../channels/ChannelInput/ChannelInput.tsx | 1 - .../sagas/notifications/notifications.saga.ts | 5 +-- .../src/integrationTests/appActions.ts | 2 +- .../channelsReplicated.saga.test.ts | 3 +- .../channelsReplicated.saga.ts | 1 + .../createGeneralChannel.saga.ts | 4 +- .../sendInitialChannelMessage.saga.test.ts | 2 +- .../deleteChannel/deleteChannel.saga.test.ts | 7 +-- .../publicChannels/publicChannels.slice.ts | 4 +- .../publicChannels.transform.ts | 7 ++- .../src/utils/tests/factories.ts | 6 ++- 13 files changed, 53 insertions(+), 35 deletions(-) diff --git a/packages/desktop/src/renderer/components/Channel/Channel.tsx b/packages/desktop/src/renderer/components/Channel/Channel.tsx index 00c74a2a2e..076bb07658 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.tsx @@ -19,10 +19,7 @@ import ChannelComponent, { ChannelComponentProps } from './ChannelComponent' import { useModal } from '../../containers/hooks' import { ModalName } from '../../sagas/modals/modals.types' -import { - FilePreviewData, - UploadFilesPreviewsProps -} from './File/UploadingPreview' +import { FilePreviewData, UploadFilesPreviewsProps } from './File/UploadingPreview' import { getFilesData } from '../../../utils/functions/fileData' @@ -42,11 +39,11 @@ const Channel = () => { const currentChannelMessagesCount = useSelector( publicChannels.selectors.currentChannelMessagesCount ) -console.log({currentChannelMessagesCount}) + const currentChannelDisplayableMessages = useSelector( publicChannels.selectors.currentChannelMessagesMergedBySender ) - console.log({currentChannelDisplayableMessages}) + const newestCurrentChannelMessage = useSelector( publicChannels.selectors.newestCurrentChannelMessage ) @@ -58,10 +55,14 @@ console.log({currentChannelMessagesCount}) const initializedCommunities = useSelector(network.selectors.initializedCommunities) const isCommunityInitialized = Boolean(initializedCommunities[community?.id]) - const pendingGeneralChannelRecreationSelector = useSelector(publicChannels.selectors.pendingGeneralChannelRecreation) - const generalChannel = useSelector(publicChannels.selectors.generalChannel) + const pendingGeneralChannelRecreationSelector = useSelector( + publicChannels.selectors.pendingGeneralChannelRecreation + ) - const pendingGeneralChannelRecreation = pendingGeneralChannelRecreationSelector && currentChannelAddress === generalChannel.address && currentChannelMessagesCount === 0 + const pendingGeneralChannelRecreation = + pendingGeneralChannelRecreationSelector && + currentChannelName === 'general' && + currentChannelMessagesCount === 0 let enableContextMenu: boolean = false if (community) { @@ -184,13 +185,19 @@ console.log({currentChannelMessagesCount}) shell.showItemInFolder(path) }, []) - const downloadFile = useCallback((media: FileMetadata) => { - dispatch(files.actions.downloadFile(media)) - }, [dispatch]) + const downloadFile = useCallback( + (media: FileMetadata) => { + dispatch(files.actions.downloadFile(media)) + }, + [dispatch] + ) - const cancelDownload = useCallback((cancelDownload: CancelDownload) => { - dispatch(files.actions.cancelDownload(cancelDownload)) - }, [dispatch]) + const cancelDownload = useCallback( + (cancelDownload: CancelDownload) => { + dispatch(files.actions.cancelDownload(cancelDownload)) + }, + [dispatch] + ) const openContextMenu = useCallback(() => { contextMenu.handleOpen() @@ -239,7 +246,12 @@ console.log({currentChannelMessagesCount}) return ( <> {currentChannelAddress && ( - + )} ) diff --git a/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx b/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx index cfcc23ffcb..392c0c146e 100644 --- a/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx +++ b/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx @@ -214,7 +214,7 @@ export const ChannelComponent: React.FC< useEffect(() => { scrollBottom() }, [channelAddress]) -console.log(isCommunityInitialized, messages.count) + return ( diff --git a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx index aa16fdc2a7..57ef63c000 100644 --- a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx +++ b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.tsx @@ -235,7 +235,6 @@ export const ChannelInputComponent: React.FC = ({ handleClipboardFiles, handleOpenFiles }) => { - console.log({inputState}) const [_anchorEl, setAnchorEl] = React.useState(null) const [mentionsToSelect, setMentionsToSelect] = React.useState([]) const messageRef = React.useRef() diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts index 618d351e2e..95062b0d8f 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts @@ -34,9 +34,8 @@ export function* displayMessageNotificationSaga( action: PayloadAction['payload']> ): Generator { const incomingMessages = action.payload.messages - console.log({ incomingMessages }) + const currentChannel = yield* select(publicChannels.selectors.currentChannel) - console.log({ currentChannel }) const currentIdentity = yield* select(identity.selectors.currentIdentity) const certificatesMapping = yield* select(users.selectors.certificatesMapping) @@ -48,7 +47,6 @@ export function* displayMessageNotificationSaga( const notificationsSound = yield* select(settings.selectors.getNotificationsSound) for (const message of incomingMessages) { - console.log({ message }) const focused = yield* call(isWindowFocused) // Do not display notifications for active channel (when the app is in foreground) @@ -155,6 +153,7 @@ function subscribeNotificationEvents( const [browserWindow] = remote.BrowserWindow.getAllWindows() browserWindow.show() // Emit store action + // KACPER emit(publicChannels.actions.setCurrentChannel({ channelAddress: channel })) } } diff --git a/packages/integration-tests/src/integrationTests/appActions.ts b/packages/integration-tests/src/integrationTests/appActions.ts index 5cc68eca4f..5ea50bfa8b 100644 --- a/packages/integration-tests/src/integrationTests/appActions.ts +++ b/packages/integration-tests/src/integrationTests/appActions.ts @@ -247,7 +247,7 @@ export async function sendMessage( log(message, 'sendMessage') const communityId = store.getState().Communities.communities.ids[0] - +// KACPER if (channelName) { store.dispatch( publicChannels.actions.setCurrentChannel({ diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts index 2f806f4531..f8449ad1de 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts @@ -65,13 +65,14 @@ describe('channelsReplicatedSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: 'owner', - address: 'photo' + address: generateChannelAddress('photo') } }) ).payload.channel }) test('save replicated channels in local storage', async () => { + console.log({ generalChannel }) const reducer = combineReducers(reducers) await expectSaga( channelsReplicatedSaga, diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts index 7368646606..d53e9f4021 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts @@ -40,6 +40,7 @@ export function* channelsReplicatedSaga( // Removing channels from store for (const channelAddress of locallyStoredChannels) { + console.log({ channelAddress }) if (!databaseStoredChannelsAddresses.includes(channelAddress)) { console.log({ channelAddress }) log(`REMOVING #${channelAddress} FROM STORE`) diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts index 9b7e6ee48c..2c08ac3e96 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts @@ -15,7 +15,7 @@ export function* createGeneralChannelSaga(): Generator { const timestamp = yield* call(getChannelTimestamp) const address = yield* call(generateChannelAddress, 'general') - console.log({ address }) + const channel: PublicChannel = { name: 'general', description: 'Welcome to #general', @@ -24,8 +24,6 @@ export function* createGeneralChannelSaga(): Generator { timestamp: timestamp } - console.log({ channel }) - yield* put( publicChannelsActions.createChannel({ channel: channel diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts index 243d701a1a..81d34d6f30 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts @@ -75,7 +75,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `Created #${channel.name}`, - channelAddress: channel.address + channelAddress: generalChannel.address }) ) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts index 41f7a1dde0..c0683dee77 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts @@ -44,7 +44,7 @@ describe('deleteChannelSaga', () => { { id: community.id, nickname: 'alice' } ) - generalChannel = publicChannelsSelectors.currentChannel(store.getState()) + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) photoChannel = ( await factory.create['payload']>( @@ -63,6 +63,7 @@ describe('deleteChannelSaga', () => { }) test('delete standard channel', async () => { + console.log({ generalChannel }) const channelAddress = photoChannel.address const reducer = combineReducers(reducers) @@ -79,13 +80,13 @@ describe('deleteChannelSaga', () => { channel: channelAddress } ]) - .put(publicChannelsActions.setCurrentChannel({ channelAddress: 'general' })) + .put(publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address })) .put(publicChannelsActions.disableChannel({ channelAddress })) .run() }) test('delete general channel', async () => { - const channelAddress = 'general' + const channelAddress = generalChannel.address const reducer = combineReducers(reducers) await expectSaga( diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index eea0e3dfe0..d60e3accb6 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -33,7 +33,9 @@ import { Identity } from '../identity/identity.types' const log = logger('publicChannels') export class PublicChannelsState { - public currentChannelAddress: string = 'general' + // KACPER + public currentChannelAddress: string = '' + public pendingGeneralChannelRecreation: boolean = false public channels: EntityState = publicChannelsAdapter.getInitialState() diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts index c7a49df7cb..ed31e62846 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts @@ -1,6 +1,6 @@ import { createTransform } from 'redux-persist' import { StoreKeys } from '../store.keys' -import { publicChannelsAdapter, publicChannelsStatusAdapter, publicChannelsSubscriptionsAdapter } from './publicChannels.adapter' +import { publicChannelsAdapter, publicChannelsSubscriptionsAdapter } from './publicChannels.adapter' import { PublicChannelsState } from './publicChannels.slice' export const PublicChannelsTransform = createTransform( @@ -10,7 +10,10 @@ export const PublicChannelsTransform = createTransform( (outboundState: PublicChannelsState, _key) => { return { ...outboundState, - currentChannelAddress: 'general', + currentChannelAddress: publicChannelsAdapter + .getSelectors() + .selectAll(outboundState.channels) + .find(channel => channel.name === 'general').address, channels: outboundState.channels, channelsStatus: outboundState.channelsStatus, channelsSubscriptions: publicChannelsSubscriptionsAdapter.getInitialState() diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index f7985e5f9f..3ed08dc159 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -13,6 +13,7 @@ import { MessageType, SendingStatus } from '../../sagas/messages/messages.types' import { DateTime } from 'luxon' import { messagesActions } from '../../sagas/messages/messages.slice' import { publicChannelsActions } from '../../sagas/publicChannels/publicChannels.slice' +import { generateChannelAddress } from '@quiet/common' export const getFactory = async (store: Store) => { // @ts-ignore @@ -52,7 +53,7 @@ export const getFactory = async (store: Store) => { description: 'Welcome to channel #general', timestamp: DateTime.utc().toSeconds(), owner: 'alice', - address: 'general' + address: generateChannelAddress('general') } }) return payload @@ -135,11 +136,12 @@ export const getFactory = async (store: Store) => { description: 'Description', timestamp: DateTime.utc().toSeconds(), owner: factory.assoc('Identity', 'nickname'), - address: '' + address: generateChannelAddress(factory.sequence('PublicChannel.name', n => `publicChannel${n}`).toString()) } }, { afterBuild: (action: ReturnType) => { + // KACPER action.payload.channel.address = action.payload.channel.name return action }, From 21bbde44d0fbdd437bd58154957cf79a0588f0d9 Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Tue, 16 May 2023 11:39:46 +0200 Subject: [PATCH 05/35] fix deleteChannel payload --- packages/backend/src/storage/storage.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index 40df9c263a..4575aa6df3 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -503,18 +503,18 @@ export class Storage extends EventEmitter { return db } - public async deleteChannel(payload: {channel: string}) { + public async deleteChannel(payload: {channelAddress: string}) { console.log('deleting channel storage', payload) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await this.channels.load({ fetchEntryTimeout: 15000 }) - const channel = this.channels.get(payload.channel) + const channel = this.channels.get(payload.channelAddress) if (channel) { - void this.channels.del(payload.channel) + void this.channels.del(payload.channelAddress) } - let repo = this.publicChannelsRepos.get(payload.channel) + let repo = this.publicChannelsRepos.get(payload.channelAddress) if (!repo) { const db = await this.orbitdb.log( - `channels.${payload.channel}`, + `channels.${payload.channelAddress}`, { accessController: { type: 'messagesaccess', @@ -537,7 +537,7 @@ export class Storage extends EventEmitter { }).filter(isDefined) await this.deleteChannelFiles(files) await this.deleteChannelMessages(hashes) - this.publicChannelsRepos.delete(payload.channel) + this.publicChannelsRepos.delete(payload.channelAddress) this.emit(StorageEvents.CHANNEL_DELETION_RESPONSE, payload) } From ca9c8c746e894a9af4ddec4d0e4a148ded1158b2 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 16 May 2023 11:41:18 +0200 Subject: [PATCH 06/35] fix payload --- packages/backend/src/libp2p/connectionsManager.ts | 2 +- packages/backend/src/socket/DataServer.ts | 4 ++-- packages/backend/src/storage/storage.ts | 15 ++++++++------- .../channelsReplicated/channelsReplicated.saga.ts | 1 + 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/libp2p/connectionsManager.ts b/packages/backend/src/libp2p/connectionsManager.ts index d6db168e93..c883361d6c 100644 --- a/packages/backend/src/libp2p/connectionsManager.ts +++ b/packages/backend/src/libp2p/connectionsManager.ts @@ -680,7 +680,7 @@ export class ConnectionsManager extends EventEmitter { this.storage.on(StorageEvents.CHECK_FOR_MISSING_FILES, (payload: CommunityId) => { this.io.emit(SocketActionTypes.CHECK_FOR_MISSING_FILES, payload) }) - this.storage.on(StorageEvents.CHANNEL_DELETION_RESPONSE, (payload: any) => { + this.storage.on(StorageEvents.CHANNEL_DELETION_RESPONSE, (payload: {channelAddress: string}) => { console.log('emitting deleted channel event back to state manager') this.io.emit(SocketActionTypes.CHANNEL_DELETION_RESPONSE, payload) }) diff --git a/packages/backend/src/socket/DataServer.ts b/packages/backend/src/socket/DataServer.ts index 847d60a28c..d4a67500cf 100644 --- a/packages/backend/src/socket/DataServer.ts +++ b/packages/backend/src/socket/DataServer.ts @@ -156,8 +156,8 @@ export class DataServer extends EventEmitter { log('leaving community') this.emit(SocketActionTypes.LEAVE_COMMUNITY) }) - socket.on(SocketActionTypes.DELETE_CHANNEL, async (payload) => { - log('deleting channel ', payload.channel) + socket.on(SocketActionTypes.DELETE_CHANNEL, async (payload: {channelAddress: string}) => { + log('deleting channel ', payload.channelAddress) this.emit(SocketActionTypes.DELETE_CHANNEL, payload) }) }) diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index 40df9c263a..b7784d9c4e 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -503,18 +503,19 @@ export class Storage extends EventEmitter { return db } - public async deleteChannel(payload: {channel: string}) { - console.log('deleting channel storage', payload) + public async deleteChannel(payload: {channelAddress: string}) { + const channelAddress = payload.channelAddress + log('deleteChannel:channelAddress', channelAddress) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await this.channels.load({ fetchEntryTimeout: 15000 }) - const channel = this.channels.get(payload.channel) + const channel = this.channels.get(channelAddress) if (channel) { - void this.channels.del(payload.channel) + void this.channels.del(channelAddress) } - let repo = this.publicChannelsRepos.get(payload.channel) + let repo = this.publicChannelsRepos.get(channelAddress) if (!repo) { const db = await this.orbitdb.log( - `channels.${payload.channel}`, + `channels.${channelAddress}`, { accessController: { type: 'messagesaccess', @@ -537,7 +538,7 @@ export class Storage extends EventEmitter { }).filter(isDefined) await this.deleteChannelFiles(files) await this.deleteChannelMessages(hashes) - this.publicChannelsRepos.delete(payload.channel) + this.publicChannelsRepos.delete(channelAddress) this.emit(StorageEvents.CHANNEL_DELETION_RESPONSE, payload) } diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts index d53e9f4021..4f48146e1d 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts @@ -41,6 +41,7 @@ export function* channelsReplicatedSaga( // Removing channels from store for (const channelAddress of locallyStoredChannels) { console.log({ channelAddress }) + console.log('check', !databaseStoredChannelsAddresses.includes(channelAddress)) if (!databaseStoredChannelsAddresses.includes(channelAddress)) { console.log({ channelAddress }) log(`REMOVING #${channelAddress} FROM STORE`) From 7271b6cca94528e3ccf6584b8c7c20ba7d5e102a Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 16 May 2023 14:21:10 +0200 Subject: [PATCH 07/35] fix state manager tests --- packages/state-manager/src/constants.ts | 2 - .../autoDownloadFiles.saga.test.ts | 37 +- .../broadcastHostedFile.saga.test.ts | 14 +- .../checkForMissingFiles.saga.test.ts | 401 ++++++++++-------- .../downloadFile/downloadFileSaga.test.ts | 9 +- .../resetTransferSpeed.saga.test.ts | 40 +- .../updateMessageMedia.test.ts | 15 +- .../sendDeletionMessage.saga.test.ts | 6 +- .../channelDeletionResponse.saga.test.ts | 6 +- .../channelsReplicated.saga.test.ts | 26 +- .../channelsReplicated.saga.ts | 3 - .../createGeneralChannel.saga.test.ts | 2 +- .../sendInitialChannelMessage.saga.test.ts | 4 +- .../deleteChannel/deleteChannel.saga.test.ts | 4 +- .../markUnreadChannels.saga.test.ts | 55 +-- .../publicChannels.selectors.test.ts | 135 +++--- .../publicChannels/publicChannels.slice.ts | 1 + .../sendNewUserInfoMessage.saga.test.ts | 17 +- .../updateNewestMessage.saga.test.ts | 131 +++--- .../src/utils/tests/factories.ts | 10 +- 20 files changed, 509 insertions(+), 409 deletions(-) diff --git a/packages/state-manager/src/constants.ts b/packages/state-manager/src/constants.ts index 01b42342a0..a8f9ac9130 100644 --- a/packages/state-manager/src/constants.ts +++ b/packages/state-manager/src/constants.ts @@ -1,5 +1,3 @@ -export const MAIN_CHANNEL = 'general' - export const AUTODOWNLOAD_SIZE_LIMIT = 20971520 // 20 MB export const PUSH_NOTIFICATION_CHANNEL = '_PUSH_NOTIFICATION_' diff --git a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts index f833960afa..aad798c49c 100644 --- a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts +++ b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts @@ -20,6 +20,7 @@ import { DateTime } from 'luxon' import { FileMetadata } from '../files.types' import { AUTODOWNLOAD_SIZE_LIMIT } from '../../../constants' import { generateChannelAddress } from '@quiet/common' +import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadFileSaga', () => { let store: Store @@ -29,6 +30,7 @@ describe('downloadFileSaga', () => { let alice: Identity let sailingChannel: PublicChannel + let generalChannel: PublicChannel beforeAll(async () => { setupCrypto() @@ -41,6 +43,7 @@ describe('downloadFileSaga', () => { ReturnType['payload'] >('Community') + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) alice = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'alice' } @@ -66,7 +69,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address })) const media: FileMetadata = { @@ -76,7 +79,7 @@ describe('downloadFileSaga', () => { ext: 'png', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -90,7 +93,7 @@ describe('downloadFileSaga', () => { type: MessageType.Image, message: 'message', createdAt: 8, - channelAddress: 'general', + channelAddress: generalChannel.address, signature: 'signature', pubKey: 'publicKey', media: media @@ -115,7 +118,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address })) const media: FileMetadata = { @@ -125,7 +128,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -139,7 +142,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: 'message', createdAt: 8, - channelAddress: 'general', + channelAddress: generalChannel.address, signature: 'signature', pubKey: 'publicKey', media: media @@ -164,7 +167,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address })) const media: FileMetadata = { @@ -174,7 +177,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -187,7 +190,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: media @@ -230,7 +233,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -243,7 +246,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: media @@ -276,7 +279,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address })) const media: FileMetadata = { @@ -287,7 +290,7 @@ describe('downloadFileSaga', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -301,7 +304,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: 'message', createdAt: 8, - channelAddress: 'general', + channelAddress: generalChannel.address, signature: 'signature', pubKey: 'publicKey', media: media @@ -326,7 +329,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address })) const media: FileMetadata = { @@ -337,7 +340,7 @@ describe('downloadFileSaga', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -351,7 +354,7 @@ describe('downloadFileSaga', () => { type: MessageType.Image, message: 'message', createdAt: 8, - channelAddress: 'general', + channelAddress: generalChannel.address, signature: 'signature', pubKey: 'publicKey', media: media diff --git a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts index 3f2672eea1..c2808a208c 100644 --- a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts +++ b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts @@ -17,6 +17,7 @@ import { publicChannelsActions } from '../../publicChannels/publicChannels.slice import { DateTime } from 'luxon' import { FileMetadata } from '../files.types' import { generateChannelAddress } from '@quiet/common' +import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadFileSaga', () => { let store: Store @@ -26,6 +27,7 @@ describe('downloadFileSaga', () => { let alice: Identity let sailingChannel: PublicChannel + let generalChannel: PublicChannel beforeAll(async () => { setupCrypto() @@ -42,7 +44,7 @@ describe('downloadFileSaga', () => { 'Identity', { id: community.id, nickname: 'alice' } ) - + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) sailingChannel = ( await factory.create['payload']>( 'PublicChannel', @@ -63,7 +65,7 @@ describe('downloadFileSaga', () => { const socket = { emit: jest.fn() } as unknown as Socket store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address })) const id = Math.random().toString(36).substr(2.9) @@ -75,7 +77,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -89,7 +91,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: media @@ -134,7 +136,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -148,7 +150,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: media diff --git a/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts b/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts index 8cd6e2e126..0eee5c8f17 100644 --- a/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts +++ b/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts @@ -1,5 +1,13 @@ import { setupCrypto } from '@quiet/identity' -import { AUTODOWNLOAD_SIZE_LIMIT, communities, getFactory, identity, MessageType, publicChannels } from '../../..' +import { + AUTODOWNLOAD_SIZE_LIMIT, + communities, + getFactory, + identity, + MessageType, + PublicChannel, + publicChannels +} from '../../..' import { prepareStore, reducers } from '../../../utils/tests/prepareStore' import { combineReducers } from '@reduxjs/toolkit' import { expectSaga } from 'redux-saga-test-plan' @@ -11,6 +19,7 @@ import { SocketActionTypes } from '../../socket/const/actionTypes' import { connectionActions } from '../../appConnection/connection.slice' import { filesActions } from '../files.slice' import { networkActions } from '../../network/network.slice' +import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('checkForMissingFilesSaga', () => { beforeAll(async () => { @@ -26,12 +35,14 @@ describe('checkForMissingFilesSaga', () => { ReturnType['payload'] >('Community') + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) + const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -54,7 +65,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.Image, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFile @@ -65,11 +76,13 @@ describe('checkForMissingFilesSaga', () => { const store = prepareStore(initialState.getState()).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Downloading - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Downloading + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -79,11 +92,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .put(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) + .put( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) .apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -103,12 +118,13 @@ describe('checkForMissingFilesSaga', () => { ReturnType['payload'] >('Community') + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -131,7 +147,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFile @@ -142,11 +158,13 @@ describe('checkForMissingFilesSaga', () => { const store = prepareStore(initialState.getState()).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Downloading - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Downloading + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -156,11 +174,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .put(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) + .put( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) .apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -180,6 +200,7 @@ describe('checkForMissingFilesSaga', () => { ReturnType['payload'] >('Community') + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) @@ -187,7 +208,7 @@ describe('checkForMissingFilesSaga', () => { const message1 = Math.random().toString(36).substr(2.9) const message2 = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFileCanceled: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -222,7 +243,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFileCanceled @@ -239,7 +260,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFilePending @@ -250,17 +271,21 @@ describe('checkForMissingFilesSaga', () => { const store = prepareStore(initialState.getState()).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFileCanceled.message.id, - cid: missingFileCanceled.cid, - downloadState: DownloadState.Canceled - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFileCanceled.message.id, + cid: missingFileCanceled.cid, + downloadState: DownloadState.Canceled + }) + ) - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFilePending.message.id, - cid: missingFilePending.cid, - downloadState: DownloadState.Downloading - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFilePending.message.id, + cid: missingFilePending.cid, + downloadState: DownloadState.Downloading + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -270,11 +295,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .not.put(filesActions.updateDownloadStatus({ - mid: missingFileCanceled.message.id, - cid: missingFileCanceled.cid, - downloadState: DownloadState.Queued - })) + .not.put( + filesActions.updateDownloadStatus({ + mid: missingFileCanceled.message.id, + cid: missingFileCanceled.cid, + downloadState: DownloadState.Queued + }) + ) .not.apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -282,11 +309,13 @@ describe('checkForMissingFilesSaga', () => { metadata: missingFileCanceled } ]) - .put(filesActions.updateDownloadStatus({ - mid: missingFilePending.message.id, - cid: missingFilePending.cid, - downloadState: DownloadState.Queued - })) + .put( + filesActions.updateDownloadStatus({ + mid: missingFilePending.message.id, + cid: missingFilePending.cid, + downloadState: DownloadState.Queued + }) + ) .apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -306,12 +335,13 @@ describe('checkForMissingFilesSaga', () => { ReturnType['payload'] >('Community') + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -334,7 +364,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFile @@ -345,11 +375,13 @@ describe('checkForMissingFilesSaga', () => { const store = prepareStore(initialState.getState()).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Ready - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Ready + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -359,11 +391,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .not.put(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) + .not.put( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) .not.apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -383,12 +417,13 @@ describe('checkForMissingFilesSaga', () => { ReturnType['payload'] >('Community') + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -411,7 +446,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFile @@ -422,11 +457,13 @@ describe('checkForMissingFilesSaga', () => { const store = prepareStore(initialState.getState()).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Downloading - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Downloading + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -436,11 +473,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .put(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) + .put( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) .apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -463,9 +502,9 @@ describe('checkForMissingFilesSaga', () => { const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) - + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -488,7 +527,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFile @@ -499,11 +538,13 @@ describe('checkForMissingFilesSaga', () => { const store = (await prepareStore(initialState.getState())).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Canceled - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Canceled + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -513,11 +554,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .not.put(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) + .not.put( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) .not.apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -537,12 +580,13 @@ describe('checkForMissingFilesSaga', () => { ReturnType['payload'] >('Community') + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -565,7 +609,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFile @@ -576,11 +620,13 @@ describe('checkForMissingFilesSaga', () => { const store = (await prepareStore(initialState.getState())).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Malicious - })) + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Malicious + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -590,11 +636,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .not.put(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) + .not.put( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) .not.apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -614,12 +662,13 @@ describe('checkForMissingFilesSaga', () => { ReturnType['payload'] >('Community') + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const channelAddress = generalChannel.address const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -642,7 +691,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: missingFile @@ -653,9 +702,11 @@ describe('checkForMissingFilesSaga', () => { const store = (await prepareStore(initialState.getState())).store const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - store.dispatch(filesActions.removeDownloadStatus({ - cid: missingFile.cid - })) + store.dispatch( + filesActions.removeDownloadStatus({ + cid: missingFile.cid + }) + ) const reducer = combineReducers(reducers) await expectSaga( @@ -665,11 +716,13 @@ describe('checkForMissingFilesSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .put(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) + .put( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) .apply(socket, socket.emit, [ SocketActionTypes.DOWNLOAD_FILE, { @@ -680,74 +733,80 @@ describe('checkForMissingFilesSaga', () => { .run() }) - it.each([[AUTODOWNLOAD_SIZE_LIMIT + 1], [AUTODOWNLOAD_SIZE_LIMIT - 1024]])('resume downloading for file of any size if it is already in queue (%s)', async (size: number) => { - const initialState = prepareStore().store - - const factory = await getFactory(initialState) - - const community = await factory.create< - ReturnType['payload'] - >('Community') - - const alice = await factory.create< - ReturnType['payload'] - >('Identity', { id: community.id, nickname: 'alice' }) - - const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' - const missingFile: FileMetadata = { - cid: Math.random().toString(36).substr(2.9), - path: null, - name: 'test-file', - ext: '.zip', - message: { - id: message, - channelAddress: channelAddress - }, - size: size - } - - await factory.create['payload']>( - 'Message', - { - identity: alice, + it.each([[AUTODOWNLOAD_SIZE_LIMIT + 1], [AUTODOWNLOAD_SIZE_LIMIT - 1024]])( + 'resume downloading for file of any size if it is already in queue (%s)', + async (size: number) => { + const initialState = prepareStore().store + + const factory = await getFactory(initialState) + + const community = await factory.create< + ReturnType['payload'] + >('Community') + + const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) + const alice = await factory.create< + ReturnType['payload'] + >('Identity', { id: community.id, nickname: 'alice' }) + + const message = Math.random().toString(36).substr(2.9) + const channelAddress = generalChannel.address + const missingFile: FileMetadata = { + cid: Math.random().toString(36).substr(2.9), + path: null, + name: 'test-file', + ext: '.zip', message: { id: message, - type: MessageType.File, - message: '', - createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', - signature: '', - pubKey: '', - media: missingFile - } + channelAddress: channelAddress + }, + size: size } - ) - const store = prepareStore(initialState.getState()).store - const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket - - store.dispatch(filesActions.updateDownloadStatus({ - mid: missingFile.message.id, - cid: missingFile.cid, - downloadState: DownloadState.Queued - })) - - const reducer = combineReducers(reducers) - await expectSaga( - checkForMissingFilesSaga, - socket, - networkActions.addInitializedCommunity(community.id) - ) - .withReducer(reducer) - .withState(store.getState()) - .apply(socket, socket.emit, [ - SocketActionTypes.DOWNLOAD_FILE, + await factory.create['payload']>( + 'Message', { - peerId: alice.peerId.id, - metadata: missingFile + identity: alice, + message: { + id: message, + type: MessageType.File, + message: '', + createdAt: DateTime.utc().valueOf(), + channelAddress: generalChannel.address, + signature: '', + pubKey: '', + media: missingFile + } } - ]) - .run() - }) + ) + + const store = prepareStore(initialState.getState()).store + const socket = { emit: jest.fn(), on: jest.fn() } as unknown as Socket + + store.dispatch( + filesActions.updateDownloadStatus({ + mid: missingFile.message.id, + cid: missingFile.cid, + downloadState: DownloadState.Queued + }) + ) + + const reducer = combineReducers(reducers) + await expectSaga( + checkForMissingFilesSaga, + socket, + networkActions.addInitializedCommunity(community.id) + ) + .withReducer(reducer) + .withState(store.getState()) + .apply(socket, socket.emit, [ + SocketActionTypes.DOWNLOAD_FILE, + { + peerId: alice.peerId.id, + metadata: missingFile + } + ]) + .run() + } + ) }) diff --git a/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts b/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts index 5b36a9a02d..50475906ec 100644 --- a/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts +++ b/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts @@ -2,7 +2,7 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' -import { getFactory } from '../../..' +import { getFactory, PublicChannel } from '../../..' import { prepareStore, reducers } from '../../../utils/tests/prepareStore' import { combineReducers } from '@reduxjs/toolkit' import { expectSaga } from 'redux-saga-test-plan' @@ -15,6 +15,7 @@ import { SocketActionTypes } from '../../socket/const/actionTypes' import { FactoryGirl } from 'factory-girl' import { DownloadState, FileMetadata } from '../../files/files.types' import { filesActions } from '../files.slice' +import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadFileSaga', () => { let store: Store @@ -25,6 +26,8 @@ describe('downloadFileSaga', () => { let message: string + let generalChannel: PublicChannel + beforeAll(async () => { setupCrypto() @@ -42,6 +45,8 @@ describe('downloadFileSaga', () => { ) message = Math.random().toString(36).substr(2.9) + + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) }) test('downloading file', async () => { @@ -54,7 +59,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: message, - channelAddress: 'general' + channelAddress: generalChannel.address } } diff --git a/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts b/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts index a5f2a41563..a442f63929 100644 --- a/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts +++ b/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts @@ -1,6 +1,6 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' -import { getFactory, MessageType, publicChannels } from '../../..' +import { getFactory, MessageType, PublicChannel, publicChannels } from '../../..' import { prepareStore, reducers } from '../../../utils/tests/prepareStore' import { combineReducers } from '@reduxjs/toolkit' import { expectSaga } from 'redux-saga-test-plan' @@ -15,6 +15,7 @@ import { DateTime } from 'luxon' import { connectionActions } from '../../appConnection/connection.slice' import { filesActions } from '../files.slice' import { networkActions } from '../../network/network.slice' +import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadFileSaga', () => { let store: Store @@ -23,6 +24,8 @@ describe('downloadFileSaga', () => { let community: Community let alice: Identity + let generalChannel: PublicChannel + beforeAll(async () => { setupCrypto() @@ -34,6 +37,8 @@ describe('downloadFileSaga', () => { ReturnType['payload'] >('Community') + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) + alice = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'alice' } @@ -43,7 +48,7 @@ describe('downloadFileSaga', () => { test('reset transfer speed for files with existing transfer speed', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address }) ) @@ -55,7 +60,7 @@ describe('downloadFileSaga', () => { ext: 'zip', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -70,7 +75,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: media @@ -92,10 +97,7 @@ describe('downloadFileSaga', () => { ) const reducer = combineReducers(reducers) - await expectSaga( - resetTransferSpeedSaga, - networkActions.addInitializedCommunity(community.id) - ) + await expectSaga(resetTransferSpeedSaga, networkActions.addInitializedCommunity(community.id)) .withReducer(reducer) .withState(store.getState()) .put( @@ -116,7 +118,7 @@ describe('downloadFileSaga', () => { test('do not reset transfer speed for files without existing transfer speed', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address }) ) @@ -128,7 +130,7 @@ describe('downloadFileSaga', () => { ext: 'zip', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -143,7 +145,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: media @@ -160,10 +162,7 @@ describe('downloadFileSaga', () => { ) const reducer = combineReducers(reducers) - await expectSaga( - resetTransferSpeedSaga, - networkActions.addInitializedCommunity(community.id) - ) + await expectSaga(resetTransferSpeedSaga, networkActions.addInitializedCommunity(community.id)) .withReducer(reducer) .withState(store.getState()) .not.put( @@ -184,7 +183,7 @@ describe('downloadFileSaga', () => { test('do not reset transfer speed for files with download state other than downloading', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelAddress: generalChannel.address }) ) @@ -196,7 +195,7 @@ describe('downloadFileSaga', () => { ext: 'zip', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -211,7 +210,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: media @@ -233,10 +232,7 @@ describe('downloadFileSaga', () => { ) const reducer = combineReducers(reducers) - await expectSaga( - resetTransferSpeedSaga, - networkActions.addInitializedCommunity(community.id) - ) + await expectSaga(resetTransferSpeedSaga, networkActions.addInitializedCommunity(community.id)) .withReducer(reducer) .withState(store.getState()) .not.put( diff --git a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts index 7fea3bae44..5538bfb3ba 100644 --- a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts +++ b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts @@ -15,6 +15,7 @@ import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' import { generateChannelAddress } from '@quiet/common' +import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadedFileSaga', () => { let store: Store @@ -25,6 +26,8 @@ describe('downloadedFileSaga', () => { let sailingChannel: PublicChannel + let generalChannel: PublicChannel + beforeAll(async () => { setupCrypto() @@ -33,9 +36,11 @@ describe('downloadedFileSaga', () => { factory = await getFactory(store) community = await factory.create< - ReturnType['payload'] + ReturnType['payload'] >('Community') + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) + alice = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'alice' } @@ -73,7 +78,7 @@ describe('downloadedFileSaga', () => { ext: 'png', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -87,7 +92,7 @@ describe('downloadedFileSaga', () => { type: MessageType.Basic, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: metadata @@ -130,7 +135,7 @@ describe('downloadedFileSaga', () => { ext: 'png', message: { id: id, - channelAddress: 'general' + channelAddress: generalChannel.address } } @@ -144,7 +149,7 @@ describe('downloadedFileSaga', () => { type: MessageType.Basic, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '', media: metadata diff --git a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts index 485b3e0b6d..14be1495a1 100644 --- a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts @@ -41,7 +41,7 @@ describe('sendDeletionMessage', () => { { id: community.id, nickname: 'alice' } ) - generalChannel = publicChannelsSelectors.currentChannel(store.getState()) + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) photoChannel = ( await factory.create['payload']>( @@ -61,11 +61,11 @@ describe('sendDeletionMessage', () => { test('send message after deletion standard channel', async () => { const channelAddress = photoChannel.address - const message = `@${owner.nickname} deleted #${channelAddress}` + const message = `@${owner.nickname} deleted #${photoChannel.name}` const messagePayload: WriteMessagePayload = { type: MessageType.Info, message, - channelAddress: 'general' + channelAddress: generalChannel.address } const reducer = combineReducers(reducers) await expectSaga( diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts index 0e270b984f..75340bc9ee 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts @@ -41,7 +41,7 @@ describe('channelDeletionResponseSaga', () => { { id: community.id, nickname: 'alice' } ) - generalChannel = publicChannelsSelectors.currentChannel(store.getState()) + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) photoChannel = ( await factory.create['payload']>( @@ -79,7 +79,7 @@ describe('channelDeletionResponseSaga', () => { }) test('delete general channel', async () => { - const channelAddress = 'general' + const channelAddress = generalChannel.address const reducer = combineReducers(reducers) await expectSaga( @@ -126,7 +126,7 @@ describe('channelDeletionResponseSaga', () => { }) test('delete general channel', async () => { - const channelAddress = 'general' + const channelAddress = generalChannel.address const reducer = combineReducers(reducers) await expectSaga( diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts index f8449ad1de..75982b5cbe 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts @@ -1,7 +1,7 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' import { prepareStore } from '../../../utils/tests/prepareStore' -import { getFactory, messages, PublicChannel, publicChannels } from '../../..' +import { getFactory, messages, MessageType, PublicChannel, publicChannels } from '../../..' import { FactoryGirl } from 'factory-girl' import { combineReducers } from 'redux' import { reducers } from '../../reducers' @@ -42,7 +42,7 @@ describe('channelsReplicatedSaga', () => { { id: community.id, nickname: 'alice' } ) - generalChannel = publicChannelsSelectors.currentChannel(store.getState()) + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) sailingChannel = ( await factory.build('PublicChannel', { @@ -183,7 +183,16 @@ describe('channelsReplicatedSaga', () => { const message = await factory.create< ReturnType['payload'] >('Message', { - identity: alice + identity: alice, + message: { + id: (Math.random() * 10 ** 18).toString(36), + type: MessageType.Basic, + message: (Math.random() * 10 ** 18).toString(36), + createdAt: DateTime.utc().valueOf(), + channelAddress: generalChannel.address, + signature: '', + pubKey: '' + } }) store.dispatch( @@ -213,7 +222,16 @@ describe('channelsReplicatedSaga', () => { const message = await factory.create< ReturnType['payload'] >('Message', { - identity: alice + identity: alice, + message: { + id: (Math.random() * 10 ** 18).toString(36), + type: MessageType.Basic, + message: (Math.random() * 10 ** 18).toString(36), + createdAt: DateTime.utc().valueOf(), + channelAddress: generalChannel.address, + signature: '', + pubKey: '' + } }) const reducer = combineReducers(reducers) diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts index 4f48146e1d..9e1ca2823e 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts @@ -40,10 +40,7 @@ export function* channelsReplicatedSaga( // Removing channels from store for (const channelAddress of locallyStoredChannels) { - console.log({ channelAddress }) - console.log('check', !databaseStoredChannelsAddresses.includes(channelAddress)) if (!databaseStoredChannelsAddresses.includes(channelAddress)) { - console.log({ channelAddress }) log(`REMOVING #${channelAddress} FROM STORE`) yield* put(publicChannelsActions.deleteChannel({ channelAddress })) } diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts index 96c42c8c73..68fc56d2c4 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts @@ -47,7 +47,7 @@ describe('createGeneralChannelSaga', () => { address: generalAddress, timestamp: 0 } - console.log({ channel }) + await expectSaga(createGeneralChannelSaga) .withReducer(reducer) .withState(store.getState()) diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts index 81d34d6f30..ab1457faaa 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts @@ -42,7 +42,7 @@ describe('sendInitialChannelMessageSaga', () => { { id: community.id, nickname: 'alice' } ) - generalChannel = publicChannelsSelectors.currentChannel(store.getState()) + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) channel = ( await factory.create['payload']>( @@ -75,7 +75,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `Created #${channel.name}`, - channelAddress: generalChannel.address + channelAddress: channel.address }) ) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts index c0683dee77..bbd83b41ae 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts @@ -77,7 +77,7 @@ describe('deleteChannelSaga', () => { .apply(socket, socket.emit, [ SocketActionTypes.DELETE_CHANNEL, { - channel: channelAddress + channelAddress } ]) .put(publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address })) @@ -99,7 +99,7 @@ describe('deleteChannelSaga', () => { .apply(socket, socket.emit, [ SocketActionTypes.DELETE_CHANNEL, { - channel: channelAddress + channelAddress } ]) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts index c6642c1ca5..83dcccc4a6 100644 --- a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts @@ -21,6 +21,7 @@ describe('markUnreadChannelsSaga', () => { let community: Community let alice: Identity let bob: Identity + let channelAdresses: string[] = [] beforeAll(async () => { setupCrypto() @@ -42,23 +43,24 @@ describe('markUnreadChannelsSaga', () => { // Automatically create channels for (const name of channelNames) { - await factory.create['payload']>( - 'PublicChannel', - { - channel: { - name: name, - description: `Welcome to #${name}`, - timestamp: DateTime.utc().valueOf(), - owner: alice.nickname, - address: generateChannelAddress(name) - } + const channel = await factory.create< + ReturnType['payload'] + >('PublicChannel', { + channel: { + name: name, + description: `Welcome to #${name}`, + timestamp: DateTime.utc().valueOf(), + owner: alice.nickname, + address: generateChannelAddress(name) } - ) + }) + channelAdresses = [...channelAdresses, channel.channel.address] } }) test('mark unread channels', async () => { - const messagesAddresses = ['general', 'memes', 'enya', 'travels'] + console.log({ channelAdresses }) + const messagesAddresses = channelAdresses const messages: ChannelMessage[] = [] // Automatically create messages @@ -92,7 +94,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 99999999999999, - channelAddress: 'enya', + channelAddress: channelAdresses.find((address) => address.includes('enya')), signature: '', pubKey: '' }, @@ -114,19 +116,19 @@ describe('markUnreadChannelsSaga', () => { .withState(store.getState()) .put( publicChannelsActions.markUnreadChannel({ - channelAddress: 'memes', + channelAddress: channelAdresses.find((address) => address.includes('memes')), message: messages[1] }) ) .not.put( publicChannelsActions.markUnreadChannel({ - channelAddress: 'enya', + channelAddress: channelAdresses.find((address) => address.includes('enya')), message: messages[2] }) ) .put( publicChannelsActions.markUnreadChannel({ - channelAddress: 'travels', + channelAddress: channelAdresses.find((address) => address.includes('travels')), message: messages[3] }) ) @@ -134,17 +136,16 @@ describe('markUnreadChannelsSaga', () => { }) test('do not mark unread channels if message is older than user', async () => { - const messagesAddresses = ['general', 'memes', 'enya', 'travels'] + const messagesAddresses = channelAdresses const messages: ChannelMessage[] = [] const community = await factory.create< - ReturnType['payload'] - >('Community') + ReturnType['payload'] + >('Community') - const alice = await factory.create['payload']>( - 'Identity', - { id: community.id, nickname: 'alice', joinTimestamp: 9239423949 } - ) + const alice = await factory.create< + ReturnType['payload'] + >('Identity', { id: community.id, nickname: 'alice', joinTimestamp: 9239423949 }) // Automatically create older messages for (const address of messagesAddresses) { @@ -177,7 +178,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 99999999999999, - channelAddress: 'enya', + channelAddress: channelAdresses.find((address) => address.includes('enya')), signature: '', pubKey: '' }, @@ -199,19 +200,19 @@ describe('markUnreadChannelsSaga', () => { .withState(store.getState()) .not.put( publicChannelsActions.markUnreadChannel({ - channelAddress: 'memes', + channelAddress: channelAdresses.find((address) => address.includes('memes')), message: messages[1] }) ) .put( publicChannelsActions.markUnreadChannel({ - channelAddress: 'enya', + channelAddress: channelAdresses.find((address) => address.includes('enya')), message: message }) ) .not.put( publicChannelsActions.markUnreadChannel({ - channelAddress: 'travels', + channelAddress: channelAdresses.find((address) => address.includes('travels')), message: messages[3] }) ) diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts index 6a0e4a897b..b4ce278d35 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts @@ -11,7 +11,7 @@ import { publicChannelsSelectors } from './publicChannels.selectors' import { publicChannelsActions } from './publicChannels.slice' -import { DisplayableMessage, ChannelMessage } from './publicChannels.types' +import { DisplayableMessage, ChannelMessage, PublicChannel } from './publicChannels.types' import { communitiesActions, Community } from '../communities/communities.slice' import { identityActions } from '../identity/identity.slice' import { usersActions } from '../users/users.slice' @@ -32,6 +32,9 @@ describe('publicChannelsSelectors', () => { let alice: Identity let john: Identity + let generalChannel: PublicChannel + let channelAddresses: string[] = [] + const msgs: { [id: string]: ChannelMessage } = {} const msgsOwners: { [id: string]: string } = {} @@ -46,14 +49,15 @@ describe('publicChannelsSelectors', () => { factory = await getFactory(store) community = await factory.create< - ReturnType['payload'] + ReturnType['payload'] >('Community') alice = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'alice' } ) - + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) + channelAddresses = [...channelAddresses, generalChannel.address] john = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'john' } @@ -63,18 +67,18 @@ describe('publicChannelsSelectors', () => { const channelNames = ['croatia', 'allergies', 'sailing', 'pets', 'antiques'] for (const name of channelNames) { - await factory.create['payload']>( - 'PublicChannel', - { - channel: { - name: name, - description: `Welcome to #${name}`, - timestamp: DateTime.utc().valueOf(), - owner: alice.nickname, - address: generateChannelAddress(name) - } + const channel = await factory.create< + ReturnType['payload'] + >('PublicChannel', { + channel: { + name: name, + description: `Welcome to #${name}`, + timestamp: DateTime.utc().valueOf(), + owner: alice.nickname, + address: generateChannelAddress(name) } - ) + }) + channelAddresses = [...channelAddresses, channel.channel.address] } /* Messages ids are being used only for veryfing proper order... @@ -198,7 +202,7 @@ describe('publicChannelsSelectors', () => { for (const item of shuffled) { const message = await factory.create< - ReturnType['payload'] + ReturnType['payload'] >('Message', { identity: item.identity, message: { @@ -206,7 +210,7 @@ describe('publicChannelsSelectors', () => { type: item.type || MessageType.Basic, message: `message_${item.id}`, createdAt: item.createdAt, - channelAddress: 'general', + channelAddress: generalChannel.address, signature: '', pubKey: '' }, @@ -246,10 +250,7 @@ describe('publicChannelsSelectors', () => { expect(groupDay3).toBe('Today') const expectedGrouppedMessages = { - [groupDay1]: [ - [displayable['7']], - [displayable['8']] - ], + [groupDay1]: [[displayable['7']], [displayable['8']]], [groupDay2]: [ [displayable['1']], [displayable['2']], @@ -277,45 +278,52 @@ describe('publicChannelsSelectors', () => { }) it("don't select messages without author", async () => { - const channel = (await factory.create['payload']>( - 'PublicChannel', - { - channel: { - name: 'utah', - description: 'Welcome to #utah', - timestamp: DateTime.utc().valueOf(), - owner: alice.nickname, - address: 'utah' + const channelAddress = generateChannelAddress('utah') + const channel = ( + await factory.create['payload']>( + 'PublicChannel', + { + channel: { + name: 'utah', + description: 'Welcome to #utah', + timestamp: DateTime.utc().valueOf(), + owner: alice.nickname, + address: channelAddress + } } - } - )).channel + ) + ).channel - const elouise = await factory.create['payload']>( - 'Identity', - { id: community.id, nickname: 'elouise' } + const elouise = await factory.create< + ReturnType['payload'] + >('Identity', { id: community.id, nickname: 'elouise' }) + + store.dispatch( + usersActions.test_remove_user_certificate({ certificate: elouise.userCertificate }) ) - store.dispatch(usersActions.test_remove_user_certificate({ certificate: elouise.userCertificate })) - - store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: channel.address - })) - - await factory.create< - ReturnType['payload'] - >('Message', { - identity: elouise, - message: { - id: '0', - type: MessageType.Basic, - message: 'elouise_message', - createdAt: DateTime.now().valueOf(), - channelAddress: channel.address, - signature: '', - pubKey: '' - }, - verifyAutomatically: true - }) + store.dispatch( + publicChannelsActions.setCurrentChannel({ + channelAddress: channelAddress + }) + ) + + await factory.create['payload']>( + 'Message', + { + identity: elouise, + message: { + id: '0', + type: MessageType.Basic, + message: 'elouise_message', + createdAt: DateTime.now().valueOf(), + channelAddress: channelAddress, + signature: '', + pubKey: '' + }, + verifyAutomatically: true + } + ) const messages = displayableCurrentChannelMessages(store.getState()) @@ -326,9 +334,9 @@ describe('publicChannelsSelectors', () => { // This case occurred in a built app const store = prepareStore().store const factory = await getFactory(store) - await factory.create< - ReturnType['payload'] - >('Community') + await factory.create['payload']>( + 'Community' + ) const oldState = store.getState() const channelId = oldState.PublicChannels.channels.ids[0] @@ -352,11 +360,14 @@ describe('publicChannelsSelectors', () => { }) it('unreadChannels selector returns only unread channels', async () => { - store.dispatch(publicChannelsActions.markUnreadChannel({ - channelAddress: 'allergies' - })) + const channelAddress = channelAddresses.find((channelAddress) => channelAddress.includes('allergies')) + store.dispatch( + publicChannelsActions.markUnreadChannel({ + channelAddress + }) + ) const unreadChannels = publicChannelsSelectors.unreadChannels(store.getState()) - expect(unreadChannels).toEqual(['allergies']) + expect(unreadChannels).toEqual([channelAddress]) }) }) diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index d60e3accb6..8741f881bc 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -152,6 +152,7 @@ export const publicChannelsSlice = createSlice({ }> ) => { const { message } = action.payload + console.log({ message }) channelMessagesAdapter.addOne( state.channels.entities[message.channelAddress].messages, message diff --git a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts index db44f09713..f999e26e6c 100644 --- a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts @@ -14,15 +14,14 @@ import { sendNewUserInfoMessageSaga } from './sendNewUserInfoMessage.saga' import { messagesActions } from '../../messages/messages.slice' import { combineReducers } from '@reduxjs/toolkit' import { reducers } from '../../reducers' - -import { MAIN_CHANNEL } from '../../../constants' - +import { publicChannelsSelectors } from '../publicChannels.selectors' describe('sendInitialChannelMessageSaga', () => { let store: Store let factory: FactoryGirl let channel: PublicChannel let user: Identity let user2: Identity + let generalChannel: PublicChannel beforeAll(async () => { setupCrypto() @@ -53,7 +52,7 @@ describe('sendInitialChannelMessageSaga', () => { channel = (await factory.build('PublicChannel')) .payload.channel - + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) store.dispatch( usersActions.test_remove_user_certificate({ certificate: user2.userCertificate }) ) @@ -71,7 +70,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2.nickname} has joined ${communityName}! 🎉`, - channelAddress: MAIN_CHANNEL + channelAddress: generalChannel.address }) ) .run() @@ -99,6 +98,7 @@ describe('sendInitialChannelMessageSaga', () => { .payload.channel const communityName = community1.name[0].toUpperCase() + community1.name.substring(1) + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) const reducer = combineReducers(reducers) await expectSaga( @@ -111,7 +111,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2.nickname} has joined ${communityName}! 🎉`, - channelAddress: MAIN_CHANNEL + channelAddress: generalChannel.address }) ) .run() @@ -142,7 +142,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2} has joined ${community1.name}! 🎉`, - channelAddress: MAIN_CHANNEL + channelAddress: generalChannel.address }) ) .run() @@ -174,6 +174,7 @@ describe('sendInitialChannelMessageSaga', () => { ) const communityName = community1.name[0].toUpperCase() + community1.name.substring(1) + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) const reducer = combineReducers(reducers) const result = await expectSaga( @@ -188,7 +189,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2.nickname} has joined ${communityName}! 🎉`, - channelAddress: MAIN_CHANNEL + channelAddress: generalChannel.address }) ) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts index 7e4c92291c..efe0a6ed7b 100644 --- a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts @@ -1,6 +1,6 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' -import { getFactory, Community, ChannelMessage, MessageType } from '../../..' +import { getFactory, Community, ChannelMessage, MessageType, PublicChannel } from '../../..' import { prepareStore, reducers } from '../../../utils/tests/prepareStore' import { expectSaga } from 'redux-saga-test-plan' import { publicChannelsActions } from '../publicChannels.slice' @@ -13,6 +13,7 @@ import { DateTime } from 'luxon' import { updateNewestMessageSaga } from './updateNewestMessage.saga' import { messagesActions } from '../../messages/messages.slice' import { generateChannelAddress } from '@quiet/common' +import { publicChannelsSelectors } from '../publicChannels.selectors' describe('markUnreadChannelsSaga', () => { let store: Store @@ -21,6 +22,10 @@ describe('markUnreadChannelsSaga', () => { let community: Community let alice: Identity + let generalChannel: PublicChannel + + let channelAdresses: string[] = [] + beforeAll(async () => { setupCrypto() @@ -29,35 +34,36 @@ describe('markUnreadChannelsSaga', () => { factory = await getFactory(store) community = await factory.create< - ReturnType['payload'] + ReturnType['payload'] >('Community') alice = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'alice' } ) - + generalChannel = publicChannelsSelectors.generalChannel(store.getState()) + channelAdresses = [...channelAdresses, generalChannel.address] const channelNames = ['memes', 'pets', 'travels'] // Automatically create channels for (const name of channelNames) { - await factory.create['payload']>( - 'PublicChannel', - { - channel: { - name: name, - description: `Welcome to #${name}`, - timestamp: DateTime.utc().valueOf(), - owner: alice.nickname, - address: generateChannelAddress(name) - } + const channel = await factory.create< + ReturnType['payload'] + >('PublicChannel', { + channel: { + name: name, + description: `Welcome to #${name}`, + timestamp: DateTime.utc().valueOf(), + owner: alice.nickname, + address: generateChannelAddress(name) } - ) + }) + channelAdresses = [...channelAdresses, channel.channel.address] } }) test('Update newest message if there is no newest message', async () => { - const messagesAddresses = ['general', 'memes'] + const messagesAddresses = channelAdresses const messages: ChannelMessage[] = [] // Automatically create messages @@ -89,17 +95,13 @@ describe('markUnreadChannelsSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .put( - publicChannelsActions.updateNewestMessage({ message: messages[0] }) - ) - .put( - publicChannelsActions.updateNewestMessage({ message: messages[1] }) - ) + .put(publicChannelsActions.updateNewestMessage({ message: messages[0] })) + .put(publicChannelsActions.updateNewestMessage({ message: messages[1] })) .run() }) test('update newest message if incoming message is newer', async () => { - const messagesAddresses = ['general'] + const messagesAddresses = [generalChannel.address] const messages: ChannelMessage[] = [] // Automatically create messages @@ -123,23 +125,26 @@ describe('markUnreadChannelsSaga', () => { } // Set the newest message - const message = (await factory.create< - ReturnType['payload'] - >('Message', { - identity: alice, - message: { - id: Math.random().toString(36).substr(2.9), - type: MessageType.Basic, - message: 'message', - createdAt: 9999, - channelAddress: 'general', - signature: '', - pubKey: '' - }, - verifyAutomatically: true - })).message - - store.dispatch(publicChannelsActions.updateNewestMessage({ message })) + const message = ( + await factory.create['payload']>( + 'Message', + { + identity: alice, + message: { + id: Math.random().toString(36).substr(2.9), + type: MessageType.Basic, + message: 'message', + createdAt: 9999, + channelAddress: generalChannel.address, + signature: '', + pubKey: '' + }, + verifyAutomatically: true + } + ) + ).message + + store.dispatch(publicChannelsActions.updateNewestMessage({ message })) const reducer = combineReducers(reducers) await expectSaga( @@ -150,13 +155,11 @@ describe('markUnreadChannelsSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .put( - publicChannelsActions.updateNewestMessage({ message: messages[0] }) - ) + .put(publicChannelsActions.updateNewestMessage({ message: messages[0] })) .run() }) test('do not update newest message if incoming message is older', async () => { - const messagesAddresses = ['general'] + const messagesAddresses = [generalChannel.address] const messages: ChannelMessage[] = [] // Automatically create messages @@ -180,23 +183,26 @@ describe('markUnreadChannelsSaga', () => { } // Set the newest message - const message = (await factory.create< - ReturnType['payload'] - >('Message', { - identity: alice, - message: { - id: Math.random().toString(36).substr(2.9), - type: MessageType.Basic, - message: 'message', - createdAt: 99999999999999, - channelAddress: 'general', - signature: '', - pubKey: '' - }, - verifyAutomatically: true - })).message - - store.dispatch(publicChannelsActions.updateNewestMessage({ message })) + const message = ( + await factory.create['payload']>( + 'Message', + { + identity: alice, + message: { + id: Math.random().toString(36).substr(2.9), + type: MessageType.Basic, + message: 'message', + createdAt: 99999999999999, + channelAddress: generalChannel.address, + signature: '', + pubKey: '' + }, + verifyAutomatically: true + } + ) + ).message + + store.dispatch(publicChannelsActions.updateNewestMessage({ message })) const reducer = combineReducers(reducers) await expectSaga( @@ -207,10 +213,7 @@ describe('markUnreadChannelsSaga', () => { ) .withReducer(reducer) .withState(store.getState()) - .not - .put( - publicChannelsActions.updateNewestMessage({ message: messages[0] }) - ) + .not.put(publicChannelsActions.updateNewestMessage({ message: messages[0] })) .run() }) }) diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index 3ed08dc159..7b5ef66c5c 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -140,11 +140,11 @@ export const getFactory = async (store: Store) => { } }, { - afterBuild: (action: ReturnType) => { - // KACPER - action.payload.channel.address = action.payload.channel.name - return action - }, + // afterBuild: (action: ReturnType) => { + // // KACPER + // action.payload.channel.address = generateChannelAddress(action.payload.channel.name) + // return action + // }, afterCreate: async ( payload: ReturnType['payload'] ) => { From a8a4c500ff163cd50561dcc496b35fbe26d1dca6 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 16 May 2023 15:10:33 +0200 Subject: [PATCH 08/35] fix createGeneralChannel test --- .../createGeneralChannel.saga.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts index 68fc56d2c4..28c117e73b 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts @@ -47,12 +47,14 @@ describe('createGeneralChannelSaga', () => { address: generalAddress, timestamp: 0 } - + console.log({ channel }) await expectSaga(createGeneralChannelSaga) .withReducer(reducer) .withState(store.getState()) - .provide([[call.fn(getChannelTimestamp), 0]]) - .provide([[call.fn(generateChannelAddress), generalAddress]]) + .provide([ + [call.fn(getChannelTimestamp), 0], + [call.fn(generateChannelAddress), generalAddress] + ]) .put( publicChannelsActions.createChannel({ channel From cda682fdb6ea8434d14be71ac0e82c366404a2bf Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Tue, 16 May 2023 15:18:46 +0200 Subject: [PATCH 09/35] fix markUnreadChannel test --- .../markUnreadChannels/markUnreadChannels.saga.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts index 83dcccc4a6..53446fdee0 100644 --- a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts @@ -59,7 +59,6 @@ describe('markUnreadChannelsSaga', () => { }) test('mark unread channels', async () => { - console.log({ channelAdresses }) const messagesAddresses = channelAdresses const messages: ChannelMessage[] = [] @@ -117,7 +116,7 @@ describe('markUnreadChannelsSaga', () => { .put( publicChannelsActions.markUnreadChannel({ channelAddress: channelAdresses.find((address) => address.includes('memes')), - message: messages[1] + message: messages[0] }) ) .not.put( From 55784b566cc4973a8de0e053638107015b4ab87f Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 16 May 2023 15:50:34 +0200 Subject: [PATCH 10/35] fix publicChannels.selectors.test --- .../publicChannels.selectors.test.ts.snap | 18 +++++++-------- .../publicChannels.selectors.test.ts | 22 +++++++++++++++---- .../src/utils/tests/factories.ts | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap b/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap index 68ca5b14cb..b82625342e 100644 --- a/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap +++ b/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap @@ -2,7 +2,7 @@ exports[`publicChannelsSelectors get messages sorted by date 1`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "1", "message": "message_1", @@ -14,7 +14,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 2`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "2", "message": "message_2", @@ -26,7 +26,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 3`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "3", "message": "message_3", @@ -38,7 +38,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 4`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "4", "message": "message_4", @@ -50,7 +50,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 5`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "5", "message": "message_5", @@ -62,7 +62,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 6`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "6", "message": "message_6", @@ -74,7 +74,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 7`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "7", "message": "message_7", @@ -86,7 +86,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 8`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "8", "message": "message_8", @@ -98,7 +98,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 9`] = ` Object { - "channelAddress": "general", + "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "9", "message": "message_9", diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts index b4ce278d35..7769fc9b63 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts @@ -62,7 +62,9 @@ describe('publicChannelsSelectors', () => { 'Identity', { id: community.id, nickname: 'john' } ) - + store.dispatch( + publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address }) + ) // Setup channels const channelNames = ['croatia', 'allergies', 'sailing', 'pets', 'antiques'] @@ -223,7 +225,18 @@ describe('publicChannelsSelectors', () => { it('get messages sorted by date', async () => { const messages = sortedCurrentChannelMessages(store.getState()) - messages.forEach(message => { + + const formattedMessages = messages.reduce((prev: ChannelMessage[], curr: ChannelMessage) => { + return [ + ...prev, + { + ...curr, + channelAddress: 'general_ec4bca1fa76046c53dff1e49979c3647' + } + ] + }, []) + + formattedMessages.forEach(message => { expect(message).toMatchSnapshot({ createdAt: expect.any(Number), pubKey: expect.any(String), @@ -234,7 +247,6 @@ describe('publicChannelsSelectors', () => { it('get grouped messages', async () => { const messages = currentChannelMessagesMergedBySender(store.getState()) - // Convert regular messages to displayable messages const displayable: { [id: string]: DisplayableMessage } = {} for (const message of Object.values(msgs)) { @@ -360,7 +372,9 @@ describe('publicChannelsSelectors', () => { }) it('unreadChannels selector returns only unread channels', async () => { - const channelAddress = channelAddresses.find((channelAddress) => channelAddress.includes('allergies')) + const channelAddress = channelAddresses.find(channelAddress => + channelAddress.includes('allergies') + ) store.dispatch( publicChannelsActions.markUnreadChannel({ channelAddress diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index 7b5ef66c5c..a97d0a251d 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -165,7 +165,7 @@ export const getFactory = async (store: Store) => { type: MessageType.Basic, message: factory.sequence('Message.message', n => `message_${n}`), createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generateChannelAddress('general'), signature: '', pubKey: '' }, From fd110cc49eaf4bc772a9665a1775d271b94a5ad3 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 08:38:39 +0200 Subject: [PATCH 11/35] fix channelsReplicated.saga.test.ts --- .../channelsReplicated/channelsReplicated.saga.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts index 75982b5cbe..88d99414e9 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts @@ -43,7 +43,9 @@ describe('channelsReplicatedSaga', () => { ) generalChannel = publicChannelsSelectors.generalChannel(store.getState()) - + store.dispatch( + publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address }) + ) sailingChannel = ( await factory.build('PublicChannel', { communityId: community.id, From 5e3fdccc68f219e90e4268d7064e09946defe487 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 09:14:31 +0200 Subject: [PATCH 12/35] fix backend unit test --- packages/backend/src/storage/storage.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/storage/storage.test.ts b/packages/backend/src/storage/storage.test.ts index 71b4f1705c..b0b59ab37e 100644 --- a/packages/backend/src/storage/storage.test.ts +++ b/packages/backend/src/storage/storage.test.ts @@ -170,10 +170,10 @@ describe('Channels', () => { const eventSpy = jest.spyOn(storage, 'emit') - await storage.deleteChannel({ channel: channelio.address }) + await storage.deleteChannel({ channelAddress: channelio.address }) expect(eventSpy).toBeCalledWith('channelDeletionResponse', { - channel: channelio.address + channelAddress: channelio.address }) }) }) From 6d698a73a60df3e5e8a5f11dc8a25ae435648f8d Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 09:45:26 +0200 Subject: [PATCH 13/35] fix storage backend test file --- packages/backend/src/storage/storage.test.ts | 36 +++++++++++++++---- .../publicChannels/publicChannels.slice.ts | 1 - .../src/utils/tests/factories.ts | 5 --- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/storage/storage.test.ts b/packages/backend/src/storage/storage.test.ts index b0b59ab37e..07c8a51407 100644 --- a/packages/backend/src/storage/storage.test.ts +++ b/packages/backend/src/storage/storage.test.ts @@ -14,8 +14,9 @@ import { jest, beforeEach, describe, it, expect, afterEach, beforeAll } from '@j import { sleep } from '../sleep' import { StorageEvents } from './types' import type { Storage as StorageType } from './storage' -import { ChannelMessage, Community, Identity, PublicChannel, TestMessage } from '@quiet/types' +import { ChannelMessage, Community, Identity, MessageType, PublicChannel, TestMessage } from '@quiet/types' import { Store, getFactory, prepareStore, publicChannels } from '@quiet/state-manager' +import { DateTime } from 'luxon' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -57,6 +58,23 @@ let utils: ComonUtilsModuleType jest.setTimeout(50000) +const generateMessageFactoryContent = () => { + const obj = { + message: { + id: (Math.random() * 10 ** 18).toString(36), + type: MessageType.Basic, + message: (Math.random() * 10 ** 18).toString(36), + createdAt: DateTime.utc().valueOf(), + channelAddress: channel.address, + signature: '', + pubKey: '' + }, + verifyAutomatically: false + } + + return obj +} + beforeAll(async () => { store = prepareStore().store factory = await getFactory(store) @@ -87,7 +105,8 @@ beforeAll(async () => { await factory.create( 'Message', { - identity: alice + identity: alice, + ...generateMessageFactoryContent() } ) ).message @@ -312,7 +331,8 @@ describe('Certificate', () => { const aliceMessage = await factory.create< ReturnType['payload'] >('Message', { - identity: alice + identity: alice, + ...generateMessageFactoryContent() }) storage = new Storage(tmpAppDataPath, community.id, { createPaths: false }) @@ -358,13 +378,16 @@ describe('Certificate', () => { const aliceMessage = await factory.create< ReturnType['payload'] >('Message', { - identity: alice + identity: alice, + ...generateMessageFactoryContent() }) const johnMessage = await factory.create< ReturnType['payload'] >('Message', { - identity: john + identity: john, + ...generateMessageFactoryContent() + }) const aliceMessageWithJohnsPublicKey: ChannelMessage = { @@ -468,7 +491,8 @@ describe('Message access controller', () => { const aliceMessage = await factory.create< ReturnType['payload'] >('Message', { - identity: alice + identity: alice, + ...generateMessageFactoryContent() }) // @ts-expect-error userCertificate can be undefined const johnCertificate: string = john.userCertificate diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index 8741f881bc..d60e3accb6 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -152,7 +152,6 @@ export const publicChannelsSlice = createSlice({ }> ) => { const { message } = action.payload - console.log({ message }) channelMessagesAdapter.addOne( state.channels.entities[message.channelAddress].messages, message diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index a97d0a251d..db29105f5e 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -140,11 +140,6 @@ export const getFactory = async (store: Store) => { } }, { - // afterBuild: (action: ReturnType) => { - // // KACPER - // action.payload.channel.address = generateChannelAddress(action.payload.channel.name) - // return action - // }, afterCreate: async ( payload: ReturnType['payload'] ) => { From a69ab29f3a00ed1338a611e7530c11e4046b1134 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 12:25:21 +0200 Subject: [PATCH 14/35] fix desktop tets, saga and currentChannelAddress selector --- .../ChannelsPanel/ChannelsPanel.test.tsx | 7 ++-- .../Sidebar/ChannelsPanel/ChannelsPanel.tsx | 6 +-- .../notifications/notifications.click.test.ts | 29 ++++++++----- .../sagas/notifications/notifications.saga.ts | 5 ++- .../sagas/notifications/notifications.test.ts | 3 +- .../publicChannels.selectors.ts | 23 +++++++++- .../publicChannels/publicChannels.slice.ts | 7 ++-- .../publicChannels/publicChannels.types.ts | 2 + .../src/utils/tests/factories.ts | 42 +++++++++++++------ 9 files changed, 89 insertions(+), 35 deletions(-) diff --git a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx index 8b9905cd82..fb3a3e0064 100644 --- a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx @@ -6,6 +6,7 @@ import { renderComponent } from '../../../testUtils/renderComponent' import { getFactory, publicChannels, communities, identity } from '@quiet/state-manager' import ChannelsPanel from './ChannelsPanel' import { DateTime } from 'luxon' +import { generateChannelAddress } from '@quiet/common' describe('Channels panel', () => { let socket: MockedSocket @@ -26,7 +27,7 @@ describe('Channels panel', () => { const community = await factory.create< ReturnType['payload'] >('Community') - + const generalChannel = publicChannels.selectors.generalChannel(store.getState()) const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) @@ -43,7 +44,7 @@ describe('Channels panel', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: name + address: generateChannelAddress(name) } } ) @@ -56,7 +57,7 @@ describe('Channels panel', () => { channels={channels} unreadChannels={[]} setCurrentChannel={function (_address: string): void {}} - currentChannel={'general'} + currentChannelAddress={generalChannel.address} createChannelModal={{ open: false, handleOpen: function (_args?: any): any {}, diff --git a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx index 13018e2e04..465ec6fbce 100644 --- a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx @@ -10,7 +10,7 @@ export interface ChannelsPanelProps { channels: PublicChannel[] unreadChannels: string[] setCurrentChannel: (address: string) => void - currentChannel: string + currentChannelAddress: string createChannelModal: ReturnType } @@ -18,7 +18,7 @@ const ChannelsPanel: React.FC = ({ channels, unreadChannels, setCurrentChannel, - currentChannel, + currentChannelAddress, createChannelModal }) => { return ( @@ -35,7 +35,7 @@ const ChannelsPanel: React.FC = ({ {channels.map((channel, index) => { const unread = unreadChannels.some(address => address === channel.address) - const selected = currentChannel === channel.address + const selected = currentChannelAddress === channel.address return ( { return jest.fn() @@ -47,26 +53,29 @@ describe('clicking in notification', () => { const { store, runSaga } = await prepareStore({}, socket) - const channel = 'sailing' + const generalAddress = generateChannelAddress('general') + const sailingAddress = generateChannelAddress('sailing') const notificationData: NotificationData = { label: 'label', body: 'body', - channel: channel, + channel: sailingAddress, sound: NotificationsSounds.splat } + store.dispatch(publicChannels.actions.setCurrentChannel({ channelAddress: generalAddress })) + // Verify current channel is 'general - expect(publicChannels.selectors.currentChannelAddress(store.getState())).toBe('general') + expect(publicChannels.selectors.currentChannelAddress(store.getState())).toBe(generalAddress) runSaga(function* (): Generator { const notification = yield* call(createNotification, notificationData) - yield* fork(handleNotificationActions, notification, MessageType.Basic, channel) + yield* fork(handleNotificationActions, notification, MessageType.Basic, sailingAddress) yield* call(notification.onclick, new Event('')) }) // Confirm current channel address has changed - expect(publicChannels.selectors.currentChannelAddress(store.getState())).toBe(channel) + expect(publicChannels.selectors.currentChannelAddress(store.getState())).toBe(sailingAddress) }) it('opens file explorer', async () => { @@ -75,7 +84,7 @@ describe('clicking in notification', () => { const { runSaga } = await prepareStore({}, socket) - const channel = 'sailing' + const sailingAddress = generateChannelAddress('sailing') const media: FileMetadata = { cid: 'cid', @@ -84,14 +93,14 @@ describe('clicking in notification', () => { path: 'path/file.ext', message: { id: 'id', - channelAddress: channel + channelAddress: sailingAddress } } const notificationData: NotificationData = { label: 'label', body: 'body', - channel: channel, + channel: sailingAddress, sound: NotificationsSounds.splat } @@ -99,7 +108,7 @@ describe('clicking in notification', () => { runSaga(function* (): Generator { const notification = yield* call(createNotification, notificationData) - yield* fork(handleNotificationActions, notification, MessageType.File, channel, media) + yield* fork(handleNotificationActions, notification, MessageType.File, sailingAddress, media) yield* call(notification.onclick, new Event('')) }) diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts index 95062b0d8f..25f324476e 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts @@ -35,7 +35,8 @@ export function* displayMessageNotificationSaga( ): Generator { const incomingMessages = action.payload.messages - const currentChannel = yield* select(publicChannels.selectors.currentChannel) + const currentChannelAddress = yield* select(publicChannels.selectors.currentChannelAddress) + const currentIdentity = yield* select(identity.selectors.currentIdentity) const certificatesMapping = yield* select(users.selectors.certificatesMapping) @@ -50,7 +51,7 @@ export function* displayMessageNotificationSaga( const focused = yield* call(isWindowFocused) // Do not display notifications for active channel (when the app is in foreground) - if (focused && message.channelAddress === currentChannel.address) return + if (focused && message.channelAddress === currentChannelAddress) return // Do not display notifications for own messages const sender = certificatesMapping[message.pubKey]?.username diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts index e1b2cf9589..f790e65769 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts @@ -98,7 +98,8 @@ beforeAll(async () => { community = await factory.create< ReturnType['payload'] >('Community') - + const generalChannel = publicChannels.selectors.generalChannel(store.getState()) + store.dispatch(publicChannels.actions.setCurrentChannel({ channelAddress: generalChannel.address })) sailingChannel = ( await factory.create['payload']>( 'PublicChannel' diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts index f103674aa8..0b2c96d675 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts @@ -12,6 +12,7 @@ import { formatMessageDisplayDay } from '../../utils/functions/dates/formatMessa import { displayableMessage } from '../../utils/functions/dates/formatDisplayableMessage' import { DisplayableMessage, + INITIAL_CURRENT_CHANNEL_ADDRESS, MessagesDailyGroups, PublicChannel, PublicChannelStatus @@ -86,7 +87,7 @@ export const sortedChannels = createSelector(publicChannels, (channels) => { return sorted }) -export const currentChannelAddress = createSelector( +export const currentChannelAddress_OLD = createSelector( selectState, (state) => { if (!state) return undefined @@ -98,6 +99,26 @@ export const generalChannel = createSelector(publicChannels, publicChannelsSelec return publicChannelsSelector.find(channel => channel.name === 'general') }) +export const currentChannelAddress = createSelector( + selectState, + generalChannel, + (state, general) => { + // KACPER - test for it - IMPORTANT !!!! + if (!state) { + return undefined + } + if (state.currentChannelAddress === INITIAL_CURRENT_CHANNEL_ADDRESS) { + if (general) { + return general.address + } else { + return 'general'// case for tests when is no channel in store + } + } else { + return state.currentChannelAddress + } + } +) + export const recentChannels = createSelector( publicChannels, generalChannel, diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index d60e3accb6..ce57c3e74e 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -25,7 +25,8 @@ import { ChannelDeletionResponsePayload, DeleteChannelFromStorePayload, ClearMessagesCachePayload, - DisableChannelPayload + DisableChannelPayload, + INITIAL_CURRENT_CHANNEL_ADDRESS } from './publicChannels.types' import logger from '../../utils/logger' @@ -33,8 +34,7 @@ import { Identity } from '../identity/identity.types' const log = logger('publicChannels') export class PublicChannelsState { - // KACPER - public currentChannelAddress: string = '' + public currentChannelAddress: string = INITIAL_CURRENT_CHANNEL_ADDRESS public pendingGeneralChannelRecreation: boolean = false @@ -152,6 +152,7 @@ export const publicChannelsSlice = createSlice({ }> ) => { const { message } = action.payload + console.log({ message }) channelMessagesAdapter.addOne( state.channels.entities[message.channelAddress].messages, message diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts index 433749c3b9..1e420f20db 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts @@ -1,6 +1,8 @@ import { Dictionary, EntityState } from '@reduxjs/toolkit' import { FileMetadata } from '../files/files.types' +export const INITIAL_CURRENT_CHANNEL_ADDRESS = 'initialCurrentChannelAddress' + export interface PublicChannel { name: string description: string diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index db29105f5e..d3368998e5 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -1,14 +1,24 @@ import factoryGirl from 'factory-girl' import { CustomReduxAdapter } from './reduxAdapter' import { Store } from '../../sagas/store.types' -import { communities, identity, messages, publicChannels, users, errors, DownloadState } from '../..' import { - createMessageSignatureTestHelper, - createPeerIdTestHelper -} from './helpers' + communities, + identity, + messages, + publicChannels, + users, + errors, + DownloadState +} from '../..' +import { createMessageSignatureTestHelper, createPeerIdTestHelper } from './helpers' import { getCrypto } from 'pkijs' import { stringToArrayBuffer } from 'pvutils' -import { createRootCertificateTestHelper, createUserCertificateTestHelper, keyObjectFromString, verifySignature } from '@quiet/identity' +import { + createRootCertificateTestHelper, + createUserCertificateTestHelper, + keyObjectFromString, + verifySignature +} from '@quiet/identity' import { MessageType, SendingStatus } from '../../sagas/messages/messages.types' import { DateTime } from 'luxon' import { messagesActions } from '../../sagas/messages/messages.slice' @@ -46,7 +56,7 @@ export const getFactory = async (store: Store) => { store.dispatch(communities.actions.setCurrentCommunity(payload.id)) } // Create 'general' channel - await factory.create('PublicChannel', { + await factory.create('PublicChannel', { communityId: payload.id, channel: { name: 'general', @@ -136,15 +146,21 @@ export const getFactory = async (store: Store) => { description: 'Description', timestamp: DateTime.utc().toSeconds(), owner: factory.assoc('Identity', 'nickname'), - address: generateChannelAddress(factory.sequence('PublicChannel.name', n => `publicChannel${n}`).toString()) + address: generateChannelAddress( + factory.sequence('PublicChannel.name', n => `publicChannel${n}`).toString() + ) } }, { afterCreate: async ( payload: ReturnType['payload'] ) => { - await factory.create('PublicChannelsMessagesBase', ({ channelAddress: payload.channel.address })) - await factory.create('PublicChannelSubscription', ({ channelAddress: payload.channel.address })) + await factory.create('PublicChannelsMessagesBase', { + channelAddress: payload.channel.address + }) + await factory.create('PublicChannelSubscription', { + channelAddress: payload.channel.address + }) return payload } } @@ -210,9 +226,11 @@ export const getFactory = async (store: Store) => { afterCreate: async ( payload: ReturnType['payload'] ) => { - store.dispatch(messagesActions.incomingMessages({ - messages: [payload.message] - })) + store.dispatch( + messagesActions.incomingMessages({ + messages: [payload.message] + }) + ) return payload } From 94b1ed6bcf3550f918eb495ff6323a68188a1e64 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 12:37:53 +0200 Subject: [PATCH 15/35] fix sidebar container and story --- .../src/renderer/components/Sidebar/Sidebar.stories.tsx | 2 +- packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx b/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx index 08e06fcd2e..48c574702c 100644 --- a/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx @@ -25,7 +25,7 @@ const Template: ComponentStory = args => { position: 'relative' }}> - + diff --git a/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx b/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx index f97251f980..75ac1fcd87 100644 --- a/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx @@ -17,7 +17,7 @@ const Sidebar = () => { const currentCommunity = useSelector(communities.selectors.currentCommunity) - const currentChannel = useSelector(publicChannels.selectors.currentChannelAddress) + const currentChannelAddress = useSelector(publicChannels.selectors.currentChannelAddress) // Workaround for Redux bug, issue: https://github.com/TryQuiet/quiet/issues/1332 useSelector(publicChannels.selectors.sortedChannels) @@ -40,7 +40,7 @@ const Sidebar = () => { channels: publicChannelsSelector, unreadChannels: unreadChannels, setCurrentChannel: setCurrentChannel, - currentChannel: currentChannel, + currentChannelAddress: currentChannelAddress, createChannelModal: createChannelModal } From ee5c3471dc9af27b0e68fe93993a737a3944d179 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 13:23:15 +0200 Subject: [PATCH 16/35] fix mobile test --- .../ChannelList/ChannelList.screen.tsx | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx index 56eac63fca..70a8197f87 100644 --- a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx +++ b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx @@ -12,6 +12,11 @@ import { formatMessageDisplayDate } from '../../utils/functions/formatMessageDis import { useContextMenu } from '../../hooks/useContextMenu' import { MenuName } from '../../const/MenuNames.enum' +import { PublicChannelStatus } from '@quiet/types' + +interface ChannelMobile extends PublicChannelStatus { + name: string +} export const ChannelListScreen: FC = () => { const dispatch = useDispatch() @@ -33,7 +38,18 @@ export const ChannelListScreen: FC = () => { ) const community = useSelector(communities.selectors.currentCommunity) - const channels = useSelector(publicChannels.selectors.channelsStatusSorted) + const channelsStatusSortedSelector = useSelector(publicChannels.selectors.channelsStatusSorted) + const publicChannelsSelector = useSelector(publicChannels.selectors.publicChannels) + + const channels = channelsStatusSortedSelector.reduce((prev: ChannelMobile[], curr) => { + return [ + ...prev, + { + ...curr, + name: publicChannelsSelector.find(channel => curr.address.includes(channel.name)).name + } + ] + }, []) const tiles = channels.map(status => { const newestMessage = status.newestMessage @@ -44,7 +60,7 @@ export const ChannelListScreen: FC = () => { : undefined const tile: ChannelTileProps = { - name: status.address, + name: status.name, address: status.address, message: message, date: date, From 4ce80687168588623d6d61147467e24810d3da18 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 13:39:18 +0200 Subject: [PATCH 17/35] fix mobile package --- .../mobile/src/screens/ChannelList/ChannelList.screen.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx index 70a8197f87..37c6d63e80 100644 --- a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx +++ b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx @@ -12,11 +12,6 @@ import { formatMessageDisplayDate } from '../../utils/functions/formatMessageDis import { useContextMenu } from '../../hooks/useContextMenu' import { MenuName } from '../../const/MenuNames.enum' -import { PublicChannelStatus } from '@quiet/types' - -interface ChannelMobile extends PublicChannelStatus { - name: string -} export const ChannelListScreen: FC = () => { const dispatch = useDispatch() @@ -41,7 +36,7 @@ export const ChannelListScreen: FC = () => { const channelsStatusSortedSelector = useSelector(publicChannels.selectors.channelsStatusSorted) const publicChannelsSelector = useSelector(publicChannels.selectors.publicChannels) - const channels = channelsStatusSortedSelector.reduce((prev: ChannelMobile[], curr) => { + const channels = channelsStatusSortedSelector.reduce((prev, curr) => { return [ ...prev, { From 418e0e9c3c2bb8626ddd27f7687b6589130961fb Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 17 May 2023 16:47:30 +0200 Subject: [PATCH 18/35] creation and deletion fixes on mobile --- .../screens/CreateChannel/CreateChannel.screen.tsx | 3 ++- .../screens/DeleteChannel/DeleteChannel.screen.tsx | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx index 9d94b1b3ec..14f1248e9d 100644 --- a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx +++ b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx @@ -15,6 +15,7 @@ import { DateTime } from 'luxon' import { navigationSelectors } from '../../store/navigation/navigation.selectors' import { ScreenNames } from '../../const/ScreenNames.enum' import { navigationActions } from '../../store/navigation/navigation.slice' +import { generateChannelAddress } from '@quiet/common' export const CreateChannelScreen: FC = () => { const dispatch = useDispatch() @@ -79,7 +80,7 @@ export const CreateChannelScreen: FC = () => { name: name, description: `Welcome to #${name}`, owner: user.nickname, - address: name, + address: generateChannelAddress(name), timestamp: DateTime.utc().valueOf() } diff --git a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx index 6637223b50..ac57130fd9 100644 --- a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx +++ b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx @@ -9,8 +9,8 @@ import { navigationSelectors } from '../../store/navigation/navigation.selectors export const DeleteChannelScreen: FC = ({ route }) => { const dispatch = useDispatch() -// KACPER - const { channel } = route.params + + const { channel: channelRouteParam } = route.params const channels = useSelector(publicChannels.selectors.publicChannels) @@ -19,18 +19,19 @@ export const DeleteChannelScreen: FC = ({ route }) => console.log({ channels }) useEffect(() => { - if (screen === ScreenNames.DeleteChannelScreen && !channels.find(c => c.name === channel)) { + if (screen === ScreenNames.DeleteChannelScreen && !channels.find(c => c.name === channelRouteParam)) { dispatch(navigationActions.replaceScreen({ screen: ScreenNames.ChannelListScreen })) } }, [dispatch, screen, channels]) const deleteChannel = useCallback(() => { + const deletedChannel = channels.find((channel) => channel.name === channelRouteParam) dispatch( publicChannels.actions.deleteChannel({ - channelAddress: channel + channelAddress: deletedChannel.address }) ) - }, [dispatch]) + }, [dispatch, channels, channelRouteParam]) const handleBackButton = useCallback(() => { dispatch( @@ -42,7 +43,7 @@ export const DeleteChannelScreen: FC = ({ route }) => return ( From bc28939a5b429d17f6adf6f2eb697cc54848db1a Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Thu, 18 May 2023 11:51:06 +0200 Subject: [PATCH 19/35] fix rtl tests --- .../src/rtl-tests/app.restart.test.tsx | 10 ++- ...channel.test.tsx => channel.main.test.tsx} | 87 +++++++++++++++---- .../src/rtl-tests/channel.switch.test.tsx | 61 +++++++++---- .../src/rtl-tests/community.create.test.tsx | 19 +++- 4 files changed, 136 insertions(+), 41 deletions(-) rename packages/desktop/src/rtl-tests/{channel.test.tsx => channel.main.test.tsx} (93%) diff --git a/packages/desktop/src/rtl-tests/app.restart.test.tsx b/packages/desktop/src/rtl-tests/app.restart.test.tsx index e70a99c405..39f80628b3 100644 --- a/packages/desktop/src/rtl-tests/app.restart.test.tsx +++ b/packages/desktop/src/rtl-tests/app.restart.test.tsx @@ -72,12 +72,14 @@ describe('Restart app works correctly', () => { await act(async () => { store.dispatch(network.actions.addInitializedCommunity(community.id)) - store.dispatch(publicChannels.actions.createGeneralChannel()) - const general = store.getState().PublicChannels.channels.entities['general'] + + const entities = store.getState().PublicChannels.channels.entities + + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') store.dispatch( publicChannels.actions.sendInitialChannelMessage({ - channelAddress: general.address, - channelName: general.name + channelAddress: generalAddress, + channelName: 'general' }) ) }) diff --git a/packages/desktop/src/rtl-tests/channel.test.tsx b/packages/desktop/src/rtl-tests/channel.main.test.tsx similarity index 93% rename from packages/desktop/src/rtl-tests/channel.test.tsx rename to packages/desktop/src/rtl-tests/channel.main.test.tsx index 4615e96b07..165b6be7e3 100644 --- a/packages/desktop/src/rtl-tests/channel.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.main.test.tsx @@ -150,6 +150,10 @@ describe('Channel', () => { ReturnType['payload'] >('Community') + const entities = store.getState().PublicChannels.channels.entities + + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) @@ -163,10 +167,18 @@ describe('Channel', () => { const authenticMessage: ChannelMessage = { ...( await factory.build('Message', { - identity: alice + identity: alice, + message: { + id: Math.random().toString(36).substr(2.9), + type: MessageType.Basic, + message: 'message', + createdAt: DateTime.utc().valueOf(), + channelAddress: generalAddress, + signature: '', + pubKey: '' + } }) - ).payload.message, - id: Math.random().toString(36).substr(2.9) + ).payload.message } const spoofedMessage: ChannelMessage = { @@ -231,13 +243,26 @@ describe('Channel', () => { ReturnType['payload'] >('Community') + const entities = store.getState().PublicChannels.channels.entities + + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) const aliceMessage = ( await factory.build('Message', { - identity: alice + identity: alice, + message: { + id: Math.random().toString(36).substr(2.9), + type: MessageType.Basic, + message: 'message', + createdAt: DateTime.utc().valueOf(), + channelAddress: generalAddress, + signature: '', + pubKey: '' + } }) ).payload.message @@ -310,6 +335,10 @@ describe('Channel', () => { ReturnType['payload'] >('Community') + const entities = store.getState().PublicChannels.channels.entities + + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) @@ -318,6 +347,15 @@ describe('Channel', () => { 'Message', { identity: alice, + message: { + id: Math.random().toString(36).substr(2.9), + type: MessageType.Basic, + message: 'message', + createdAt: DateTime.utc().valueOf(), + channelAddress: generalAddress, + signature: '', + pubKey: '' + }, verifyAutomatically: true } ) @@ -435,6 +473,10 @@ describe('Channel', () => { ReturnType['payload'] >('Community') + const entities = store.getState().PublicChannels.channels.entities + + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) @@ -460,7 +502,7 @@ describe('Channel', () => { type: MessageType.Basic, message: msg, createdAt: messagesText.indexOf(msg) + 1, - channelAddress: 'general', + channelAddress: generalAddress, signature: '', pubKey: '' } @@ -704,6 +746,10 @@ describe('Channel', () => { ReturnType['payload'] >('Community') + const entities = initialState.getState().PublicChannels.channels.entities + + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) @@ -746,6 +792,7 @@ describe('Channel', () => { if (action === SocketActionTypes.SEND_MESSAGE) { const data = input as socketEventData<[SendMessagePayload]> const payload = data[0] + console.log({ payload }) return socket.socketClient.emit(SocketActionTypes.INCOMING_MESSAGES, { messages: [payload.message] }) @@ -837,7 +884,10 @@ describe('Channel', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + + const entities = initialState.getState().PublicChannels.channels.entities + + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -846,7 +896,7 @@ describe('Channel', () => { ext: '.jpeg', message: { id: message, - channelAddress: channelAddress + channelAddress: generalAddress }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -860,7 +910,7 @@ describe('Channel', () => { type: MessageType.Image, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelAddress: generalAddress, signature: '', pubKey: '', media: missingFile @@ -1059,7 +1109,8 @@ describe('Channel', () => { >('Identity', { id: community.id, nickname: 'alice' }) const messageId = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const entities = initialState.getState().PublicChannels.channels.entities + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') const media: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -1069,7 +1120,7 @@ describe('Channel', () => { size: AUTODOWNLOAD_SIZE_LIMIT - 1024, message: { id: messageId, - channelAddress: channelAddress + channelAddress: generalAddress } } @@ -1081,7 +1132,7 @@ describe('Channel', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: channelAddress, + channelAddress: generalAddress, signature: '', pubKey: '', media: media @@ -1173,7 +1224,8 @@ describe('Channel', () => { >('Identity', { id: community.id, nickname: 'alice' }) const messageId = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const entities = initialState.getState().PublicChannels.channels.entities + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') const media: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -1183,7 +1235,7 @@ describe('Channel', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: messageId, - channelAddress: channelAddress + channelAddress: generalAddress } } @@ -1195,7 +1247,7 @@ describe('Channel', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: channelAddress, + channelAddress: generalAddress, signature: '', pubKey: '', media: media @@ -1289,7 +1341,8 @@ describe('Channel', () => { >('Identity', { id: community.id, nickname: 'alice' }) const messageId = Math.random().toString(36).substr(2.9) - const channelAddress = 'general' + const entities = initialState.getState().PublicChannels.channels.entities + const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') const media: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -1299,7 +1352,7 @@ describe('Channel', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: messageId, - channelAddress: channelAddress + channelAddress: generalAddress } } @@ -1311,7 +1364,7 @@ describe('Channel', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: channelAddress, + channelAddress: generalAddress, signature: '', pubKey: '', media: media diff --git a/packages/desktop/src/rtl-tests/channel.switch.test.tsx b/packages/desktop/src/rtl-tests/channel.switch.test.tsx index 428022dca3..820236c8a9 100644 --- a/packages/desktop/src/rtl-tests/channel.switch.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.switch.test.tsx @@ -36,14 +36,15 @@ jest.setTimeout(20_000) jest.mock('electron', () => { return { ipcRenderer: { on: () => {}, send: jest.fn(), sendSync: jest.fn() }, - remote: - { + remote: { BrowserWindow: { getAllWindows: () => { - return [{ - show: jest.fn(), - isFocused: jest.fn() - }] + return [ + { + show: jest.fn(), + isFocused: jest.fn() + } + ] } } } @@ -61,6 +62,7 @@ describe('Switch channels', () => { let community: Community let alice: Identity + let generalAddress: string beforeEach(async () => { socket = new MockedSocket() @@ -75,16 +77,17 @@ describe('Switch channels', () => { factory = await getFactory(redux.store) community = await factory.create< - ReturnType['payload'] + ReturnType['payload'] >('Community') alice = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'alice' } ) + const entities = redux.store.getState().PublicChannels.channels.entities + generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') const channelNames = ['memes', 'pets', 'travels'] - // Automatically create channels for (const name of channelNames) { await factory.create['payload']>( @@ -104,8 +107,22 @@ describe('Switch channels', () => { it('Opens another channel', async () => { const generalChannelMessage = await factory.create< - ReturnType['payload'] - >('Message', { identity: alice, verifyAutomatically: true }) + ReturnType['payload'] + >('Message', { + identity: alice, + + message: { + id: (Math.random() * 10 ** 18).toString(36), + type: MessageType.Basic, + message: (Math.random() * 10 ** 18).toString(36), + createdAt: DateTime.utc().valueOf(), + channelAddress: generalAddress, + signature: '', + pubKey: '' + }, + + verifyAutomatically: true + }) window.HTMLElement.prototype.scrollTo = jest.fn() @@ -175,9 +192,11 @@ describe('Switch channels', () => { ) // Set 'general' as active channel - store.dispatch(publicChannels.actions.setCurrentChannel({ - channelAddress: 'general' - })) + store.dispatch( + publicChannels.actions.setCurrentChannel({ + channelAddress: 'general' + }) + ) // Assert channel is not highglighted const memesChannelLink = screen.getByTestId('memes-link-text') @@ -289,9 +308,11 @@ describe('Switch channels', () => { ) // Set 'general' as active channel - store.dispatch(publicChannels.actions.setCurrentChannel({ - channelAddress: 'general' - })) + store.dispatch( + publicChannels.actions.setCurrentChannel({ + channelAddress: 'general' + }) + ) // Assert channel is not highglighted const travelsChannelLink = screen.getByTestId('travels-link-text') @@ -309,9 +330,13 @@ describe('Switch channels', () => { expect(travelsChannelLink).toHaveStyle('opacity: 0.7') // Verify replicated message in present in repository - expect(messages.selectors.validCurrentPublicChannelMessagesEntries(redux.store.getState())[0]).toStrictEqual(message) + expect( + messages.selectors.validCurrentPublicChannelMessagesEntries(redux.store.getState())[0] + ).toStrictEqual(message) // Verify replicated messages was placed in cache - expect(publicChannels.selectors.currentChannelMessages(redux.store.getState())[0]).toStrictEqual(message) + expect( + publicChannels.selectors.currentChannelMessages(redux.store.getState())[0] + ).toStrictEqual(message) // Confirm new message was properly cached and is visible expect(await screen.findByText(message.message)).toBeVisible() diff --git a/packages/desktop/src/rtl-tests/community.create.test.tsx b/packages/desktop/src/rtl-tests/community.create.test.tsx index 29b0437e18..78eb444764 100644 --- a/packages/desktop/src/rtl-tests/community.create.test.tsx +++ b/packages/desktop/src/rtl-tests/community.create.test.tsx @@ -18,16 +18,19 @@ import { Community, InitCommunityPayload, LaunchRegistrarPayload, + publicChannels, RegisterOwnerCertificatePayload, SocketActionTypes } from '@quiet/state-manager' import Channel from '../renderer/components/Channel/Channel' import LoadingPanel from '../renderer/components/LoadingPanel/LoadingPanel' +import { generateChannelAddress } from '@quiet/common' jest.setTimeout(20_000) describe('User', () => { let socket: MockedSocket + const generalAddress = generateChannelAddress('general') beforeEach(() => { socket = new MockedSocket() @@ -100,6 +103,7 @@ describe('User', () => { socket.socketClient.emit(SocketActionTypes.NEW_COMMUNITY, { id: payload.id }) + socket.socketClient.emit(SocketActionTypes.CHANNELS_REPLICATED, { communityId: payload.id, channels: { @@ -108,7 +112,7 @@ describe('User', () => { description: 'string', owner: 'owner', timestamp: 0, - address: 'general' + address: generalAddress } } }) @@ -159,7 +163,10 @@ describe('User', () => { await userEvent.click(createUsernameButton) // Wait for the actions that updates the store - await act(async () => {}) + await act(async () => { + // Little workaround + store.dispatch(publicChannels.actions.setCurrentChannel({ channelAddress: generalAddress })) + }) // Check if create/username modals are gone expect(createCommunityTitle).not.toBeVisible() @@ -200,6 +207,14 @@ describe('User', () => { "Messages/addPublicChannelsMessagesBase", "PublicChannels/clearUnreadChannel", "Modals/closeModal", + "Messages/lazyLoading", + "Messages/resetCurrentPublicChannelCache", + "Messages/resetCurrentPublicChannelCache", + "PublicChannels/setCurrentChannel", + "PublicChannels/clearUnreadChannel", + "Messages/lazyLoading", + "Messages/resetCurrentPublicChannelCache", + "Messages/resetCurrentPublicChannelCache", ] `) }) From 79c3e80fd67b76ddbf9a3a8a060d2b65a6fe565c Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Thu, 18 May 2023 15:26:59 +0200 Subject: [PATCH 20/35] mobile - channel creation and channel deletion fixes --- .../CreateChannel/CreateChannel.screen.tsx | 15 +++++++++++---- .../DeleteChannel/DeleteChannel.screen.tsx | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx index 14f1248e9d..efe12fbf48 100644 --- a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx +++ b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx @@ -20,7 +20,14 @@ import { generateChannelAddress } from '@quiet/common' export const CreateChannelScreen: FC = () => { const dispatch = useDispatch() - const [channel, setChannel] = useState(null) + interface ChannelStructure { + channelName: string | null + channelAddress: string | null + } + const [channel, setChannel] = useState({ + channelAddress: null, + channelName: null + }) const [clearComponent, setClearComponent] = useState(false) // How to clear component without using screen's state? const user = useSelector(identity.selectors.currentIdentity) @@ -35,11 +42,11 @@ export const CreateChannelScreen: FC = () => { useEffect(() => { if ( currentScreen === ScreenNames.CreateChannelScreen && - channels.filter(_channel => _channel.name === channel).length > 0 + channels.filter(_channel => _channel.name === channel.channelName).length > 0 ) { dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: channel + channelAddress: channel.channelAddress }) ) setChannel(null) @@ -84,7 +91,7 @@ export const CreateChannelScreen: FC = () => { timestamp: DateTime.utc().valueOf() } - setChannel(name) + setChannel({ channelAddress: channel.address, channelName: channel.name }) dispatch( publicChannels.actions.createChannel({ diff --git a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx index ac57130fd9..20cfb946bf 100644 --- a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx +++ b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx @@ -10,7 +10,7 @@ import { navigationSelectors } from '../../store/navigation/navigation.selectors export const DeleteChannelScreen: FC = ({ route }) => { const dispatch = useDispatch() - const { channel: channelRouteParam } = route.params + const { channel: channelName } = route.params const channels = useSelector(publicChannels.selectors.publicChannels) @@ -19,19 +19,19 @@ export const DeleteChannelScreen: FC = ({ route }) => console.log({ channels }) useEffect(() => { - if (screen === ScreenNames.DeleteChannelScreen && !channels.find(c => c.name === channelRouteParam)) { + if (screen === ScreenNames.DeleteChannelScreen && !channels.find(c => c.name === channelName)) { dispatch(navigationActions.replaceScreen({ screen: ScreenNames.ChannelListScreen })) } }, [dispatch, screen, channels]) const deleteChannel = useCallback(() => { - const deletedChannel = channels.find((channel) => channel.name === channelRouteParam) + const deletedChannel = channels.find((channel) => channel.name === channelName) dispatch( publicChannels.actions.deleteChannel({ channelAddress: deletedChannel.address }) ) - }, [dispatch, channels, channelRouteParam]) + }, [dispatch, channels, channelName]) const handleBackButton = useCallback(() => { dispatch( @@ -43,7 +43,7 @@ export const DeleteChannelScreen: FC = ({ route }) => return ( From b2d37e2955614e1a8526697c3d84cb257446af26 Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Fri, 19 May 2023 11:20:58 +0200 Subject: [PATCH 21/35] Remove channel deletion leftover --- packages/backend/src/storage/storage.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index b7784d9c4e..df0fc613fd 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -271,15 +271,6 @@ export class Storage extends EventEmitter { channels: this.channels.all as unknown as { [key: string]: PublicChannel } }) - // Delete channel on replication - // Array.from(this.publicChannelsRepos.keys()).forEach(e => { - // const isDeleted = !Object.keys(this.channels.all).includes(e) - // if (isDeleted) { - // log('deleting channel ', e) - // void this.deleteChannel({ channel: e }) - // } - // }) - Object.values(this.channels.all).forEach(async (channel: PublicChannel) => { await this.subscribeToChannel(channel) }) From 321051fb74039c722b13e27ea19f47dc40e0ee73 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Fri, 19 May 2023 11:38:03 +0200 Subject: [PATCH 22/35] refactor channel.address to channel.id --- .../backend/src/libp2p/connectionsManager.ts | 8 +- packages/backend/src/socket/DataServer.ts | 12 +-- .../src/storage/ipfsFileManager.test.ts | 36 +++---- packages/backend/src/storage/storage.test.ts | 19 ++-- packages/backend/src/storage/storage.ts | 100 +++++++++--------- .../src/storage/storageLargeFiles.test.ts | 2 +- .../backend/src/validation/validators.test.ts | 18 ++-- packages/backend/src/validation/validators.ts | 6 +- packages/common/src/channelAddress.ts | 2 +- .../components/Channel/Channel.stories.cy.tsx | 4 +- .../components/Channel/Channel.stories.tsx | 24 ++--- .../renderer/components/Channel/Channel.tsx | 10 +- .../components/Channel/ChannelComponent.tsx | 8 +- .../Channel/CreateChannel/CreateChannel.tsx | 6 +- .../Channel/DeleteChannel/DeleteChannel.tsx | 2 +- .../FileComponent/FileComponent.stories.tsx | 2 +- .../File/FileComponent/FileComponent.test.tsx | 2 +- .../File/UploadedImage/UploadedImage.test.tsx | 4 +- .../components/SearchModal/ChannelItem.tsx | 4 +- .../SearchModal/SearchModal.stories.tsx | 14 +-- .../SearchModal/SearchModal.test.tsx | 7 +- .../components/SearchModal/SearchModal.tsx | 4 +- .../SearchModal/SearchModelComponent.tsx | 4 +- .../ChannelsPanel/ChannelsListItem.tsx | 2 +- .../ChannelsPanel/ChannelsPanel.test.tsx | 8 +- .../Sidebar/ChannelsPanel/ChannelsPanel.tsx | 12 +-- .../components/Sidebar/Sidebar.stories.tsx | 10 +- .../renderer/components/Sidebar/Sidebar.tsx | 8 +- .../ChannelInput/ChannelInput.stories.tsx | 4 +- .../ChannelInput/ChannelInput.test.tsx | 6 +- .../channels/ChannelInput/ChannelInput.tsx | 8 +- .../channels/NestedMessageContent.test.tsx | 6 +- .../widgets/channels/DirectMessageInput.tsx | 4 +- .../directMessages/directMessages.saga.ts | 6 +- .../notifications/notifications.click.test.ts | 24 ++--- .../sagas/notifications/notifications.saga.ts | 16 +-- .../sagas/notifications/notifications.test.ts | 50 ++++----- .../src/rtl-tests/app.restart.test.tsx | 4 +- .../src/rtl-tests/channel.add.test.tsx | 4 +- .../src/rtl-tests/channel.main.test.tsx | 46 ++++---- .../src/rtl-tests/channel.switch.test.tsx | 22 ++-- .../src/rtl-tests/community.create.test.tsx | 8 +- .../src/rtl-tests/community.join.test.tsx | 3 +- .../src/rtl-tests/loadingPanel.test.tsx | 2 +- .../src/rtl-tests/searchModal.test.tsx | 4 +- .../src/integrationTests/appActions.ts | 2 +- .../src/integrationTests/assertions.ts | 2 +- .../src/testUtils/actions.ts | 2 +- .../src/testUtils/assertions.ts | 2 +- .../Notification/NotificationHandler.kt | 2 +- .../ChannelList/ChannelList.stories.tsx | 16 +-- .../ChannelList/ChannelList.test.tsx | 16 +-- .../ChannelTile/ChannelTile.component.tsx | 4 +- .../ChannelTile/ChannelTile.stories.tsx | 8 +- .../ChannelTile/ChannelTile.test.tsx | 4 +- .../ChannelTile/ChannelTile.types.ts | 4 +- .../src/components/Chat/Chat.stories.tsx | 4 +- .../mobile/src/components/Chat/Chat.test.tsx | 2 +- .../src/screens/Channel/Channel.screen.tsx | 4 +- .../ChannelList/ChannelList.screen.tsx | 8 +- .../CreateChannel/CreateChannel.screen.tsx | 12 +-- .../DeleteChannel/DeleteChannel.screen.tsx | 2 +- .../events/nativeServicesCallbacks.ts | 4 +- .../showNotification.saga.test.ts | 4 +- .../autoDownloadFiles.saga.test.ts | 40 +++---- .../autoDownloadFiles.saga.ts | 2 +- .../broadcastHostedFile.saga.test.ts | 16 +-- .../broadcastHostedFile.saga.ts | 4 +- .../checkForMissingFiles.saga.test.ts | 58 +++++----- .../checkForMissingFiles.saga.ts | 2 +- .../downloadFile/downloadFileSaga.test.ts | 2 +- .../src/sagas/files/files.types.ts | 2 +- .../resetTransferSpeed.saga.test.ts | 18 ++-- .../updateMessageMedia.test.ts | 16 +-- .../updateMessageMedia/updateMessageMedia.ts | 4 +- .../files/uploadFile/uploadFile.saga.test.ts | 10 +- .../sagas/files/uploadFile/uploadFile.saga.ts | 4 +- .../askForMessages.saga.test.ts | 2 +- .../checkForMessages.saga.test.ts | 6 +- .../checkForMessages/checkForMessages.saga.ts | 6 +- .../incomingMessages.saga.test.ts | 62 +++++------ .../incomingMessages/incomingMessages.saga.ts | 6 +- .../extendChannelCache.saga.test.ts | 10 +- .../manageCache/extendChannelCache.saga.ts | 6 +- .../resetChannelCache.saga.test.ts | 10 +- .../manageCache/resetChannelCache.saga.ts | 6 +- .../src/sagas/messages/messages.adapter.ts.ts | 2 +- .../sagas/messages/messages.selectors.test.ts | 6 +- .../src/sagas/messages/messages.selectors.ts | 16 +-- .../src/sagas/messages/messages.slice.ts | 18 ++-- .../src/sagas/messages/messages.types.ts | 16 +-- .../sendDeletionMessage.saga.test.ts | 14 +-- .../sendDeletionMessage.saga.ts | 8 +- .../sendMessage/sendMessage.saga.test.ts | 20 ++-- .../messages/sendMessage/sendMessage.saga.ts | 6 +- .../publicChannels.selectors.test.ts.snap | 18 ++-- .../channelDeletionResponse.saga.test.ts | 46 ++++---- .../channelDeletionResponse.saga.ts | 14 +-- .../channelsReplicated.saga.test.ts | 46 ++++---- .../channelsReplicated.saga.ts | 18 ++-- .../createChannel/createChannel.saga.test.ts | 4 +- .../createGeneralChannel.saga.test.ts | 10 +- .../createGeneralChannel.saga.ts | 8 +- .../sendInitialChannelMessage.saga.test.ts | 12 +-- .../sendInitialChannelMessage.saga.ts | 6 +- .../deleteChannel/deleteChannel.saga.test.ts | 20 ++-- .../deleteChannel/deleteChannel.saga.ts | 12 +-- .../markUnreadChannels.saga.test.ts | 34 +++--- .../markUnreadChannels.saga.ts | 14 +-- .../publicChannels/publicChannels.adapter.ts | 6 +- .../publicChannels.selectors.test.ts | 32 +++--- .../publicChannels.selectors.ts | 30 +++--- .../publicChannels/publicChannels.slice.ts | 46 ++++---- .../publicChannels.transform.ts | 4 +- .../publicChannels/publicChannels.types.ts | 34 +++--- .../sendNewUserInfoMessage.saga.test.ts | 8 +- .../sendNewUserInfoMessage.saga.ts | 2 +- .../updateNewestMessage.saga.test.ts | 30 +++--- .../updateNewestMessage.saga.ts | 6 +- .../startConnection/startConnection.saga.ts | 4 +- .../src/utils/tests/factories.ts | 18 ++-- packages/types/src/channel.ts | 26 ++--- packages/types/src/files.ts | 2 +- packages/types/src/message.ts | 16 +-- 124 files changed, 792 insertions(+), 789 deletions(-) diff --git a/packages/backend/src/libp2p/connectionsManager.ts b/packages/backend/src/libp2p/connectionsManager.ts index c883361d6c..295ae18497 100644 --- a/packages/backend/src/libp2p/connectionsManager.ts +++ b/packages/backend/src/libp2p/connectionsManager.ts @@ -566,7 +566,7 @@ export class ConnectionsManager extends EventEmitter { await this.storage?.sendMessage(args.message) }) this.dataServer.on(SocketActionTypes.ASK_FOR_MESSAGES, async (args: AskForMessagesPayload) => { - await this.storage?.askForMessages(args.channelAddress, args.ids) + await this.storage?.askForMessages(args.channelId, args.ids) }) // Files @@ -595,8 +595,8 @@ export class ConnectionsManager extends EventEmitter { }) this.dataServer.on( SocketActionTypes.SEND_DIRECT_MESSAGE, - async (channelAddress: string, messagePayload) => { - await this.storage?.sendDirectMessage(channelAddress, messagePayload) + async (channelId: string, messagePayload) => { + await this.storage?.sendDirectMessage(channelId, messagePayload) } ) this.dataServer.on( @@ -680,7 +680,7 @@ export class ConnectionsManager extends EventEmitter { this.storage.on(StorageEvents.CHECK_FOR_MISSING_FILES, (payload: CommunityId) => { this.io.emit(SocketActionTypes.CHECK_FOR_MISSING_FILES, payload) }) - this.storage.on(StorageEvents.CHANNEL_DELETION_RESPONSE, (payload: {channelAddress: string}) => { + this.storage.on(StorageEvents.CHANNEL_DELETION_RESPONSE, (payload: {channelId: string}) => { console.log('emitting deleted channel event back to state manager') this.io.emit(SocketActionTypes.CHANNEL_DELETION_RESPONSE, payload) }) diff --git a/packages/backend/src/socket/DataServer.ts b/packages/backend/src/socket/DataServer.ts index d4a67500cf..06c7278b12 100644 --- a/packages/backend/src/socket/DataServer.ts +++ b/packages/backend/src/socket/DataServer.ts @@ -90,15 +90,15 @@ export class DataServer extends EventEmitter { SocketActionTypes.SEND_DIRECT_MESSAGE, async ( peerId: string, - { channelAddress, message }: { channelAddress: string; message: string } + { channelId, message }: { channelId: string; message: string } ) => { - this.emit(SocketActionTypes.SEND_DIRECT_MESSAGE, { channelAddress, message }) + this.emit(SocketActionTypes.SEND_DIRECT_MESSAGE, { channelId, message }) } ) socket.on( SocketActionTypes.SUBSCRIBE_FOR_DIRECT_MESSAGE_THREAD, - async (peerId: string, channelAddress: string) => { - this.emit(SocketActionTypes.SUBSCRIBE_FOR_DIRECT_MESSAGE_THREAD, { peerId, channelAddress }) + async (peerId: string, channelId: string) => { + this.emit(SocketActionTypes.SUBSCRIBE_FOR_DIRECT_MESSAGE_THREAD, { peerId, channelId }) } ) socket.on( @@ -156,8 +156,8 @@ export class DataServer extends EventEmitter { log('leaving community') this.emit(SocketActionTypes.LEAVE_COMMUNITY) }) - socket.on(SocketActionTypes.DELETE_CHANNEL, async (payload: {channelAddress: string}) => { - log('deleting channel ', payload.channelAddress) + socket.on(SocketActionTypes.DELETE_CHANNEL, async (payload: {channelId: string}) => { + log('deleting channel ', payload.channelId) this.emit(SocketActionTypes.DELETE_CHANNEL, payload) }) }) diff --git a/packages/backend/src/storage/ipfsFileManager.test.ts b/packages/backend/src/storage/ipfsFileManager.test.ts index 54d6e643d6..f0f7863f4d 100644 --- a/packages/backend/src/storage/ipfsFileManager.test.ts +++ b/packages/backend/src/storage/ipfsFileManager.test.ts @@ -56,7 +56,7 @@ describe('Ipfs file manager', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } @@ -70,7 +70,7 @@ describe('Ipfs file manager', () => { expect(eventSpy).toHaveBeenNthCalledWith(1, StorageEvents.REMOVE_DOWNLOAD_STATUS, { cid: 'uploading_id' }) }) await waitForExpect(() => { - expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) + expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelId: 'channelId', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) ) }) await waitForExpect(() => { @@ -93,7 +93,7 @@ describe('Ipfs file manager', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } @@ -103,7 +103,7 @@ describe('Ipfs file manager', () => { expect(eventSpy).toHaveBeenNthCalledWith(1, StorageEvents.REMOVE_DOWNLOAD_STATUS, { cid: 'uploading_id' }) }) await waitForExpect(() => { - expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-file', size: 761797, width: undefined } + expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelId: 'channelId', id: 'id' }, name: 'test-file', size: 761797, width: undefined } ) ) }) @@ -111,7 +111,7 @@ describe('Ipfs file manager', () => { expect(eventSpy).toHaveBeenNthCalledWith(3, StorageEvents.UPDATE_DOWNLOAD_PROGRESS, { cid: cid, downloadProgress: undefined, downloadState: 'hosted', mid: 'id' }) }) await waitForExpect(() => { - expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-file', size: 761797, width: undefined }) + expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelId: 'channelId', id: 'id' }, name: 'test-file', size: 761797, width: undefined }) ) }) }) @@ -130,7 +130,7 @@ describe('Ipfs file manager', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } @@ -157,7 +157,7 @@ describe('Ipfs file manager', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } @@ -167,13 +167,13 @@ describe('Ipfs file manager', () => { expect(eventSpy).toHaveBeenNthCalledWith(1, StorageEvents.REMOVE_DOWNLOAD_STATUS, { cid: 'uploading_id' }) }) await waitForExpect(() => { - expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-file', size: 761797, width: undefined })) + expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelId: 'channelId', id: 'id' }, name: 'test-file', size: 761797, width: undefined })) }) await waitForExpect(() => { expect(eventSpy).toHaveBeenNthCalledWith(3, StorageEvents.UPDATE_DOWNLOAD_PROGRESS, { cid: cid, downloadProgress: undefined, downloadState: 'hosted', mid: 'id' }) }) await waitForExpect(() => { - expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-file', size: 761797, width: undefined })) + expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelId: 'channelId', id: 'id' }, name: 'test-file', size: 761797, width: undefined })) }) // Downloading @@ -212,7 +212,7 @@ describe('Ipfs file manager', () => { cid, message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } @@ -223,7 +223,7 @@ describe('Ipfs file manager', () => { expect(eventSpy).toHaveBeenNthCalledWith(1, StorageEvents.REMOVE_DOWNLOAD_STATUS, { cid }) }) await waitForExpect(() => { - expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-file', size: 761797, width: undefined }) + expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelId: 'channelId', id: 'id' }, name: 'test-file', size: 761797, width: undefined }) ) }) await waitForExpect(() => { @@ -231,7 +231,7 @@ describe('Ipfs file manager', () => { ) }) await waitForExpect(() => { - expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-file', size: 761797, width: undefined }) + expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.pdf', height: undefined, message: { channelId: 'channelId', id: 'id' }, name: 'test-file', size: 761797, width: undefined }) ) }) @@ -272,7 +272,7 @@ describe('Ipfs file manager', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } @@ -281,13 +281,13 @@ describe('Ipfs file manager', () => { expect(eventSpy).toHaveBeenNthCalledWith(1, StorageEvents.REMOVE_DOWNLOAD_STATUS, { cid: 'uploading_id' } ) - expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) + expect(eventSpy).toHaveBeenNthCalledWith(2, StorageEvents.UPLOADED_FILE, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelId: 'channelId', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) ) expect(eventSpy).toHaveBeenNthCalledWith(3, StorageEvents.UPDATE_DOWNLOAD_PROGRESS, { cid: cid, downloadProgress: undefined, downloadState: 'hosted', mid: 'id' } ) - expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) + expect(eventSpy).toHaveBeenNthCalledWith(4, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelId: 'channelId', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) ) // Downloading @@ -308,7 +308,7 @@ describe('Ipfs file manager', () => { expect(eventSpy).toHaveBeenNthCalledWith(7, StorageEvents.UPDATE_DOWNLOAD_PROGRESS, { cid: cid, downloadProgress: { downloaded: 15863, size: 15847, transferSpeed: 0 }, downloadState: 'completed', mid: 'id' } ) }, 10000) - expect(eventSpy).toHaveBeenNthCalledWith(8, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelAddress: 'channelAddress', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) + expect(eventSpy).toHaveBeenNthCalledWith(8, StorageEvents.UPDATE_MESSAGE_MEDIA, expect.objectContaining({ cid: cid, ext: '.png', height: 44, message: { channelId: 'channelId', id: 'id' }, name: 'test-image', size: 15847, width: 824 }) ) }) it('downloaded file matches uploaded file', async () => { @@ -326,7 +326,7 @@ describe('Ipfs file manager', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } @@ -370,7 +370,7 @@ describe('Ipfs file manager', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } diff --git a/packages/backend/src/storage/storage.test.ts b/packages/backend/src/storage/storage.test.ts index 07c8a51407..51949e5002 100644 --- a/packages/backend/src/storage/storage.test.ts +++ b/packages/backend/src/storage/storage.test.ts @@ -65,7 +65,7 @@ const generateMessageFactoryContent = () => { type: MessageType.Basic, message: (Math.random() * 10 ** 18).toString(36), createdAt: DateTime.utc().valueOf(), - channelAddress: channel.address, + channelId: channel.id, signature: '', pubKey: '' }, @@ -88,7 +88,7 @@ beforeAll(async () => { description: channel.description, owner: channel.owner, timestamp: channel.timestamp, - address: channel.address + id: channel.id } alice = await factory.create( @@ -189,10 +189,10 @@ describe('Channels', () => { const eventSpy = jest.spyOn(storage, 'emit') - await storage.deleteChannel({ channelAddress: channelio.address }) + await storage.deleteChannel({ channelId: channelio.id }) expect(eventSpy).toBeCalledWith('channelDeletionResponse', { - channelAddress: channelio.address + channelId: channelio.id }) }) }) @@ -346,7 +346,8 @@ describe('Certificate', () => { await storage.subscribeToChannel(channelio) const eventSpy = jest.spyOn(storage, 'emit') - const publicChannelRepo = storage.publicChannelsRepos.get(message.channelAddress) + console.log('storage.publicChannelsRepos.get(message.channelId)', storage.publicChannelsRepos.get(message.channelId)) + const publicChannelRepo = storage.publicChannelsRepos.get(message.channelId) expect(publicChannelRepo).not.toBeUndefined() // @ts-expect-error const db = publicChannelRepo.db @@ -405,7 +406,7 @@ describe('Certificate', () => { await storage.subscribeToChannel(channelio) const spyOnEmit = jest.spyOn(storage, 'emit') - const publicChannelRepo = storage.publicChannelsRepos.get(message.channelAddress) + const publicChannelRepo = storage.publicChannelsRepos.get(message.channelId) expect(publicChannelRepo).not.toBeUndefined() // @ts-expect-error const db = publicChannelRepo.db @@ -466,7 +467,7 @@ describe('Message access controller', () => { await storage.subscribeToChannel(channelio) - const publicChannelRepo = storage.publicChannelsRepos.get(message.channelAddress) + const publicChannelRepo = storage.publicChannelsRepos.get(message.channelId) expect(publicChannelRepo).not.toBeUndefined() // @ts-expect-error const db = publicChannelRepo.db @@ -500,7 +501,7 @@ describe('Message access controller', () => { const spoofedMessage = { ...aliceMessage.message, - channelAddress: channelio.address, + channelId: channelio.id, pubKey: johnPublicKey } delete spoofedMessage.media // Media 'undefined' is not accepted by db.add @@ -516,7 +517,7 @@ describe('Message access controller', () => { await storage.subscribeToChannel(channelio) - const publicChannelRepo = storage.publicChannelsRepos.get(message.channelAddress) + const publicChannelRepo = storage.publicChannelsRepos.get(message.channelId) expect(publicChannelRepo).not.toBeUndefined() // @ts-expect-error const db = publicChannelRepo.db diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index b7784d9c4e..ff994094b2 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -364,28 +364,28 @@ export class Storage extends EventEmitter { public async subscribeToChannel(channelData: PublicChannel): Promise { let db: EventStore - let repo = this.publicChannelsRepos.get(channelData.address) + let repo = this.publicChannelsRepos.get(channelData.id) if (repo) { db = repo.db } else { try { db = await this.createChannel(channelData) } catch (e) { - log.error(`Can't subscribe to channel ${channelData.address}`, e.message) + log.error(`Can't subscribe to channel ${channelData.id}`, e.message) return } if (!db) { - log(`Can't subscribe to channel ${channelData.address}`) + log(`Can't subscribe to channel ${channelData.id}`) return } - repo = this.publicChannelsRepos.get(channelData.address) + repo = this.publicChannelsRepos.get(channelData.id) } if (repo && !repo.eventsAttached) { - log('Subscribing to channel ', channelData.address) + log('Subscribing to channel ', channelData.id) db.events.on('write', async (_address, entry) => { - log(`Writing to public channel db ${channelData.address}`) + log(`Writing to public channel db ${channelData.id}`) const verified = await this.verifyMessage(entry.payload.value) this.emit(StorageEvents.LOAD_MESSAGES, { @@ -431,7 +431,7 @@ export class Storage extends EventEmitter { const ids = this.getAllEventLogEntries(db).map(msg => msg.id) this.emit(StorageEvents.SEND_MESSAGES_IDS, { ids, - channelAddress: channelData.address, + channelId: channelData.id, communityId: this.communityId }) }) @@ -439,7 +439,7 @@ export class Storage extends EventEmitter { const ids = this.getAllEventLogEntries(db).map(msg => msg.id) this.emit(StorageEvents.SEND_MESSAGES_IDS, { ids, - channelAddress: channelData.address, + channelId: channelData.id, communityId: this.communityId }) }) @@ -447,14 +447,14 @@ export class Storage extends EventEmitter { repo.eventsAttached = true } - log(`Subscribed to channel ${channelData.address}`) + log(`Subscribed to channel ${channelData.id}`) this.emit(StorageEvents.SET_CHANNEL_SUBSCRIBED, { - channelAddress: channelData.address + channelId: channelData.id }) } - public async askForMessages(channelAddress: string, ids: string[]) { - const repo = this.publicChannelsRepos.get(channelAddress) + public async askForMessages(channelId: string, ids: string[]) { + const repo = this.publicChannelsRepos.get(channelId) if (!repo) return const messages = this.getAllEventLogEntries(repo.db) const filteredMessages: ChannelMessage[] = [] @@ -473,10 +473,10 @@ export class Storage extends EventEmitter { log.error('STORAGE: Invalid channel format') throw new Error('Create channel validation error') } - log(`Creating channel ${data.address}`) + log(`Creating channel ${data.id}`) const db: EventStore = await this.orbitdb.log( - `channels.${data.address}`, + `channels.${data.id}`, { accessController: { type: 'messagesaccess', @@ -485,9 +485,9 @@ export class Storage extends EventEmitter { } ) - const channel = this.channels.get(data.address) + const channel = this.channels.get(data.id) if (channel === undefined) { - await this.channels.put(data.address, { + await this.channels.put(data.id, { ...data }) this.emit(StorageEvents.CREATED_CHANNEL, { @@ -495,27 +495,27 @@ export class Storage extends EventEmitter { }) } - this.publicChannelsRepos.set(data.address, { db, eventsAttached: false }) - log(`Set ${data.address} to local channels`) + this.publicChannelsRepos.set(data.id, { db, eventsAttached: false }) + log(`Set ${data.id} to local channels`) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await db.load({ fetchEntryTimeout: 2000 }) - log(`Created channel ${data.address}`) + log(`Created channel ${data.id}`) return db } - public async deleteChannel(payload: {channelAddress: string}) { - const channelAddress = payload.channelAddress - log('deleteChannel:channelAddress', channelAddress) + public async deleteChannel(payload: {channelId: string}) { + const channelId = payload.channelId + log('deleteChannel:channelId', channelId) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await this.channels.load({ fetchEntryTimeout: 15000 }) - const channel = this.channels.get(channelAddress) + const channel = this.channels.get(channelId) if (channel) { - void this.channels.del(channelAddress) + void this.channels.del(channelId) } - let repo = this.publicChannelsRepos.get(channelAddress) + let repo = this.publicChannelsRepos.get(channelId) if (!repo) { const db = await this.orbitdb.log( - `channels.${channelAddress}`, + `channels.${channelId}`, { accessController: { type: 'messagesaccess', @@ -538,7 +538,7 @@ export class Storage extends EventEmitter { }).filter(isDefined) await this.deleteChannelFiles(files) await this.deleteChannelMessages(hashes) - this.publicChannelsRepos.delete(channelAddress) + this.publicChannelsRepos.delete(channelId) this.emit(StorageEvents.CHANNEL_DELETION_RESPONSE, payload) } @@ -565,10 +565,10 @@ export class Storage extends EventEmitter { log.error('STORAGE: public channel message is invalid') return } - const repo = this.publicChannelsRepos.get(message.channelAddress) + const repo = this.publicChannelsRepos.get(message.channelId) if (!repo) { log.error( - `Could not send message. No '${message.channelAddress}' channel in saved public channels` + `Could not send message. No '${message.channelId}' channel in saved public channels` ) return } @@ -636,58 +636,58 @@ export class Storage extends EventEmitter { ) } - public async subscribeToDirectMessageThread(channelAddress: string) { + public async subscribeToDirectMessageThread(channelId: string) { let db: EventStore - let repo = this.directMessagesRepos.get(channelAddress) + let repo = this.directMessagesRepos.get(channelId) if (repo) { db = repo.db } else { - db = await this.createDirectMessageThread(channelAddress) + db = await this.createDirectMessageThread(channelId) if (!db) { - log(`Can't subscribe to direct messages thread ${channelAddress}`) + log(`Can't subscribe to direct messages thread ${channelId}`) return } - repo = this.directMessagesRepos.get(channelAddress) + repo = this.directMessagesRepos.get(channelId) } if (repo && !repo.eventsAttached) { - log('Subscribing to direct messages thread ', channelAddress) + log('Subscribing to direct messages thread ', channelId) this.emit(StorageEvents.LOAD_ALL_DIRECT_MESSAGES, { messages: this.getAllEventLogEntries(db), - channelAddress + channelId }) db.events.on('write', (_address, _entry) => { log('Writing') this.emit(StorageEvents.LOAD_ALL_DIRECT_MESSAGES, { messages: this.getAllEventLogEntries(db), - channelAddress + channelId }) }) db.events.on('replicated', () => { log('Message replicated') this.emit(StorageEvents.LOAD_ALL_DIRECT_MESSAGES, { messages: this.getAllEventLogEntries(db), - channelAddress + channelId }) }) db.events.on('ready', () => { log('DIRECT Messages thread ready') }) repo.eventsAttached = true - log('Subscription to channel ready', channelAddress) + log('Subscription to channel ready', channelId) } } - private async createDirectMessageThread(channelAddress: string): Promise> { - if (!channelAddress) { - log("No channel address, can't create channel") - throw new Error('No channel address, can\'t create channel') + private async createDirectMessageThread(channelId: string): Promise> { + if (!channelId) { + log("No channel ID, can't create channel") + throw new Error('No channel ID, can\'t create channel') } - log(`creatin direct message thread for ${channelAddress}`) + log(`creatin direct message thread for ${channelId}`) - const db: EventStore = await this.orbitdb.log(`dms.${channelAddress}`, { + const db: EventStore = await this.orbitdb.log(`dms.${channelId}`, { accessController: { write: ['*'] } @@ -698,20 +698,20 @@ export class Storage extends EventEmitter { // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await db.load({ fetchEntryTimeout: 2000 }) - this.directMessagesRepos.set(channelAddress, { db, eventsAttached: false }) + this.directMessagesRepos.set(channelId, { db, eventsAttached: false }) return db } - public async sendDirectMessage(channelAddress: string, message: string) { + public async sendDirectMessage(channelId: string, message: string) { if (!validate.isDirectMessage(message)) { log.error('STORAGE: Invalid direct message format') return } - await this.subscribeToDirectMessageThread(channelAddress) // Is it necessary? Yes it is atm + await this.subscribeToDirectMessageThread(channelId) // Is it necessary? Yes it is atm log('STORAGE: sendDirectMessage entered') - log(`STORAGE: sendDirectMessage channelAddress is ${channelAddress}`) + log(`STORAGE: sendDirectMessage channelId is ${channelId}`) log(`STORAGE: sendDirectMessage message is ${JSON.stringify(message)}`) - const db = this.directMessagesRepos.get(channelAddress)?.db + const db = this.directMessagesRepos.get(channelId)?.db if (!db) return log(`STORAGE: sendDirectMessage db is ${db.address.root}`) log(`STORAGE: sendDirectMessage db is ${db.address.path}`) diff --git a/packages/backend/src/storage/storageLargeFiles.test.ts b/packages/backend/src/storage/storageLargeFiles.test.ts index c61d80cf04..dcb47bf085 100644 --- a/packages/backend/src/storage/storageLargeFiles.test.ts +++ b/packages/backend/src/storage/storageLargeFiles.test.ts @@ -47,7 +47,7 @@ describe('Storage', () => { cid: 'uploading_id', message: { id: 'id', - channelAddress: 'channelAddress' + channelId: 'channelId' } } diff --git a/packages/backend/src/validation/validators.test.ts b/packages/backend/src/validation/validators.test.ts index b96b667df8..23b9ad0ddb 100644 --- a/packages/backend/src/validation/validators.test.ts +++ b/packages/backend/src/validation/validators.test.ts @@ -70,7 +70,7 @@ describe('Validators - Messages', () => { type: 1, message: 'hello', createdAt: 1234567, - channelAddress: '123n23l234lk234', + channelId: '123n23l234lk234', signature: 'asdfasdf', pubKey: 'afsdf' } @@ -82,14 +82,14 @@ describe('Validators - Messages', () => { type: 1, message: 'hello', createdAt: 1234567, - channelAddress: '123n23l234lk234', + channelId: '123n23l234lk234', signature: 'asdfasdf', pubKey: 'afsdf', media: { cid: '123', message: { id: 'fzxjdiasf8ashfisfd', - channelAddress: '123n23l234lk234' + channelId: '123n23l234lk234' }, path: '/path/to/file', name: 'file', @@ -103,7 +103,7 @@ describe('Validators - Messages', () => { type: 1, message: 'hello', createdAt: 1234567, - channelAddress: '123n23l234lk234', + channelId: '123n23l234lk234', signature: 'asdfasdf', pubKey: 'afsdf' } @@ -127,13 +127,13 @@ describe('Validators - Messages', () => { type: 1, message: 'hello', createdAt: 1234567, - channelAddress: '123n23l234lk234', + channelId: '123n23l234lk234', signature: 'asdfasdf', pubKey: 'afsdf', media: { message: { id: 'fzxjdiasf8ashfisfd', - channelAddress: '123n23l234lk234' + channelId: '123n23l234lk234' }, path: '/path/to/file', name: 'file', @@ -151,7 +151,7 @@ describe('Validators - Channels', () => { description: 'quiet', owner: 'szakalakakaaakaka', timestamp: 12341234, - address: 'sadfdasfsadfsdfsnfsdjfdsfsdfjsdf' + id: 'sadfdasfsadfsdfsnfsdjfdsfsdfjsdf' } expect(isChannel(channel)).toBeTruthy() }) @@ -160,7 +160,7 @@ describe('Validators - Channels', () => { name: 'quiet', description: 'quiet', owner: 'szakalakakaaakaka', - address: 'sadfdasfsadfsdfsnfsdjfdsfsdfjsdf' + id: 'sadfdasfsadfsdfsnfsdjfdsfsdfjsdf' } expect(isChannel(channel as unknown as PublicChannel)).toBeFalsy() }) @@ -170,7 +170,7 @@ describe('Validators - Channels', () => { description: 'quiet', owner: 'szakalakakaaakaka', timestamp: 'asfasdf', - address: 'sadfdasfsadfsdfsnfsdjfdsfsdfjsdf' + id: 'sadfdasfsadfsdfsnfsdjfdsfsdfjsdf' } expect(isChannel((channel as unknown) as PublicChannel)).toBeFalsy() }) diff --git a/packages/backend/src/validation/validators.ts b/packages/backend/src/validation/validators.ts index a011bcaff8..6c0696c4d9 100644 --- a/packages/backend/src/validation/validators.ts +++ b/packages/backend/src/validation/validators.ts @@ -14,7 +14,7 @@ const messageMediaSchema = joi.object({ height: joi.number().allow(null), message: joi.object({ id: joi.string().required(), - channelAddress: joi.string().required() + channelId: joi.string().required() }) }) @@ -24,7 +24,7 @@ const messageSchema = joi.object({ message: joi.alternatives(joi.string(), joi.binary()).required(), media: messageMediaSchema, createdAt: joi.number().required(), - channelAddress: joi.string().required(), + channelId: joi.string().required(), signature: joi.string().required(), pubKey: joi.string().required() }) @@ -34,7 +34,7 @@ const channelSchema = joi.object({ description: joi.string().required(), owner: joi.string().required(), timestamp: joi.number().required(), - address: joi.string().required() + id: joi.string().required() }) export const isUser = (publicKey: string, halfKey: string): boolean => { diff --git a/packages/common/src/channelAddress.ts b/packages/common/src/channelAddress.ts index 9f40994521..fbc8531cca 100644 --- a/packages/common/src/channelAddress.ts +++ b/packages/common/src/channelAddress.ts @@ -1,4 +1,4 @@ import crypto from 'crypto' -export const generateChannelAddress = (channelName: String) => +export const generateChannelId = (channelName: String) => `${channelName}_${crypto.randomBytes(16).toString('hex')}` diff --git a/packages/desktop/src/renderer/components/Channel/Channel.stories.cy.tsx b/packages/desktop/src/renderer/components/Channel/Channel.stories.cy.tsx index 6040b06858..7e30236e41 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.stories.cy.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.stories.cy.tsx @@ -46,7 +46,7 @@ const Template: ComponentStory = () => { type: 1, message: 'I agree!', createdAt: 0, - channelAddress: 'general', + channelId: 'general', signature: 'signature', pubKey: 'pubKey' }} @@ -85,7 +85,7 @@ const Template: ComponentStory = () => { handleClose: function (): any {}, src: 'images/butterfly.jpeg' }} - channelAddress={'general'} + channelId={'general'} channelName={'general'} lazyLoading={function (_load: boolean): void {}} onInputChange={function (_value: string): void {}} diff --git a/packages/desktop/src/renderer/components/Channel/Channel.stories.tsx b/packages/desktop/src/renderer/components/Channel/Channel.stories.tsx index 36b6dfc5b5..aa2933cc64 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.stories.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.stories.tsx @@ -52,12 +52,12 @@ const args: Partial = { type: 1, message: 'I agree!', createdAt: 0, - channelAddress: 'general', + channelId: 'general', signature: 'signature', pubKey: 'pubKey' }, pendingMessages: {}, - channelAddress: 'general', + channelId: 'general', channelName: 'general', lazyLoading: function (_load: boolean): void {}, onInputChange: function (_value: string): void {}, @@ -113,7 +113,7 @@ ImagePlaceholder.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.png', @@ -143,7 +143,7 @@ SentImage.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.png', @@ -211,7 +211,7 @@ UploadingFile.args = { media: { cid: 'uploading_32', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', @@ -241,7 +241,7 @@ HostedFile.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', @@ -272,7 +272,7 @@ ReadyDownload.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', @@ -303,7 +303,7 @@ Downloading.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', @@ -338,7 +338,7 @@ CompletedDownload.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', @@ -373,7 +373,7 @@ CancelingDownload.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', @@ -408,7 +408,7 @@ CanceledDownload.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', @@ -439,7 +439,7 @@ MaliciousDownload.args = { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', diff --git a/packages/desktop/src/renderer/components/Channel/Channel.tsx b/packages/desktop/src/renderer/components/Channel/Channel.tsx index 076bb07658..2661d45329 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.tsx @@ -33,7 +33,7 @@ const Channel = () => { const user = useSelector(identity.selectors.currentIdentity) - const currentChannelAddress = useSelector(publicChannels.selectors.currentChannelAddress) + const currentchannelId = useSelector(publicChannels.selectors.currentchannelId) const currentChannelName = useSelector(publicChannels.selectors.currentChannelName) const currentChannelMessagesCount = useSelector( @@ -205,11 +205,11 @@ const Channel = () => { useEffect(() => { dispatch(messages.actions.resetCurrentPublicChannelCache()) - }, [currentChannelAddress]) + }, [currentchannelId]) const channelComponentProps: ChannelComponentProps = { user: user, - channelAddress: currentChannelAddress, + channelId: currentchannelId, channelName: currentChannelName, messages: { count: currentChannelMessagesCount, @@ -245,12 +245,12 @@ const Channel = () => { return ( <> - {currentChannelAddress && ( + {currentchannelId && ( )} diff --git a/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx b/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx index 392c0c146e..a20669430b 100644 --- a/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx +++ b/packages/desktop/src/renderer/components/Channel/ChannelComponent.tsx @@ -41,7 +41,7 @@ const ChannelMessagesWrapperStyled = styled(Grid)(({ theme }) => ({ export interface ChannelComponentProps { user: Identity - channelAddress: string + channelId: string channelName: string messages: { count: number @@ -78,7 +78,7 @@ export const ChannelComponent: React.FC< ChannelComponentProps & UploadFilesPreviewsProps & FileActionsProps > = ({ user, - channelAddress, + channelId, channelName, messages, newestMessage, @@ -213,7 +213,7 @@ export const ChannelComponent: React.FC< useEffect(() => { scrollBottom() - }, [channelAddress]) + }, [channelId]) return ( @@ -244,7 +244,7 @@ export const ChannelComponent: React.FC< { const dispatch = useDispatch() @@ -38,7 +38,7 @@ export const CreateChannel = () => { ) { dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: newChannel.address + channelId: newChannel.id }) ) setNewChannel(null) @@ -73,7 +73,7 @@ export const CreateChannel = () => { name: name, description: `Welcome to #${name}`, owner: user.nickname, - address: generateChannelAddress(name), + id: generateChannelId(name), timestamp: DateTime.utc().valueOf() } flushSync(() => { diff --git a/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.tsx b/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.tsx index 0d8dcb0b3d..2342cd5f80 100644 --- a/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.tsx +++ b/packages/desktop/src/renderer/components/Channel/DeleteChannel/DeleteChannel.tsx @@ -13,7 +13,7 @@ export const DeleteChannel: FC = () => { const dispatch = useDispatch() const deleteChannel = useCallback(() => { - dispatch(publicChannels.actions.deleteChannel({ channelAddress: channel.address })) + dispatch(publicChannels.actions.deleteChannel({ channelId: channel.id })) modal.handleClose() // Close self }, [modal]) diff --git a/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.stories.tsx b/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.stories.tsx index b830e302f7..03d89def3f 100644 --- a/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.stories.tsx +++ b/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.stories.tsx @@ -33,7 +33,7 @@ const args: FileComponentProps = { media: { cid: cid, message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', diff --git a/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.test.tsx b/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.test.tsx index caf60d53f0..68e075227b 100644 --- a/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.test.tsx +++ b/packages/desktop/src/renderer/components/Channel/File/FileComponent/FileComponent.test.tsx @@ -14,7 +14,7 @@ describe('FileComponent', () => { media: { cid: 'QmWUCSApiy76nW9DAk5M9QbH1nkW5XCYwxUHRSULjATyqs', message: { - channelAddress: 'general', + channelId: 'general', id: 'wgtlstx3u7' }, ext: '.zip', diff --git a/packages/desktop/src/renderer/components/Channel/File/UploadedImage/UploadedImage.test.tsx b/packages/desktop/src/renderer/components/Channel/File/UploadedImage/UploadedImage.test.tsx index 2f3376c1d7..d72920b4db 100644 --- a/packages/desktop/src/renderer/components/Channel/File/UploadedImage/UploadedImage.test.tsx +++ b/packages/desktop/src/renderer/components/Channel/File/UploadedImage/UploadedImage.test.tsx @@ -30,7 +30,7 @@ describe('UploadedFile', () => { height: 600, message: { id: 'string', - channelAddress: 'general' + channelId: 'general' } } } @@ -112,7 +112,7 @@ describe('UploadedFile', () => { message.media.path = 'path/to/file/test.png' message.media.message = { id: 'string', - channelAddress: 'general' + channelId: 'general' } const result = renderComponent( diff --git a/packages/desktop/src/renderer/components/SearchModal/ChannelItem.tsx b/packages/desktop/src/renderer/components/SearchModal/ChannelItem.tsx index 1ba138328d..9c582bb314 100644 --- a/packages/desktop/src/renderer/components/SearchModal/ChannelItem.tsx +++ b/packages/desktop/src/renderer/components/SearchModal/ChannelItem.tsx @@ -19,7 +19,7 @@ const ChannelItem = ({ useEnterPress(() => { if (focused) { - onClickHandler(item.address) + onClickHandler(item.id) } }, [focused, channelInput]) @@ -31,7 +31,7 @@ const ChannelItem = ({ })} tabIndex={0} onClick={() => { - onClickHandler(item.address) + onClickHandler(item.id) }}> {`# ${item.name}`} diff --git a/packages/desktop/src/renderer/components/SearchModal/SearchModal.stories.tsx b/packages/desktop/src/renderer/components/SearchModal/SearchModal.stories.tsx index f1e97d0ff5..0da2cfce87 100644 --- a/packages/desktop/src/renderer/components/SearchModal/SearchModal.stories.tsx +++ b/packages/desktop/src/renderer/components/SearchModal/SearchModal.stories.tsx @@ -12,15 +12,15 @@ export const Component = Template.bind({}) const args = { open: true, dynamicSearchedChannelsSelector: [ - { name: 'fun', address: 'fun' }, - { name: 'mobile', address: 'mobile' }, - { name: 'new-york-plans', address: 'new-york-plans' } + { name: 'fun', id: 'fun' }, + { name: 'mobile', id: 'mobile' }, + { name: 'new-york-plans', id: 'new-york-plans' } ], publicChannelsSelector: [ - { name: 'fun', address: 'fun' }, - { name: 'mobile', address: 'mobile' }, - { name: 'new-york-plans', address: 'new-york-plans' }, - { name: 'general', address: 'general' } + { name: 'fun', id: 'fun' }, + { name: 'mobile', id: 'mobile' }, + { name: 'new-york-plans', id: 'new-york-plans' }, + { name: 'general', id: 'general' } ], unreadChannelsSelector: [], channelInput: '' diff --git a/packages/desktop/src/renderer/components/SearchModal/SearchModal.test.tsx b/packages/desktop/src/renderer/components/SearchModal/SearchModal.test.tsx index 6feb244d58..f8307a0204 100644 --- a/packages/desktop/src/renderer/components/SearchModal/SearchModal.test.tsx +++ b/packages/desktop/src/renderer/components/SearchModal/SearchModal.test.tsx @@ -5,6 +5,7 @@ import { prepareStore } from '../../testUtils/prepareStore' import { renderComponent } from '../../testUtils/renderComponent' import { getFactory, publicChannels, communities, identity } from '@quiet/state-manager' import SearchModalComponent from './SearchModelComponent' +import { generateChannelId } from '@quiet/common' describe('Search Modal', () => { let socket: MockedSocket @@ -46,7 +47,7 @@ describe('Search Modal', () => { description: `Welcome to #${channelMock.name}`, timestamp: channelMock.timestamp, owner: alice.nickname, - address: channelMock.name + id: generateChannelId(channelMock.name) } } ) @@ -59,8 +60,8 @@ describe('Search Modal', () => { const result = renderComponent( { const publicChannelsSelector = useSelector(publicChannels.selectors.publicChannels) const setCurrentChannel = useCallback( - (address: string) => { + (id: string) => { dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: address + channelId: id }) ) searchChannelModal.handleClose() diff --git a/packages/desktop/src/renderer/components/SearchModal/SearchModelComponent.tsx b/packages/desktop/src/renderer/components/SearchModal/SearchModelComponent.tsx index 7ebdeea3ef..4bb0e457fa 100644 --- a/packages/desktop/src/renderer/components/SearchModal/SearchModelComponent.tsx +++ b/packages/desktop/src/renderer/components/SearchModal/SearchModelComponent.tsx @@ -165,10 +165,10 @@ const SearchModalComponent: React.FC = ({ const channelList = unread && channelInput.length === 0 ? unreadChannels : dynamicSearchedChannelsSelector - const onChannelClickHandler = (address: string) => { + const onChannelClickHandler = (id: string) => { setChannelInput('') setCurrentFocus(0) - setCurrentChannel(address) + setCurrentChannel(id) } const [focusedIndex, setCurrentFocus] = useCyclingFocus( diff --git a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx index 0793be2a51..47a892968a 100644 --- a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsListItem.tsx @@ -99,7 +99,7 @@ export const ChannelsListItem: React.FC = ({ ref={ref} disableGutters onClick={() => { - setCurrentChannel(channel.address) + setCurrentChannel(channel.id) }} className={classNames(classes.root, { [classes.selected]: selected, diff --git a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx index fb3a3e0064..07a1f09659 100644 --- a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx @@ -6,7 +6,7 @@ import { renderComponent } from '../../../testUtils/renderComponent' import { getFactory, publicChannels, communities, identity } from '@quiet/state-manager' import ChannelsPanel from './ChannelsPanel' import { DateTime } from 'luxon' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('Channels panel', () => { let socket: MockedSocket @@ -44,7 +44,7 @@ describe('Channels panel', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress(name) + id: generateChannelId(name) } } ) @@ -56,8 +56,8 @@ describe('Channels panel', () => { void - currentChannelAddress: string + setCurrentChannel: (id: string) => void + currentchannelId: string createChannelModal: ReturnType } @@ -18,7 +18,7 @@ const ChannelsPanel: React.FC = ({ channels, unreadChannels, setCurrentChannel, - currentChannelAddress, + currentchannelId, createChannelModal }) => { return ( @@ -34,15 +34,15 @@ const ChannelsPanel: React.FC = ({ {channels.map((channel, index) => { - const unread = unreadChannels.some(address => address === channel.address) - const selected = currentChannelAddress === channel.address + const unread = unreadChannels.some(id => id === channel.id) + const selected = currentchannelId === channel.id return ( ) diff --git a/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx b/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx index 48c574702c..7e4aa2bae2 100644 --- a/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/Sidebar.stories.tsx @@ -25,7 +25,7 @@ const Template: ComponentStory = args => { position: 'relative' }}> - + @@ -45,22 +45,22 @@ const args: IdentityPanelProps & ChannelsPanelProps = { channels: [ // @ts-expect-error { - address: 'general', + id: 'general', name: 'general' }, // @ts-expect-error { - address: 'spooky', + id: 'spooky', name: 'spooky' }, // @ts-expect-error { - address: 'kalkan', + id: 'kalkan', name: 'kalkan' } ], unreadChannels: ['spooky'], - setCurrentChannel: function (_address: string): void {}, + setCurrentChannel: function (_id: string): void {}, currentChannel: 'general', createChannelModal: { open: false, diff --git a/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx b/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx index 75ac1fcd87..5946a24ba6 100644 --- a/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx @@ -17,16 +17,16 @@ const Sidebar = () => { const currentCommunity = useSelector(communities.selectors.currentCommunity) - const currentChannelAddress = useSelector(publicChannels.selectors.currentChannelAddress) + const currentchannelId = useSelector(publicChannels.selectors.currentchannelId) // Workaround for Redux bug, issue: https://github.com/TryQuiet/quiet/issues/1332 useSelector(publicChannels.selectors.sortedChannels) const publicChannelsSelector = useSelector(publicChannels.selectors.publicChannels) - const setCurrentChannel = (address: string) => { + const setCurrentChannel = (id: string) => { dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: address + channelId: id }) ) } @@ -40,7 +40,7 @@ const Sidebar = () => { channels: publicChannelsSelector, unreadChannels: unreadChannels, setCurrentChannel: setCurrentChannel, - currentChannelAddress: currentChannelAddress, + currentchannelId: currentchannelId, createChannelModal: createChannelModal } diff --git a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.stories.tsx b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.stories.tsx index 055cbc6346..9dbd3027e3 100644 --- a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.stories.tsx +++ b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.stories.tsx @@ -18,7 +18,7 @@ export const Component = Template.bind({}) export const Disabled = Template.bind({}) const args: ChannelInputProps = { - channelAddress: 'channelAddress', + channelId: 'channelId', channelParticipants: [{ nickname: 'john' }, { nickname: 'emily' }], inputPlaceholder: '#general as @alice', onChange: function (_arg: string): void {}, @@ -32,7 +32,7 @@ const args: ChannelInputProps = { } const argsDisabledInput: ChannelInputProps = { - channelAddress: 'channelAddress', + channelId: 'channelId', channelParticipants: [{ nickname: 'john' }, { nickname: 'emily' }], inputPlaceholder: '#general as @alice', onChange: function (_arg: string): void {}, diff --git a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.test.tsx b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.test.tsx index ccc67d418c..ead1abc4d0 100644 --- a/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.test.tsx +++ b/packages/desktop/src/renderer/components/widgets/channels/ChannelInput/ChannelInput.test.tsx @@ -11,7 +11,7 @@ describe('ChannelInput', () => { it('renders component input available ', () => { const result = renderComponent( { it('renders component input unavailable', () => { const result = renderComponent( { renderComponent( inputPlaceholder: string @@ -221,7 +221,7 @@ export interface ChannelInputProps { } export const ChannelInputComponent: React.FC = ({ - channelAddress, + channelId, channelParticipants = [], inputPlaceholder, inputState = INPUT_STATE.AVAILABLE, @@ -263,7 +263,7 @@ export const ChannelInputComponent: React.FC = ({ React.useEffect(() => { inputRef.current.updater.enqueueForceUpdate(inputRef.current) - }, [inputPlaceholder, channelAddress]) + }, [inputPlaceholder, channelId]) // Use reference to bypass memorization React.useEffect(() => { @@ -295,7 +295,7 @@ export const ChannelInputComponent: React.FC = ({ } } isFirstRenderRef.current = false - }, [channelAddress]) + }, [channelId]) React.useEffect(() => { messageRef.current = message diff --git a/packages/desktop/src/renderer/components/widgets/channels/NestedMessageContent.test.tsx b/packages/desktop/src/renderer/components/widgets/channels/NestedMessageContent.test.tsx index 20228e34d4..431c7dfcbe 100644 --- a/packages/desktop/src/renderer/components/widgets/channels/NestedMessageContent.test.tsx +++ b/packages/desktop/src/renderer/components/widgets/channels/NestedMessageContent.test.tsx @@ -75,7 +75,7 @@ describe('NestedMessageContent', () => { size: AUTODOWNLOAD_SIZE_LIMIT - 2048, message: { id: 'string', - channelAddress: 'general' + channelId: 'general' } } } @@ -138,7 +138,7 @@ describe('NestedMessageContent', () => { size: AUTODOWNLOAD_SIZE_LIMIT - 2048, message: { id: 'string', - channelAddress: 'general' + channelId: 'general' } } } @@ -200,7 +200,7 @@ describe('NestedMessageContent', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 2048, message: { id: 'string', - channelAddress: 'general' + channelId: 'general' } } } diff --git a/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx b/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx index 1dbef7b284..5dc6cfbb96 100644 --- a/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx +++ b/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx @@ -31,13 +31,13 @@ export const ChannelInput = () => { const { onChange, onEnter, resetDebounce } = useDirectMessageInputActions() - const currentChannelAddress = useSelector(publicChannels.selectors.currentChannelAddress) + const currentchannelId = useSelector(publicChannels.selectors.currentchannelId) const currentChannelName = useSelector(publicChannels.selectors.currentChannelName) const user = useSelector(identity.selectors.currentIdentity) return ( { -// return conv.conversationId === action.payload.channelAddress +// return conv.conversationId === action.payload.channelId // }) // const contact = conversation[0] @@ -70,7 +70,7 @@ // ): Generator { // const conversations = yield* select(directMessagesSelectors.conversations) // const conversation = Array.from(Object.values(conversations)).filter(conv => { -// return conv.conversationId === action.payload.channelAddress +// return conv.conversationId === action.payload.channelId // }) // const contact = conversation[0] // const contactPublicKey = contact.contactPublicKey @@ -83,7 +83,7 @@ // const channel = yield* select(contactsSelectors.contact(user.nickname)) // if (!channel) { -// log.error(`Couldn't load all messages. No channel ${action.payload.channelAddress} in contacts`) +// log.error(`Couldn't load all messages. No channel ${action.payload.channelId} in contacts`) // return // } diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.click.test.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.click.test.ts index 1cf4b8ad96..8b0f75620d 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.click.test.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.click.test.ts @@ -15,7 +15,7 @@ import { handleNotificationActions, NotificationData } from './notifications.saga' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' const notification = jest.fn().mockImplementation(() => { return jest.fn() @@ -53,29 +53,29 @@ describe('clicking in notification', () => { const { store, runSaga } = await prepareStore({}, socket) - const generalAddress = generateChannelAddress('general') - const sailingAddress = generateChannelAddress('sailing') + const generalId = generateChannelId('general') + const sailingId = generateChannelId('sailing') const notificationData: NotificationData = { label: 'label', body: 'body', - channel: sailingAddress, + channel: sailingId, sound: NotificationsSounds.splat } - store.dispatch(publicChannels.actions.setCurrentChannel({ channelAddress: generalAddress })) + store.dispatch(publicChannels.actions.setCurrentChannel({ channelId: generalId })) // Verify current channel is 'general - expect(publicChannels.selectors.currentChannelAddress(store.getState())).toBe(generalAddress) + expect(publicChannels.selectors.currentchannelId(store.getState())).toBe(generalId) runSaga(function* (): Generator { const notification = yield* call(createNotification, notificationData) - yield* fork(handleNotificationActions, notification, MessageType.Basic, sailingAddress) + yield* fork(handleNotificationActions, notification, MessageType.Basic, sailingId) yield* call(notification.onclick, new Event('')) }) // Confirm current channel address has changed - expect(publicChannels.selectors.currentChannelAddress(store.getState())).toBe(sailingAddress) + expect(publicChannels.selectors.currentchannelId(store.getState())).toBe(sailingId) }) it('opens file explorer', async () => { @@ -84,7 +84,7 @@ describe('clicking in notification', () => { const { runSaga } = await prepareStore({}, socket) - const sailingAddress = generateChannelAddress('sailing') + const sailingId = generateChannelId('sailing') const media: FileMetadata = { cid: 'cid', @@ -93,14 +93,14 @@ describe('clicking in notification', () => { path: 'path/file.ext', message: { id: 'id', - channelAddress: sailingAddress + channelId: sailingId } } const notificationData: NotificationData = { label: 'label', body: 'body', - channel: sailingAddress, + channel: sailingId, sound: NotificationsSounds.splat } @@ -108,7 +108,7 @@ describe('clicking in notification', () => { runSaga(function* (): Generator { const notification = yield* call(createNotification, notificationData) - yield* fork(handleNotificationActions, notification, MessageType.File, sailingAddress, media) + yield* fork(handleNotificationActions, notification, MessageType.File, sailingId, media) yield* call(notification.onclick, new Event('')) }) diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts index 25f324476e..01deb54e55 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts @@ -35,7 +35,7 @@ export function* displayMessageNotificationSaga( ): Generator { const incomingMessages = action.payload.messages - const currentChannelAddress = yield* select(publicChannels.selectors.currentChannelAddress) + const currentchannelId = yield* select(publicChannels.selectors.currentchannelId) const currentIdentity = yield* select(identity.selectors.currentIdentity) const certificatesMapping = yield* select(users.selectors.certificatesMapping) @@ -51,7 +51,7 @@ export function* displayMessageNotificationSaga( const focused = yield* call(isWindowFocused) // Do not display notifications for active channel (when the app is in foreground) - if (focused && message.channelAddress === currentChannelAddress) return + if (focused && message.channelId === currentchannelId) return // Do not display notifications for own messages const sender = certificatesMapping[message.pubKey]?.username @@ -66,12 +66,12 @@ export function* displayMessageNotificationSaga( // Do not display when message is not verified if (!action.payload.isVerified) return - let label = `New message from @${sender} in #${message.channelAddress}` + let label = `New message from @${sender} in #${message.channelId}` let body = `${message.message.substring(0, 64)}${message.message.length > 64 ? '...' : ''}` // Change notification's label for the image if (message.type === MessageType.Image) { - label = `@${sender} sent an image in #${message.channelAddress}` + label = `@${sender} sent an image in #${message.channelId}` body = undefined } @@ -79,16 +79,16 @@ export function* displayMessageNotificationSaga( if (message.type === MessageType.File) { const status = downloadStatuses[message.id] - label = `@${sender} sends file in #${message.channelAddress}` + label = `@${sender} sends file in #${message.channelId}` body = undefined if (status?.downloadState === DownloadState.Completed) { - label = `@${sender} sent a file in #${message.channelAddress}` + label = `@${sender} sent a file in #${message.channelId}` body = 'Download complete. Click to show file in folder.' } } - const channel = message.channelAddress + const channel = message.channelId const type = message.type const media = message.media @@ -155,7 +155,7 @@ function subscribeNotificationEvents( browserWindow.show() // Emit store action // KACPER - emit(publicChannels.actions.setCurrentChannel({ channelAddress: channel })) + emit(publicChannels.actions.setCurrentChannel({ channelId: channel })) } } return () => {} diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts index f790e65769..13542f247a 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts @@ -99,7 +99,7 @@ beforeAll(async () => { ReturnType['payload'] >('Community') const generalChannel = publicChannels.selectors.generalChannel(store.getState()) - store.dispatch(publicChannels.actions.setCurrentChannel({ channelAddress: generalChannel.address })) + store.dispatch(publicChannels.actions.setCurrentChannel({ channelId: generalChannel.id })) sailingChannel = ( await factory.create['payload']>( 'PublicChannel' @@ -128,7 +128,7 @@ beforeAll(async () => { type: MessageType.Basic, message: 'hello there!', createdAt: lastConnectedTime + 1, - channelAddress: sailingChannel.address, + channelId: sailingChannel.id, signature: '', pubKey: '' } @@ -143,7 +143,7 @@ beforeAll(async () => { type: MessageType.Basic, message: 'how are you?', createdAt: lastConnectedTime + 1, - channelAddress: sailingChannel.address, + channelId: sailingChannel.id, signature: '', pubKey: '' } @@ -183,14 +183,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.address}`, + label: `New message from @${bob.nickname} in #${sailingChannel.id}`, body: message.message, - channel: sailingChannel.address, + channel: sailingChannel.id, sound: NotificationsSounds.pow }) .run() - expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.address}`, { + expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.id}`, { body: message.message, icon: '../../build/icon.png', silent: true @@ -255,7 +255,7 @@ describe('displayNotificationsSaga', () => { test('do not display notification when the user is on the active channel', async () => { store.dispatch( - publicChannels.actions.setCurrentChannel({ channelAddress: sailingChannel.address }) + publicChannels.actions.setCurrentChannel({ channelId: sailingChannel.id }) ) const reducer = combineReducers(reducers) @@ -277,7 +277,7 @@ describe('displayNotificationsSaga', () => { test('notification shows for message in current channel when app window does not have focus', async () => { store.dispatch( - publicChannels.actions.setCurrentChannel({ channelAddress: sailingChannel.address }) + publicChannels.actions.setCurrentChannel({ channelId: sailingChannel.id }) ) const reducer = combineReducers(reducers) @@ -292,14 +292,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.address}`, + label: `New message from @${bob.nickname} in #${sailingChannel.id}`, body: message.message, - channel: sailingChannel.address, + channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.address}`, { + expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.id}`, { body: message.message, icon: '../../build/icon.png', silent: true @@ -308,7 +308,7 @@ describe('displayNotificationsSaga', () => { test('notification shows for message in non-active channel when app window has focus', async () => { store.dispatch( - publicChannels.actions.setCurrentChannel({ channelAddress: 'general' }) + publicChannels.actions.setCurrentChannel({ channelId: 'general' }) ) const reducer = combineReducers(reducers) @@ -323,14 +323,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), true]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.address}`, + label: `New message from @${bob.nickname} in #${sailingChannel.id}`, body: message.message, - channel: sailingChannel.address, + channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.address}`, { + expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.id}`, { body: message.message, icon: '../../build/icon.png', silent: true @@ -415,9 +415,9 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.address}`, + label: `New message from @${bob.nickname} in #${sailingChannel.id}`, body: message.message, - channel: sailingChannel.address, + channel: sailingChannel.id, sound: NotificationsSounds.none }) .run() @@ -463,7 +463,7 @@ describe('displayNotificationsSaga', () => { ext: '.png', message: { id: message.id, - channelAddress: message.channelAddress + channelId: message.channelId } } } @@ -477,14 +477,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `@${bob.nickname} sent an image in #${sailingChannel.address}`, + label: `@${bob.nickname} sent an image in #${sailingChannel.id}`, body: undefined, - channel: sailingChannel.address, + channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`@${bob.nickname} sent an image in #${sailingChannel.address}`, { + expect(notification).toBeCalledWith(`@${bob.nickname} sent an image in #${sailingChannel.id}`, { body: undefined, icon: '../../build/icon.png', silent: true @@ -504,7 +504,7 @@ describe('displayNotificationsSaga', () => { ext: '.ext', message: { id: message.id, - channelAddress: message.channelAddress + channelId: message.channelId } } } @@ -518,14 +518,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `@${bob.nickname} sends file in #${sailingChannel.address}`, + label: `@${bob.nickname} sends file in #${sailingChannel.id}`, body: undefined, - channel: sailingChannel.address, + channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`@${bob.nickname} sends file in #${sailingChannel.address}`, { + expect(notification).toBeCalledWith(`@${bob.nickname} sends file in #${sailingChannel.id}`, { body: undefined, icon: '../../build/icon.png', silent: true diff --git a/packages/desktop/src/rtl-tests/app.restart.test.tsx b/packages/desktop/src/rtl-tests/app.restart.test.tsx index 39f80628b3..28ee718514 100644 --- a/packages/desktop/src/rtl-tests/app.restart.test.tsx +++ b/packages/desktop/src/rtl-tests/app.restart.test.tsx @@ -75,10 +75,10 @@ describe('Restart app works correctly', () => { const entities = store.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') store.dispatch( publicChannels.actions.sendInitialChannelMessage({ - channelAddress: generalAddress, + channelId: generalId, channelName: 'general' }) ) diff --git a/packages/desktop/src/rtl-tests/channel.add.test.tsx b/packages/desktop/src/rtl-tests/channel.add.test.tsx index b59c860ab9..d62f93f583 100644 --- a/packages/desktop/src/rtl-tests/channel.add.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.add.test.tsx @@ -106,7 +106,7 @@ describe('Add new channel', () => { if (action === SocketActionTypes.SEND_MESSAGE) { const data = input as socketEventData<[SendMessagePayload]> const { message } = data[0] - expect(message.channelAddress).toEqual(channelName.output) + expect(message.channelId).toEqual(channelName.output) expect(message.message).toEqual(`Created #${channelName.output}`) return socket.socketClient.emit(SocketActionTypes.INCOMING_MESSAGES, { messages: [message], @@ -315,7 +315,7 @@ describe('Add new channel', () => { if (action === SocketActionTypes.SEND_MESSAGE) { const data = input as socketEventData<[SendMessagePayload]> const { message } = data[0] - expect(message.channelAddress).toEqual(channelName) + expect(message.channelId).toEqual(channelName) expect(message.message).toEqual(`Created #${channelName}`) return socket.socketClient.emit(SocketActionTypes.INCOMING_MESSAGES, { messages: [message], diff --git a/packages/desktop/src/rtl-tests/channel.main.test.tsx b/packages/desktop/src/rtl-tests/channel.main.test.tsx index 165b6be7e3..25d9eb0817 100644 --- a/packages/desktop/src/rtl-tests/channel.main.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.main.test.tsx @@ -152,7 +152,7 @@ describe('Channel', () => { const entities = store.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const alice = await factory.create< ReturnType['payload'] @@ -173,7 +173,7 @@ describe('Channel', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '' } @@ -245,7 +245,7 @@ describe('Channel', () => { const entities = store.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const alice = await factory.create< ReturnType['payload'] @@ -259,7 +259,7 @@ describe('Channel', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '' } @@ -337,7 +337,7 @@ describe('Channel', () => { const entities = store.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const alice = await factory.create< ReturnType['payload'] @@ -352,7 +352,7 @@ describe('Channel', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '' }, @@ -475,7 +475,7 @@ describe('Channel', () => { const entities = store.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const alice = await factory.create< ReturnType['payload'] @@ -502,7 +502,7 @@ describe('Channel', () => { type: MessageType.Basic, message: msg, createdAt: messagesText.indexOf(msg) + 1, - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '' } @@ -610,7 +610,7 @@ describe('Channel', () => { it('renders a multi-line message', async () => { renderComponent( { it.skip('traverses a multi-line message it with arrow keys', async () => { renderComponent( { const entities = initialState.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const alice = await factory.create< ReturnType['payload'] @@ -887,7 +887,7 @@ describe('Channel', () => { const entities = initialState.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -896,7 +896,7 @@ describe('Channel', () => { ext: '.jpeg', message: { id: message, - channelAddress: generalAddress + channelId: generalId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -910,7 +910,7 @@ describe('Channel', () => { type: MessageType.Image, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '', media: missingFile @@ -1110,7 +1110,7 @@ describe('Channel', () => { const messageId = Math.random().toString(36).substr(2.9) const entities = initialState.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const media: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -1120,7 +1120,7 @@ describe('Channel', () => { size: AUTODOWNLOAD_SIZE_LIMIT - 1024, message: { id: messageId, - channelAddress: generalAddress + channelId: generalId } } @@ -1132,7 +1132,7 @@ describe('Channel', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '', media: media @@ -1225,7 +1225,7 @@ describe('Channel', () => { const messageId = Math.random().toString(36).substr(2.9) const entities = initialState.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const media: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -1235,7 +1235,7 @@ describe('Channel', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: messageId, - channelAddress: generalAddress + channelId: generalId } } @@ -1247,7 +1247,7 @@ describe('Channel', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '', media: media @@ -1342,7 +1342,7 @@ describe('Channel', () => { const messageId = Math.random().toString(36).substr(2.9) const entities = initialState.getState().PublicChannels.channels.entities - const generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + const generalId = Object.keys(entities).find(key => entities[key].name === 'general') const media: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -1352,7 +1352,7 @@ describe('Channel', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: messageId, - channelAddress: generalAddress + channelId: generalId } } @@ -1364,7 +1364,7 @@ describe('Channel', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '', media: media diff --git a/packages/desktop/src/rtl-tests/channel.switch.test.tsx b/packages/desktop/src/rtl-tests/channel.switch.test.tsx index 820236c8a9..96d1fd646f 100644 --- a/packages/desktop/src/rtl-tests/channel.switch.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.switch.test.tsx @@ -62,7 +62,7 @@ describe('Switch channels', () => { let community: Community let alice: Identity - let generalAddress: string + let generalId: string beforeEach(async () => { socket = new MockedSocket() @@ -85,7 +85,7 @@ describe('Switch channels', () => { { id: community.id, nickname: 'alice' } ) const entities = redux.store.getState().PublicChannels.channels.entities - generalAddress = Object.keys(entities).find(key => entities[key].name === 'general') + generalId = Object.keys(entities).find(key => entities[key].name === 'general') const channelNames = ['memes', 'pets', 'travels'] // Automatically create channels @@ -98,7 +98,7 @@ describe('Switch channels', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: name + id: name } } ) @@ -116,7 +116,7 @@ describe('Switch channels', () => { type: MessageType.Basic, message: (Math.random() * 10 ** 18).toString(36), createdAt: DateTime.utc().valueOf(), - channelAddress: generalAddress, + channelId: generalId, signature: '', pubKey: '' }, @@ -161,11 +161,11 @@ describe('Switch channels', () => { }) it('Highlights channel with unread messages and removes the highlight when entered', async () => { - const messagesAddresses = ['memes', 'pets'] + const messagesIds = ['memes', 'pets'] const messages: ChannelMessage[] = [] // Automatically create messages - for (const address of messagesAddresses) { + for (const id of messagesIds) { const message = ( await factory.build('Message', { identity: alice, @@ -174,7 +174,7 @@ describe('Switch channels', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: address, + channelId: id, signature: '', pubKey: '' }, @@ -194,7 +194,7 @@ describe('Switch channels', () => { // Set 'general' as active channel store.dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: 'general' + channelId: 'general' }) ) @@ -239,7 +239,7 @@ describe('Switch channels', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: 'general', + channelId: 'general', signature: '', pubKey: '' }, @@ -289,7 +289,7 @@ describe('Switch channels', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: 'travels', + channelId: 'travels', signature: '', pubKey: '' }, @@ -310,7 +310,7 @@ describe('Switch channels', () => { // Set 'general' as active channel store.dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: 'general' + channelId: 'general' }) ) diff --git a/packages/desktop/src/rtl-tests/community.create.test.tsx b/packages/desktop/src/rtl-tests/community.create.test.tsx index 78eb444764..db29118ad6 100644 --- a/packages/desktop/src/rtl-tests/community.create.test.tsx +++ b/packages/desktop/src/rtl-tests/community.create.test.tsx @@ -24,13 +24,13 @@ import { } from '@quiet/state-manager' import Channel from '../renderer/components/Channel/Channel' import LoadingPanel from '../renderer/components/LoadingPanel/LoadingPanel' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' jest.setTimeout(20_000) describe('User', () => { let socket: MockedSocket - const generalAddress = generateChannelAddress('general') + const generalId = generateChannelId('general') beforeEach(() => { socket = new MockedSocket() @@ -112,7 +112,7 @@ describe('User', () => { description: 'string', owner: 'owner', timestamp: 0, - address: generalAddress + id: generalId } } }) @@ -165,7 +165,7 @@ describe('User', () => { // Wait for the actions that updates the store await act(async () => { // Little workaround - store.dispatch(publicChannels.actions.setCurrentChannel({ channelAddress: generalAddress })) + store.dispatch(publicChannels.actions.setCurrentChannel({ channelId: generalId })) }) // Check if create/username modals are gone diff --git a/packages/desktop/src/rtl-tests/community.join.test.tsx b/packages/desktop/src/rtl-tests/community.join.test.tsx index 1557cc0739..19b343d84d 100644 --- a/packages/desktop/src/rtl-tests/community.join.test.tsx +++ b/packages/desktop/src/rtl-tests/community.join.test.tsx @@ -29,6 +29,7 @@ import { import Channel from '../renderer/components/Channel/Channel' import LoadingPanel from '../renderer/components/LoadingPanel/LoadingPanel' import { createUserCertificateTestHelper } from '@quiet/identity' +import { generateChannelId } from '@quiet/common' jest.setTimeout(20_000) @@ -131,7 +132,7 @@ describe('User', () => { description: 'string', owner: 'owner', timestamp: 0, - address: 'general' + id: 'general' } } }) diff --git a/packages/desktop/src/rtl-tests/loadingPanel.test.tsx b/packages/desktop/src/rtl-tests/loadingPanel.test.tsx index bc4766af28..672fdb0043 100644 --- a/packages/desktop/src/rtl-tests/loadingPanel.test.tsx +++ b/packages/desktop/src/rtl-tests/loadingPanel.test.tsx @@ -98,7 +98,7 @@ describe('Loading panel', () => { description: 'Welcome to #general', timestamp: DateTime.utc().valueOf(), owner: 'owner', - address: 'general' + id: 'general' } }) ).payload diff --git a/packages/desktop/src/rtl-tests/searchModal.test.tsx b/packages/desktop/src/rtl-tests/searchModal.test.tsx index 12f483340b..074ae84ea5 100644 --- a/packages/desktop/src/rtl-tests/searchModal.test.tsx +++ b/packages/desktop/src/rtl-tests/searchModal.test.tsx @@ -98,7 +98,7 @@ describe('Switch channels', () => { description: `Welcome to #${channelMock.name}`, timestamp: channelMock.timestamp, owner: alice.nickname, - address: channelMock.name + id: channelMock.name } } ) @@ -197,7 +197,7 @@ describe('Switch channels', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: 'fun', + channelId: 'fun', signature: '', pubKey: '' }, diff --git a/packages/integration-tests/src/integrationTests/appActions.ts b/packages/integration-tests/src/integrationTests/appActions.ts index 5ea50bfa8b..e4b2442e41 100644 --- a/packages/integration-tests/src/integrationTests/appActions.ts +++ b/packages/integration-tests/src/integrationTests/appActions.ts @@ -251,7 +251,7 @@ export async function sendMessage( if (channelName) { store.dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: channelName + channelId: channelName }) ) } diff --git a/packages/integration-tests/src/integrationTests/assertions.ts b/packages/integration-tests/src/integrationTests/assertions.ts index a7e180a17e..b10dfaa6b1 100644 --- a/packages/integration-tests/src/integrationTests/assertions.ts +++ b/packages/integration-tests/src/integrationTests/assertions.ts @@ -40,7 +40,7 @@ export async function assertReceivedChannelsAndSubscribe( store.dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: store.getState().PublicChannels.channels.ids[0] as string + channelId: store.getState().PublicChannels.channels.ids[0] as string }) ) diff --git a/packages/integration-tests/src/testUtils/actions.ts b/packages/integration-tests/src/testUtils/actions.ts index 440358d40b..641d028bf6 100644 --- a/packages/integration-tests/src/testUtils/actions.ts +++ b/packages/integration-tests/src/testUtils/actions.ts @@ -180,7 +180,7 @@ export const switchChannel = async ({ channelName, store }) => { const communityId = store.getState().Communities.communities.ids[0] store.dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: channelName + channelId: channelName }) ) } diff --git a/packages/integration-tests/src/testUtils/assertions.ts b/packages/integration-tests/src/testUtils/assertions.ts index 455a7949f5..e8d93aa841 100644 --- a/packages/integration-tests/src/testUtils/assertions.ts +++ b/packages/integration-tests/src/testUtils/assertions.ts @@ -35,7 +35,7 @@ export async function assertReceivedChannel( store.dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: store.getState().PublicChannels.channels.ids[0] as string + channelId: store.getState().PublicChannels.channels.ids[0] as string }) ) diff --git a/packages/mobile/android/app/src/main/java/com/quietmobile/Notification/NotificationHandler.kt b/packages/mobile/android/app/src/main/java/com/quietmobile/Notification/NotificationHandler.kt index 239cec55dd..9ca2109df2 100644 --- a/packages/mobile/android/app/src/main/java/com/quietmobile/Notification/NotificationHandler.kt +++ b/packages/mobile/android/app/src/main/java/com/quietmobile/Notification/NotificationHandler.kt @@ -35,7 +35,7 @@ class NotificationHandler(private val context: Context) { try { // Parse channel name - val _channel = _message.getString("channelAddress") + val _channel = _message.getString("channelId") channel = String.format("#%s", _channel) // Parse message content val _content = _message.getString("message") diff --git a/packages/mobile/src/components/ChannelList/ChannelList.stories.tsx b/packages/mobile/src/components/ChannelList/ChannelList.stories.tsx index 4975f96c3f..60dd2a254e 100644 --- a/packages/mobile/src/components/ChannelList/ChannelList.stories.tsx +++ b/packages/mobile/src/components/ChannelList/ChannelList.stories.tsx @@ -12,39 +12,39 @@ storiesOf('ChannelList', module).add('Default', () => ( tiles={[ { name: 'general', - address: 'general', + id: 'general', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: '1:55pm', unread: false, - redirect: (address: string) => { console.log(`Clicked ${address}`) } + redirect: (id: string) => { console.log(`Clicked ${id}`) } }, { name: 'spam', - address: 'spam', + id: 'spam', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: '1:55pm', unread: false, - redirect: (address: string) => { console.log(`Clicked ${address}`) } + redirect: (id: string) => { console.log(`Clicked ${id}`) } }, { name: 'design', - address: 'design', + id: 'design', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: '6/1/22', unread: true, - redirect: (address: string) => { console.log(`Clicked ${address}`) } + redirect: (id: string) => { console.log(`Clicked ${id}`) } }, { name: 'qa', - address: 'qa', + id: 'qa', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: 'Yesterday', unread: false, - redirect: (address: string) => { console.log(`Clicked ${address}`) } + redirect: (id: string) => { console.log(`Clicked ${id}`) } } ]} /> diff --git a/packages/mobile/src/components/ChannelList/ChannelList.test.tsx b/packages/mobile/src/components/ChannelList/ChannelList.test.tsx index d113aada77..00f48e3b04 100644 --- a/packages/mobile/src/components/ChannelList/ChannelList.test.tsx +++ b/packages/mobile/src/components/ChannelList/ChannelList.test.tsx @@ -14,7 +14,7 @@ describe('ChannelList component', () => { tiles={[ { name: 'general', - address: 'general', + id: 'general', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: '1:55pm', @@ -23,7 +23,7 @@ describe('ChannelList component', () => { }, { name: 'spam', - address: 'spam', + id: 'spam', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: '1:55pm', @@ -32,7 +32,7 @@ describe('ChannelList component', () => { }, { name: 'design', - address: 'design', + id: 'design', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: '6/1/22', @@ -41,7 +41,7 @@ describe('ChannelList component', () => { }, { name: 'qa', - address: 'design', + id: 'design', message: 'Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.', date: 'Yesterday', @@ -188,32 +188,32 @@ describe('ChannelList component', () => { data={ [ { - "address": "general", "date": "1:55pm", + "id": "general", "message": "Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.", "name": "general", "redirect": [MockFunction], "unread": false, }, { - "address": "spam", "date": "1:55pm", + "id": "spam", "message": "Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.", "name": "spam", "redirect": [MockFunction], "unread": false, }, { - "address": "design", "date": "6/1/22", + "id": "design", "message": "Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.", "name": "design", "redirect": [MockFunction], "unread": true, }, { - "address": "design", "date": "Yesterday", + "id": "design", "message": "Text from latest chat message. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Id massa venenatis id eget massa commodo posuere faucibus aliquam. At scelerisque nisi mauris facilisis.", "name": "qa", "redirect": [MockFunction], diff --git a/packages/mobile/src/components/ChannelTile/ChannelTile.component.tsx b/packages/mobile/src/components/ChannelTile/ChannelTile.component.tsx index efe5cd6a8d..da52ee7b83 100644 --- a/packages/mobile/src/components/ChannelTile/ChannelTile.component.tsx +++ b/packages/mobile/src/components/ChannelTile/ChannelTile.component.tsx @@ -8,7 +8,7 @@ import { ChannelTileProps } from './ChannelTile.types' export const ChannelTile: FC = ({ name, - address, + id, message, date, unread, @@ -45,7 +45,7 @@ export const ChannelTile: FC = ({ { - redirect(address) + redirect(id) }}> ( { console.log(`Clicked ${address}`) }} + redirect={(id: string) => { console.log(`Clicked ${id}`) }} /> )) .add('Unread', () => ( { console.log(`Clicked ${address}`) }} + redirect={(id: string) => { console.log(`Clicked ${id}`) }} /> )) diff --git a/packages/mobile/src/components/ChannelTile/ChannelTile.test.tsx b/packages/mobile/src/components/ChannelTile/ChannelTile.test.tsx index 050a32808d..463ac665ec 100644 --- a/packages/mobile/src/components/ChannelTile/ChannelTile.test.tsx +++ b/packages/mobile/src/components/ChannelTile/ChannelTile.test.tsx @@ -8,7 +8,7 @@ describe('ChannelList component', () => { const { toJSON } = renderComponent( { const { toJSON } = renderComponent( void + redirect: (id: string) => void } diff --git a/packages/mobile/src/components/Chat/Chat.stories.tsx b/packages/mobile/src/components/Chat/Chat.stories.tsx index 45bd027eeb..c29d66d50b 100644 --- a/packages/mobile/src/components/Chat/Chat.stories.tsx +++ b/packages/mobile/src/components/Chat/Chat.stories.tsx @@ -20,7 +20,7 @@ storiesOf('Chat', module) description: '', owner: '', timestamp: 0, - address: '' + id: '' }} messages={{ count: 16, @@ -203,7 +203,7 @@ storiesOf('Chat', module) description: '', owner: '', timestamp: 0, - address: '' + id: '' }} user={'holmes'} /> diff --git a/packages/mobile/src/components/Chat/Chat.test.tsx b/packages/mobile/src/components/Chat/Chat.test.tsx index e21b647e1f..38025c9d44 100644 --- a/packages/mobile/src/components/Chat/Chat.test.tsx +++ b/packages/mobile/src/components/Chat/Chat.test.tsx @@ -27,7 +27,7 @@ describe('Chat component', () => { description: '', owner: '', timestamp: 0, - address: '' + id: '' }} pendingMessages={{}} messages={{ diff --git a/packages/mobile/src/screens/Channel/Channel.screen.tsx b/packages/mobile/src/screens/Channel/Channel.screen.tsx index 342eab2b45..a4b7086d4d 100644 --- a/packages/mobile/src/screens/Channel/Channel.screen.tsx +++ b/packages/mobile/src/screens/Channel/Channel.screen.tsx @@ -27,7 +27,7 @@ export const ChannelScreen: FC = () => { ) dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: '' // Necessary for marking channels as unread on channel's list + channelId: '' // Necessary for marking channels as unread on channel's list }) ) return true @@ -88,7 +88,7 @@ export const ChannelScreen: FC = () => { useEffect(() => { dispatch(messages.actions.resetCurrentPublicChannelCache()) - }, [currentChannel?.address]) + }, [currentChannel?.id]) const [imagePreview, setImagePreview] = useState(null) diff --git a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx index 37c6d63e80..73cfcfd1f1 100644 --- a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx +++ b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx @@ -17,10 +17,10 @@ export const ChannelListScreen: FC = () => { const dispatch = useDispatch() const redirect = useCallback( - (address: string) => { + (id: string) => { dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: address + channelId: id }) ) dispatch( @@ -41,7 +41,7 @@ export const ChannelListScreen: FC = () => { ...prev, { ...curr, - name: publicChannelsSelector.find(channel => curr.address.includes(channel.name)).name + name: publicChannelsSelector.find(channel => curr.id.includes(channel.name)).name } ] }, []) @@ -56,7 +56,7 @@ export const ChannelListScreen: FC = () => { const tile: ChannelTileProps = { name: status.name, - address: status.address, + id: status.id, message: message, date: date, unread: status.unread, diff --git a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx index efe12fbf48..9c2a4c456c 100644 --- a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx +++ b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx @@ -15,17 +15,17 @@ import { DateTime } from 'luxon' import { navigationSelectors } from '../../store/navigation/navigation.selectors' import { ScreenNames } from '../../const/ScreenNames.enum' import { navigationActions } from '../../store/navigation/navigation.slice' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' export const CreateChannelScreen: FC = () => { const dispatch = useDispatch() interface ChannelStructure { channelName: string | null - channelAddress: string | null + channelId: string | null } const [channel, setChannel] = useState({ - channelAddress: null, + channelId: null, channelName: null }) const [clearComponent, setClearComponent] = useState(false) // How to clear component without using screen's state? @@ -46,7 +46,7 @@ export const CreateChannelScreen: FC = () => { ) { dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: channel.channelAddress + channelId: channel.channelId }) ) setChannel(null) @@ -87,11 +87,11 @@ export const CreateChannelScreen: FC = () => { name: name, description: `Welcome to #${name}`, owner: user.nickname, - address: generateChannelAddress(name), + id: generateChannelId(name), timestamp: DateTime.utc().valueOf() } - setChannel({ channelAddress: channel.address, channelName: channel.name }) + setChannel({ channelId: channel.id, channelName: channel.name }) dispatch( publicChannels.actions.createChannel({ diff --git a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx index 20cfb946bf..a0dd9879e6 100644 --- a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx +++ b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx @@ -28,7 +28,7 @@ export const DeleteChannelScreen: FC = ({ route }) => const deletedChannel = channels.find((channel) => channel.name === channelName) dispatch( publicChannels.actions.deleteChannel({ - channelAddress: deletedChannel.address + channelId: deletedChannel.id }) ) }, [dispatch, channels, channelName]) diff --git a/packages/mobile/src/store/nativeServices/events/nativeServicesCallbacks.ts b/packages/mobile/src/store/nativeServices/events/nativeServicesCallbacks.ts index 1e6b49c963..35604e884f 100644 --- a/packages/mobile/src/store/nativeServices/events/nativeServicesCallbacks.ts +++ b/packages/mobile/src/store/nativeServices/events/nativeServicesCallbacks.ts @@ -49,9 +49,9 @@ export const deviceEvents = () => { ), nativeEventEmitter?.addListener( NativeEventKeys.Notification, - (channelAddress: string) => { + (channelId: string) => { // Change data source in state-manager - emit(publicChannels.actions.setCurrentChannel({ channelAddress })) + emit(publicChannels.actions.setCurrentChannel({ channelId })) // Redirect to proper screen in the application emit(navigationActions.navigation({ screen: ScreenNames.ChannelScreen })) } diff --git a/packages/mobile/src/store/nativeServices/showNotification/showNotification.saga.test.ts b/packages/mobile/src/store/nativeServices/showNotification/showNotification.saga.test.ts index 3c6c36f9ab..b38388310f 100644 --- a/packages/mobile/src/store/nativeServices/showNotification/showNotification.saga.test.ts +++ b/packages/mobile/src/store/nativeServices/showNotification/showNotification.saga.test.ts @@ -19,9 +19,9 @@ describe('showNotificationSaga', () => { beforeAll(async () => { payload = { - channelAddress: 'channelAddress', + channelId: 'channelId', message: { - channelAddress: 'address', + channelId: 'address', createdAt: 0, id: 'id', message: 'message', diff --git a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts index aad798c49c..7b8a796fb0 100644 --- a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts +++ b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts @@ -19,7 +19,7 @@ import { publicChannelsActions } from '../../publicChannels/publicChannels.slice import { DateTime } from 'luxon' import { FileMetadata } from '../files.types' import { AUTODOWNLOAD_SIZE_LIMIT } from '../../../constants' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadFileSaga', () => { @@ -57,7 +57,7 @@ describe('downloadFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress('sailing') + id: generateChannelId('sailing') } } )).channel @@ -69,7 +69,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id })) const media: FileMetadata = { @@ -79,7 +79,7 @@ describe('downloadFileSaga', () => { ext: 'png', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -93,7 +93,7 @@ describe('downloadFileSaga', () => { type: MessageType.Image, message: 'message', createdAt: 8, - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: 'signature', pubKey: 'publicKey', media: media @@ -118,7 +118,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id })) const media: FileMetadata = { @@ -128,7 +128,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -142,7 +142,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: 'message', createdAt: 8, - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: 'signature', pubKey: 'publicKey', media: media @@ -167,7 +167,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id })) const media: FileMetadata = { @@ -177,7 +177,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -190,7 +190,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: media @@ -223,7 +223,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: sailingChannel.address + channelId: sailingChannel.id })) const media: FileMetadata = { @@ -233,7 +233,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -246,7 +246,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: media @@ -279,7 +279,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id })) const media: FileMetadata = { @@ -290,7 +290,7 @@ describe('downloadFileSaga', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -304,7 +304,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: 'message', createdAt: 8, - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: 'signature', pubKey: 'publicKey', media: media @@ -329,7 +329,7 @@ describe('downloadFileSaga', () => { const id = Math.random().toString(36).substr(2.9) store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id })) const media: FileMetadata = { @@ -340,7 +340,7 @@ describe('downloadFileSaga', () => { size: AUTODOWNLOAD_SIZE_LIMIT + 1024, message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -354,7 +354,7 @@ describe('downloadFileSaga', () => { type: MessageType.Image, message: 'message', createdAt: 8, - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: 'signature', pubKey: 'publicKey', media: media diff --git a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.ts b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.ts index 5e1c78ce72..2c892fb39f 100644 --- a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.ts +++ b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.ts @@ -23,7 +23,7 @@ export function* autoDownloadFilesSaga( if (message.type !== MessageType.Image && message.type !== MessageType.File) return const channelMessages = yield* select( - messagesSelectors.publicChannelMessagesEntities(message.channelAddress) + messagesSelectors.publicChannelMessagesEntities(message.channelId) ) const draft = channelMessages[message.id] diff --git a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts index c2808a208c..4acd0f65b9 100644 --- a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts +++ b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.test.ts @@ -16,7 +16,7 @@ import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' import { FileMetadata } from '../files.types' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadFileSaga', () => { @@ -54,7 +54,7 @@ describe('downloadFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress('sailing') + id: generateChannelId('sailing') } } ) @@ -65,7 +65,7 @@ describe('downloadFileSaga', () => { const socket = { emit: jest.fn() } as unknown as Socket store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id })) const id = Math.random().toString(36).substr(2.9) @@ -77,7 +77,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -91,7 +91,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: media @@ -124,7 +124,7 @@ describe('downloadFileSaga', () => { const socket = { emit: jest.fn() } as unknown as Socket store.dispatch(publicChannelsActions.setCurrentChannel({ - channelAddress: sailingChannel.address + channelId: sailingChannel.id })) const id = Math.random().toString(36).substr(2.9) @@ -136,7 +136,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -150,7 +150,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: media diff --git a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.ts b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.ts index 021bf4eae5..ea5cf68434 100644 --- a/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.ts +++ b/packages/state-manager/src/sagas/files/broadcastHostedFile/broadcastHostedFile.saga.ts @@ -15,14 +15,14 @@ export function* broadcastHostedFileSaga( const identity = yield* select(identitySelectors.currentIdentity) const channelMessages = yield* select( - messagesSelectors.publicChannelMessagesEntities(action.payload.message.channelAddress) + messagesSelectors.publicChannelMessagesEntities(action.payload.message.channelId) ) const message = channelMessages[action.payload.message.id] if (!message || !instanceOfChannelMessage(message)) { console.error( - `Cannot broadcast message after uploading. Draft ${action.payload.message.id} from #${action.payload.message.channelAddress} does not exist in local storage.` + `Cannot broadcast message after uploading. Draft ${action.payload.message.id} from #${action.payload.message.channelId} does not exist in local storage.` ) return } diff --git a/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts b/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts index 0eee5c8f17..5c4054109d 100644 --- a/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts +++ b/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.test.ts @@ -42,7 +42,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -51,7 +51,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.jpeg', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -65,7 +65,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.Image, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile @@ -124,7 +124,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -133,7 +133,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -147,7 +147,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile @@ -208,7 +208,7 @@ describe('checkForMissingFilesSaga', () => { const message1 = Math.random().toString(36).substr(2.9) const message2 = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFileCanceled: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -217,7 +217,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message1, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -229,7 +229,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message2, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -243,7 +243,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFileCanceled @@ -260,7 +260,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFilePending @@ -341,7 +341,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -350,7 +350,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT + 2048 } @@ -364,7 +364,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile @@ -423,7 +423,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -432,7 +432,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT + 2048 } @@ -446,7 +446,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile @@ -504,7 +504,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const generalChannel = publicChannelsSelectors.generalChannel(initialState.getState()) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -513,7 +513,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -527,7 +527,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile @@ -586,7 +586,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -595,7 +595,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -609,7 +609,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile @@ -668,7 +668,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), @@ -677,7 +677,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: AUTODOWNLOAD_SIZE_LIMIT - 2048 } @@ -691,7 +691,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile @@ -750,7 +750,7 @@ describe('checkForMissingFilesSaga', () => { >('Identity', { id: community.id, nickname: 'alice' }) const message = Math.random().toString(36).substr(2.9) - const channelAddress = generalChannel.address + const channelId = generalChannel.id const missingFile: FileMetadata = { cid: Math.random().toString(36).substr(2.9), path: null, @@ -758,7 +758,7 @@ describe('checkForMissingFilesSaga', () => { ext: '.zip', message: { id: message, - channelAddress: channelAddress + channelId: channelId }, size: size } @@ -772,7 +772,7 @@ describe('checkForMissingFilesSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: missingFile diff --git a/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.ts b/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.ts index 39e1a8e81c..3775e091c2 100644 --- a/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.ts +++ b/packages/state-manager/src/sagas/files/checkForMissingFiles/checkForMissingFiles.saga.ts @@ -28,7 +28,7 @@ export function* checkForMissingFilesSaga( const downloadStatuses = yield* select(filesSelectors.downloadStatuses) for (const channel of channels) { - const missingFiles = yield* select(missingChannelFiles(channel.address)) + const missingFiles = yield* select(missingChannelFiles(channel.id)) if (missingFiles.length > 0) { for (const file of missingFiles) { diff --git a/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts b/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts index 50475906ec..a2fd481f07 100644 --- a/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts +++ b/packages/state-manager/src/sagas/files/downloadFile/downloadFileSaga.test.ts @@ -59,7 +59,7 @@ describe('downloadFileSaga', () => { ext: 'ext', message: { id: message, - channelAddress: generalChannel.address + channelId: generalChannel.id } } diff --git a/packages/state-manager/src/sagas/files/files.types.ts b/packages/state-manager/src/sagas/files/files.types.ts index 0167c582ff..b6d0cbebbe 100644 --- a/packages/state-manager/src/sagas/files/files.types.ts +++ b/packages/state-manager/src/sagas/files/files.types.ts @@ -14,7 +14,7 @@ export interface FileMetadata extends FileContent { export interface FileMessage { id: string - channelAddress: string + channelId: string } export interface UploadFilePayload { diff --git a/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts b/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts index a442f63929..197a1b6ee0 100644 --- a/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts +++ b/packages/state-manager/src/sagas/files/resetTransferSpeed/resetTransferSpeed.saga.test.ts @@ -48,7 +48,7 @@ describe('downloadFileSaga', () => { test('reset transfer speed for files with existing transfer speed', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -60,7 +60,7 @@ describe('downloadFileSaga', () => { ext: 'zip', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -75,7 +75,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: media @@ -118,7 +118,7 @@ describe('downloadFileSaga', () => { test('do not reset transfer speed for files without existing transfer speed', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -130,7 +130,7 @@ describe('downloadFileSaga', () => { ext: 'zip', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -145,7 +145,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: media @@ -183,7 +183,7 @@ describe('downloadFileSaga', () => { test('do not reset transfer speed for files with download state other than downloading', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -195,7 +195,7 @@ describe('downloadFileSaga', () => { ext: 'zip', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -210,7 +210,7 @@ describe('downloadFileSaga', () => { type: MessageType.File, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: media diff --git a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts index 5538bfb3ba..282a7708c6 100644 --- a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts +++ b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.test.ts @@ -14,7 +14,7 @@ import { updateMessageMediaSaga } from './updateMessageMedia' import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' describe('downloadedFileSaga', () => { @@ -55,7 +55,7 @@ describe('downloadedFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress('sailing') + id: generateChannelId('sailing') } } ) @@ -65,7 +65,7 @@ describe('downloadedFileSaga', () => { test('update message media', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: 'general' + channelId: 'general' }) ) @@ -78,7 +78,7 @@ describe('downloadedFileSaga', () => { ext: 'png', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -92,7 +92,7 @@ describe('downloadedFileSaga', () => { type: MessageType.Basic, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: metadata @@ -122,7 +122,7 @@ describe('downloadedFileSaga', () => { test('update message media for non-active channel', async () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: sailingChannel.address + channelId: sailingChannel.id }) ) @@ -135,7 +135,7 @@ describe('downloadedFileSaga', () => { ext: 'png', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -149,7 +149,7 @@ describe('downloadedFileSaga', () => { type: MessageType.Basic, message: '', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '', media: metadata diff --git a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.ts b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.ts index a37e19cff9..4301c5de56 100644 --- a/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.ts +++ b/packages/state-manager/src/sagas/files/updateMessageMedia/updateMessageMedia.ts @@ -9,14 +9,14 @@ export function* updateMessageMediaSaga( action: PayloadAction['payload']> ): Generator { const channelMessages = yield* select( - messagesSelectors.publicChannelMessagesEntities(action.payload.message.channelAddress) + messagesSelectors.publicChannelMessagesEntities(action.payload.message.channelId) ) const message = channelMessages[action.payload.message.id] if (!message || !instanceOfChannelMessage(message)) { console.error( - `Cannot update message media. Message ${action.payload.message.id} from #${action.payload.message.channelAddress} does not exist in local storage.` + `Cannot update message media. Message ${action.payload.message.id} from #${action.payload.message.channelId} does not exist in local storage.` ) return } diff --git a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts index 53414f664c..093018f125 100644 --- a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts +++ b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts @@ -16,13 +16,13 @@ import { uploadFileSaga } from './uploadFile.saga' import { FactoryGirl } from 'factory-girl' import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' -import { currentChannelAddress } from '../../publicChannels/publicChannels.selectors' +import { currentchannelId } from '../../publicChannels/publicChannels.selectors' import { DownloadState, FileMetadata } from '../../files/files.types' import { filesActions } from '../files.slice' import { generateMessageId } from '../../messages/utils/message.utils' import { DateTime } from 'luxon' import { messagesActions } from '../../messages/messages.slice' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('uploadFileSaga', () => { let store: Store @@ -59,7 +59,7 @@ describe('uploadFileSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress('sailing') + id: generateChannelId('sailing') } } )).channel @@ -70,7 +70,7 @@ describe('uploadFileSaga', () => { test('uploading file', async () => { const socket = { emit: jest.fn() } as unknown as Socket - const currentChannel = currentChannelAddress(store.getState()) + const currentChannel = currentchannelId(store.getState()) const peerId = alice.peerId.id @@ -81,7 +81,7 @@ describe('uploadFileSaga', () => { ext: 'ext', message: { id: message, - channelAddress: currentChannel + channelId: currentChannel } } const reducer = combineReducers(reducers) diff --git a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts index febc8cfd68..835a803ef6 100644 --- a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts +++ b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts @@ -16,7 +16,7 @@ export function* uploadFileSaga( ): Generator { const identity = yield* select(identitySelectors.currentIdentity) - const currentChannel = yield* select(publicChannelsSelectors.currentChannelAddress) + const currentChannel = yield* select(publicChannelsSelectors.currentchannelId) const id = yield* call(generateMessageId) @@ -25,7 +25,7 @@ export function* uploadFileSaga( cid: `uploading_${id}`, message: { id: id, - channelAddress: currentChannel + channelId: currentChannel } } diff --git a/packages/state-manager/src/sagas/messages/askForMessages/askForMessages.saga.test.ts b/packages/state-manager/src/sagas/messages/askForMessages/askForMessages.saga.test.ts index 4732f5c5b9..a100387e0e 100644 --- a/packages/state-manager/src/sagas/messages/askForMessages/askForMessages.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/askForMessages/askForMessages.saga.test.ts @@ -12,7 +12,7 @@ describe('askForMessagesSaga', () => { const askForMessagesPayload: AskForMessagesPayload = { peerId: '', communityId: '', - channelAddress: '', + channelId: '', ids: [] } const saga: TestApi = testSaga( diff --git a/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts b/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts index c44d545970..f5cf72ff28 100644 --- a/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts @@ -60,7 +60,7 @@ describe('checkForMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -74,7 +74,7 @@ describe('checkForMessagesSaga', () => { checkForMessagesSaga, messagesActions.responseSendMessagesIds({ ids: [message.id, 'jf84hwwa', 'kl12sa0a'], - channelAddress: generalChannel.address, + channelId: generalChannel.id, communityId: community.id }) ) @@ -84,7 +84,7 @@ describe('checkForMessagesSaga', () => { messagesActions.askForMessages({ peerId: alice.peerId.id, communityId: community.id, - channelAddress: generalChannel.address, + channelId: generalChannel.id, ids: ['jf84hwwa', 'kl12sa0a'] }) ) diff --git a/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.ts b/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.ts index 7a9be6c7c7..ae00ac46fe 100644 --- a/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.ts +++ b/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.ts @@ -8,20 +8,20 @@ import { currentCommunity } from '../../communities/communities.selectors' import { currentIdentity } from '../../identity/identity.selectors' export function* checkForMessagesSaga(action: PayloadAction['payload']>): Generator { - const { ids, channelAddress } = action.payload + const { ids, channelId } = action.payload const community = yield* select(currentCommunity) const identity = yield* select(currentIdentity) - const missingMessages = yield* select(missingChannelMessages(ids, channelAddress)) + const missingMessages = yield* select(missingChannelMessages(ids, channelId)) if (missingMessages?.length > 0) { yield* put( messagesActions.askForMessages({ peerId: identity.peerId.id, communityId: community.id, - channelAddress: channelAddress, + channelId: channelId, ids: missingMessages }) ) diff --git a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts index f868e839c1..c16fe108e5 100644 --- a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.test.ts @@ -19,7 +19,7 @@ import { incomingMessagesSaga } from './incomingMessages.saga' import { messagesActions } from '../messages.slice' import { reducers } from '../../reducers' import { FileMetadata } from '../../files/files.types' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('incomingMessagesSaga', () => { let store: Store @@ -59,7 +59,7 @@ describe('incomingMessagesSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress('sailing') + id: generateChannelId('sailing') } } ) @@ -74,7 +74,7 @@ describe('incomingMessagesSaga', () => { description: 'Welcome to #barbeque', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress('barbeque') + id: generateChannelId('barbeque') } } ) @@ -90,7 +90,7 @@ describe('incomingMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -101,7 +101,7 @@ describe('incomingMessagesSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -120,7 +120,7 @@ describe('incomingMessagesSaga', () => { .put( publicChannelsActions.cacheMessages({ messages: [message], - channelAddress: message.channelAddress + channelId: message.channelId }) ) .run() @@ -137,7 +137,7 @@ describe('incomingMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -152,7 +152,7 @@ describe('incomingMessagesSaga', () => { ext: 'png', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } } @@ -164,7 +164,7 @@ describe('incomingMessagesSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -172,7 +172,7 @@ describe('incomingMessagesSaga', () => { store.dispatch( publicChannelsActions.cacheMessages({ messages: [message], - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -197,7 +197,7 @@ describe('incomingMessagesSaga', () => { .put( publicChannelsActions.cacheMessages({ messages: [message], - channelAddress: message.channelAddress + channelId: message.channelId }) ) .run() @@ -214,7 +214,7 @@ describe('incomingMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, media: { cid: 'uploading', path: 'path/to/image.png', @@ -222,7 +222,7 @@ describe('incomingMessagesSaga', () => { ext: 'png', message: { id: id, - channelAddress: generalChannel.address + channelId: generalChannel.id } }, signature: '', @@ -235,7 +235,7 @@ describe('incomingMessagesSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -243,7 +243,7 @@ describe('incomingMessagesSaga', () => { store.dispatch( publicChannelsActions.cacheMessages({ messages: [message], - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -273,7 +273,7 @@ describe('incomingMessagesSaga', () => { path: 'path/to/image.png' } }], - channelAddress: message.channelAddress + channelId: message.channelId }) ) .run() @@ -288,7 +288,7 @@ describe('incomingMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: sailingChannel.address, + channelId: sailingChannel.id, signature: '', pubKey: '' }, @@ -299,7 +299,7 @@ describe('incomingMessagesSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -315,7 +315,7 @@ describe('incomingMessagesSaga', () => { .not.put( publicChannelsActions.cacheMessages({ messages: [message], - channelAddress: message.channelAddress + channelId: message.channelId }) ) .run() @@ -330,7 +330,7 @@ describe('incomingMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -350,7 +350,7 @@ describe('incomingMessagesSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -366,7 +366,7 @@ describe('incomingMessagesSaga', () => { .not.put( publicChannelsActions.cacheMessages({ messages: [message], - channelAddress: message.channelAddress + channelId: message.channelId }) ) .run() @@ -382,7 +382,7 @@ describe('incomingMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf() - DateTime.utc().minus({ days: 1 }).valueOf(), - channelAddress: barbequeChannel.address, + channelId: barbequeChannel.id, signature: '', pubKey: '' }, @@ -393,7 +393,7 @@ describe('incomingMessagesSaga', () => { // Set 'barbeque' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: barbequeChannel.address + channelId: barbequeChannel.id }) ) @@ -411,7 +411,7 @@ describe('incomingMessagesSaga', () => { message: 'message', createdAt: DateTime.utc().valueOf() + DateTime.utc().minus({ minutes: index }).valueOf(), - channelAddress: barbequeChannel.address, + channelId: barbequeChannel.id, signature: '', pubKey: '' }, @@ -429,7 +429,7 @@ describe('incomingMessagesSaga', () => { 'CacheMessages', { messages: messages, - channelAddress: barbequeChannel.address + channelId: barbequeChannel.id } ) @@ -465,7 +465,7 @@ describe('incomingMessagesSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf() - DateTime.utc().minus({ days: 1 }).valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -476,7 +476,7 @@ describe('incomingMessagesSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -494,7 +494,7 @@ describe('incomingMessagesSaga', () => { message: 'message', createdAt: DateTime.utc().valueOf() + DateTime.utc().minus({ minutes: index }).valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -512,7 +512,7 @@ describe('incomingMessagesSaga', () => { 'CacheMessages', { messages: messages, - channelAddress: generalChannel.address + channelId: generalChannel.id } ) @@ -536,7 +536,7 @@ describe('incomingMessagesSaga', () => { .put( publicChannelsActions.cacheMessages({ messages: updatedCache, - channelAddress: message.channelAddress + channelId: message.channelId }) ) .run() diff --git a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts index aabf493a46..1cb768b054 100644 --- a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts +++ b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts @@ -11,8 +11,8 @@ export function* incomingMessagesSaga( ): Generator { for (const incomingMessage of action.payload.messages) { // Proceed only for messages from current channel - const currentChannelAddress = yield* select(publicChannelsSelectors.currentChannelAddress) - if (incomingMessage.channelAddress !== currentChannelAddress) { + const currentchannelId = yield* select(publicChannelsSelectors.currentchannelId) + if (incomingMessage.channelId !== currentchannelId) { return } @@ -75,7 +75,7 @@ export function* incomingMessagesSaga( const cacheMessagesPayload: CacheMessagesPayload = { messages: cachedMessages, - channelAddress: message.channelAddress + channelId: message.channelId } yield* put(publicChannelsActions.cacheMessages(cacheMessagesPayload)) diff --git a/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.test.ts b/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.test.ts index 112d40bdb9..fb4ff93dcf 100644 --- a/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.test.ts @@ -52,7 +52,7 @@ describe('extendCurrentPublicChannelCacheSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -72,7 +72,7 @@ describe('extendCurrentPublicChannelCacheSaga', () => { message: 'message', createdAt: DateTime.utc().valueOf() + DateTime.utc().minus({ minutes: index }).valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -91,7 +91,7 @@ describe('extendCurrentPublicChannelCacheSaga', () => { 'CacheMessages', { messages: messages.slice(0, 50), - channelAddress: generalChannel.address + channelId: generalChannel.id } ) @@ -114,12 +114,12 @@ describe('extendCurrentPublicChannelCacheSaga', () => { .put( publicChannelsActions.cacheMessages({ messages: updatedCache, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .put( messagesActions.setDisplayedMessagesNumber({ - channelAddress: generalChannel.address, + channelId: generalChannel.id, display: 100 }) ) diff --git a/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts b/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts index 8396f56874..4dbda3bb9c 100644 --- a/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts +++ b/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts @@ -9,7 +9,7 @@ import { SetDisplayedMessagesNumberPayload } from '../messages.types' export function* extendCurrentPublicChannelCacheSaga(): Generator { const communityId = yield* select(communitiesSelectors.currentCommunityId) - const channelAddress = yield* select(publicChannelsSelectors.currentChannelAddress) + const channelId = yield* select(publicChannelsSelectors.currentchannelId) const channelMessagesChunkSize = 50 @@ -29,7 +29,7 @@ export function* extendCurrentPublicChannelCacheSaga(): Generator { const cacheMessagesPayload: CacheMessagesPayload = { messages: messages, - channelAddress: channelAddress + channelId: channelId } yield* put(publicChannelsActions.cacheMessages(cacheMessagesPayload)) @@ -41,7 +41,7 @@ export function* extendCurrentPublicChannelCacheSaga(): Generator { } const setDisplayedMessagesNumberPayload: SetDisplayedMessagesNumberPayload = { - channelAddress: channelAddress, + channelId: channelId, display: display } diff --git a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts index 3d44bb0604..e30f65dc78 100644 --- a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts @@ -51,7 +51,7 @@ describe('resetChannelCacheSaga', () => { // Set 'general' as active channel store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -69,7 +69,7 @@ describe('resetChannelCacheSaga', () => { message: 'message', createdAt: DateTime.utc().valueOf() + DateTime.utc().minus({ minutes: index }).valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -87,7 +87,7 @@ describe('resetChannelCacheSaga', () => { 'CacheMessages', { messages: messages, - channelAddress: generalChannel.address + channelId: generalChannel.id } ) @@ -106,12 +106,12 @@ describe('resetChannelCacheSaga', () => { .put( publicChannelsActions.cacheMessages({ messages: updatedCache, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .put( messagesActions.setDisplayedMessagesNumber({ - channelAddress: generalChannel.address, + channelId: generalChannel.id, display: 50 }) ) diff --git a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts index 6b28f8497f..7083c3c4d7 100644 --- a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts +++ b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts @@ -7,7 +7,7 @@ import { messagesActions } from '../messages.slice' import { SetDisplayedMessagesNumberPayload } from '../messages.types' export function* resetCurrentPublicChannelCacheSaga(): Generator { - const channelAddress = yield* select(publicChannelsSelectors.currentChannelAddress) + const channelId = yield* select(publicChannelsSelectors.currentchannelId) const channelMessagesChunkSize = 50 @@ -25,13 +25,13 @@ export function* resetCurrentPublicChannelCacheSaga(): Generator { const cacheMessagesPayload: CacheMessagesPayload = { messages: messages, - channelAddress: channelAddress + channelId: channelId } yield* put(publicChannelsActions.cacheMessages(cacheMessagesPayload)) const setDisplayedMessagesNumberPayload: SetDisplayedMessagesNumberPayload = { - channelAddress: channelAddress, + channelId: channelId, display: channelMessagesChunkSize } diff --git a/packages/state-manager/src/sagas/messages/messages.adapter.ts.ts b/packages/state-manager/src/sagas/messages/messages.adapter.ts.ts index c8b9adb105..e1a91e8df1 100644 --- a/packages/state-manager/src/sagas/messages/messages.adapter.ts.ts +++ b/packages/state-manager/src/sagas/messages/messages.adapter.ts.ts @@ -3,7 +3,7 @@ import { ChannelMessage } from '../publicChannels/publicChannels.types' import { MessageSendingStatus, MessageVerificationStatus, PublicChannelsMessagesBase } from './messages.types' export const publicChannelsMessagesBaseAdapter = createEntityAdapter({ - selectId: base => base.channelAddress + selectId: base => base.channelId }) export const messagesBaseAdapter = createEntityAdapter() diff --git a/packages/state-manager/src/sagas/messages/messages.selectors.test.ts b/packages/state-manager/src/sagas/messages/messages.selectors.test.ts index 9528f8c7d8..e12ae590f2 100644 --- a/packages/state-manager/src/sagas/messages/messages.selectors.test.ts +++ b/packages/state-manager/src/sagas/messages/messages.selectors.test.ts @@ -58,7 +58,7 @@ describe('messagesSelectors', () => { }) ).payload.message, id: Math.random().toString(36).substr(2.9), - channelAddress: generalChannel.address + channelId: generalChannel.id } const spoofedMessage: ChannelMessage = { @@ -68,7 +68,7 @@ describe('messagesSelectors', () => { }) ).payload.message, id: Math.random().toString(36).substr(2.9), - channelAddress: generalChannel.address, + channelId: generalChannel.id, pubKey: johnPublicKey } @@ -85,7 +85,7 @@ describe('messagesSelectors', () => { store.dispatch( publicChannels.actions.setCurrentChannel({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) diff --git a/packages/state-manager/src/sagas/messages/messages.selectors.ts b/packages/state-manager/src/sagas/messages/messages.selectors.ts index 08b4691aef..6389bfa61e 100644 --- a/packages/state-manager/src/sagas/messages/messages.selectors.ts +++ b/packages/state-manager/src/sagas/messages/messages.selectors.ts @@ -1,7 +1,7 @@ import { createSelector } from 'reselect' import { AUTODOWNLOAD_SIZE_LIMIT } from '../../constants' import { channelMessagesAdapter } from '../publicChannels/publicChannels.adapter' -import { currentChannelAddress } from '../publicChannels/publicChannels.selectors' +import { currentchannelId } from '../publicChannels/publicChannels.selectors' import { StoreKeys } from '../store.keys' import { CreatedSelectors, StoreState } from '../store.types' import { certificatesMapping } from '../users/users.selectors' @@ -38,7 +38,7 @@ export const publicChannelsMessagesBase = createSelector(messagesSlice, reducerS export const currentPublicChannelMessagesBase = createSelector( publicChannelsMessagesBase, - currentChannelAddress, + currentchannelId, (base, address) => { return base[address] } @@ -98,21 +98,21 @@ export const sortedCurrentPublicChannelMessagesEntries = createSelector( } ) -export const missingChannelMessages = (ids: string[], channelAddress: string) => +export const missingChannelMessages = (ids: string[], channelId: string) => createSelector(publicChannelsMessagesBase, base => { - if (!base[channelAddress]) return [] + if (!base[channelId]) return [] const channelMessages = channelMessagesAdapter .getSelectors() - .selectIds(base[channelAddress].messages) + .selectIds(base[channelId].messages) return ids.filter(id => !channelMessages.includes(id)) }) -export const missingChannelFiles = (channelAddress: string) => +export const missingChannelFiles = (channelId: string) => createSelector(publicChannelsMessagesBase, downloadStatuses, (base, statuses) => { - if (!base[channelAddress]) return [] + if (!base[channelId]) return [] const channelMessages = channelMessagesAdapter .getSelectors() - .selectAll(base[channelAddress].messages) + .selectAll(base[channelId].messages) return channelMessages .filter(message => (message.type === MessageType.Image || message.type === MessageType.File) && message.media?.path === null) .map(message => message.media) diff --git a/packages/state-manager/src/sagas/messages/messages.slice.ts b/packages/state-manager/src/sagas/messages/messages.slice.ts index ffd860c667..5aafe869d3 100644 --- a/packages/state-manager/src/sagas/messages/messages.slice.ts +++ b/packages/state-manager/src/sagas/messages/messages.slice.ts @@ -43,13 +43,13 @@ export const messagesSlice = createSlice({ sendDeletionMessage: (state, _action: PayloadAction) => state, deleteChannelEntry: (state, action: PayloadAction) => { - const { channelAddress } = action.payload - publicChannelsMessagesBaseAdapter.removeOne(state.publicChannelsMessagesBase, channelAddress) + const { channelId } = action.payload + publicChannelsMessagesBaseAdapter.removeOne(state.publicChannelsMessagesBase, channelId) }, addPublicChannelsMessagesBase: (state, action: PayloadAction) => { - const { channelAddress } = action.payload + const { channelId } = action.payload publicChannelsMessagesBaseAdapter.addOne(state.publicChannelsMessagesBase, { - channelAddress: channelAddress, + channelId: channelId, messages: channelMessagesAdapter.getInitialState(), display: 50 }) @@ -83,12 +83,12 @@ export const messagesSlice = createSlice({ const { messages } = action.payload for (const message of messages) { if (!instanceOfChannelMessage(message)) return - if (!state.publicChannelsMessagesBase.entities[message.channelAddress]) return + if (!state.publicChannelsMessagesBase.entities[message.channelId]) return let incoming = message const draft = state.publicChannelsMessagesBase - .entities[message.channelAddress] + .entities[message.channelId] ?.messages .entities[message.id] @@ -103,16 +103,16 @@ export const messagesSlice = createSlice({ } channelMessagesAdapter.upsertOne( - state.publicChannelsMessagesBase.entities[message.channelAddress].messages, + state.publicChannelsMessagesBase.entities[message.channelId].messages, incoming ) } }, setDisplayedMessagesNumber: (state, action: PayloadAction) => { - const { display, channelAddress } = action.payload + const { display, channelId } = action.payload publicChannelsMessagesBaseAdapter.updateOne( state.publicChannelsMessagesBase, { - id: channelAddress, + id: channelId, changes: { display: display } diff --git a/packages/state-manager/src/sagas/messages/messages.types.ts b/packages/state-manager/src/sagas/messages/messages.types.ts index 35fdd7f4e8..90a8720954 100644 --- a/packages/state-manager/src/sagas/messages/messages.types.ts +++ b/packages/state-manager/src/sagas/messages/messages.types.ts @@ -28,7 +28,7 @@ export interface PushNotificationPayload { export interface WriteMessagePayload { message: string id?: string - channelAddress?: string + channelId?: string type?: MessageType media?: FileMetadata } @@ -39,17 +39,17 @@ export interface PublicKeyMappingPayload { } export interface AddPublicChannelsMessagesBasePayload { - channelAddress: string + channelId: string } export interface PublicChannelsMessagesBase { - channelAddress: string + channelId: string messages: EntityState display: number } export interface SetDisplayedMessagesNumberPayload { - channelAddress: string + channelId: string display: number } @@ -71,20 +71,20 @@ export interface MessageSendingStatus { export interface AskForMessagesPayload { ids: string[] peerId: string - channelAddress: string + channelId: string communityId: string } export interface ChannelMessagesIdsResponse { ids: string[] - channelAddress: string + channelId: string communityId: string } export interface DeleteChannelEntryPayload { - channelAddress: string + channelId: string } export interface SendDeletionMessagePayload { - channelAddress: string + channelId: string } diff --git a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts index 14be1495a1..1fab7c43a9 100644 --- a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.test.ts @@ -14,7 +14,7 @@ import { messagesActions } from '../../messages/messages.slice' import { publicChannelsSelectors } from '../../publicChannels/publicChannels.selectors' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { sendDeletionMessageSaga } from './sendDeletionMessage.saga' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('sendDeletionMessage', () => { let store: Store @@ -52,7 +52,7 @@ describe('sendDeletionMessage', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: generateChannelAddress('photo') + id: generateChannelId('photo') } } ) @@ -60,18 +60,18 @@ describe('sendDeletionMessage', () => { }) test('send message after deletion standard channel', async () => { - const channelAddress = photoChannel.address + const channelId = photoChannel.id const message = `@${owner.nickname} deleted #${photoChannel.name}` const messagePayload: WriteMessagePayload = { type: MessageType.Info, message, - channelAddress: generalChannel.address + channelId: generalChannel.id } const reducer = combineReducers(reducers) await expectSaga( sendDeletionMessageSaga, messagesActions.sendDeletionMessage({ - channelAddress + channelId }) ) .withReducer(reducer) @@ -81,13 +81,13 @@ describe('sendDeletionMessage', () => { }) test('not send message after deletion general channel', async () => { - const channelAddress = 'general' + const channelId = 'general' const reducer = combineReducers(reducers) await expectSaga( sendDeletionMessageSaga, messagesActions.sendDeletionMessage({ - channelAddress + channelId }) ) .withReducer(reducer) diff --git a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts index a87eeb6641..bff5016466 100644 --- a/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts +++ b/packages/state-manager/src/sagas/messages/sendDeletionMessage/sendDeletionMessage.saga.ts @@ -8,10 +8,10 @@ import { WriteMessagePayload, MessageType } from '../messages.types' export function* sendDeletionMessageSaga( action: PayloadAction['payload']> ): Generator { - const { channelAddress } = action.payload + const { channelId } = action.payload const generalChannel = yield* select(publicChannelsSelectors.generalChannel) - const isGeneral = channelAddress === generalChannel.address + const isGeneral = channelId === generalChannel.id const ownerNickname = yield* select(communitiesSelectors.ownerNickname) @@ -21,8 +21,8 @@ export function* sendDeletionMessageSaga( const payload: WriteMessagePayload = { type: MessageType.Info, - message: `@${ownerNickname} deleted #${channelAddress.slice(0, channelAddress.indexOf('_'))}`, // TEMPORARY - channelAddress: generalChannel.address + message: `@${ownerNickname} deleted #${channelId.slice(0, channelId.indexOf('_'))}`, // TEMPORARY + channelId: generalChannel.id } if (isOwner && !isGeneral) { diff --git a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts index 57d9194f3a..0209ab8bf0 100644 --- a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts @@ -21,11 +21,11 @@ import { messagesActions } from '../messages.slice' import { generateMessageId, getCurrentTime } from '../utils/message.utils' import { sendMessageSaga } from './sendMessage.saga' import { FactoryGirl } from 'factory-girl' -import { currentChannelAddress } from '../../publicChannels/publicChannels.selectors' +import { currentchannelId } from '../../publicChannels/publicChannels.selectors' import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('sendMessageSaga', () => { let store: Store @@ -60,7 +60,7 @@ describe('sendMessageSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress('sailing') + id: generateChannelId('sailing') } } )).channel @@ -69,7 +69,7 @@ describe('sendMessageSaga', () => { test('sign and send message in current channel', async () => { const socket = { emit: jest.fn() } as unknown as Socket - const currentChannel = currentChannelAddress(store.getState()) + const currentChannel = currentchannelId(store.getState()) const reducer = combineReducers(reducers) await expectSaga( @@ -97,7 +97,7 @@ describe('sendMessageSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 8, - channelAddress: currentChannel, + channelId: currentChannel, signature: 'signature', pubKey: 'publicKey', media: undefined @@ -114,7 +114,7 @@ describe('sendMessageSaga', () => { await expectSaga( sendMessageSaga, socket, - messagesActions.sendMessage({ message: 'message', channelAddress: sailingChannel.address }) + messagesActions.sendMessage({ message: 'message', channelId: sailingChannel.id }) ) .withReducer(reducer) .withState(store.getState()) @@ -136,7 +136,7 @@ describe('sendMessageSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 24, - channelAddress: sailingChannel.address, + channelId: sailingChannel.id, signature: 'signature', pubKey: 'publicKey', media: undefined @@ -150,7 +150,7 @@ describe('sendMessageSaga', () => { const socket = { emit: jest.fn() } as unknown as Socket const messageId = Math.random().toString(36).substr(2.9) - const currentChannel = currentChannelAddress(store.getState()) + const currentChannel = currentchannelId(store.getState()) const media: FileMetadata = { cid: 'cid', @@ -159,7 +159,7 @@ describe('sendMessageSaga', () => { ext: 'ext', message: { id: messageId, - channelAddress: currentChannel + channelId: currentChannel } } @@ -189,7 +189,7 @@ describe('sendMessageSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 8, - channelAddress: currentChannel, + channelId: currentChannel, signature: 'signature', pubKey: 'publicKey', media: undefined diff --git a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts index f1515b07c8..a64a1ba2ba 100644 --- a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts +++ b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts @@ -28,14 +28,14 @@ export function* sendMessageSaga( const signatureArrayBuffer = yield* call(sign, action.payload.message, keyObject) const signature = yield* call(arrayBufferToString, signatureArrayBuffer) - const currentChannel = yield* select(publicChannelsSelectors.currentChannelAddress) + const currentChannel = yield* select(publicChannelsSelectors.currentchannelId) const createdAt = yield* call(getCurrentTime) const generatedMessageId = yield* call(generateMessageId) const id = action.payload.id || generatedMessageId - const channelAddress = action.payload.channelAddress || currentChannel + const channelId = action.payload.channelId || currentChannel const message: ChannelMessage = { id: id, @@ -43,7 +43,7 @@ export function* sendMessageSaga( message: action.payload.message, media: action.payload.media, createdAt, - channelAddress, + channelId, signature, pubKey } diff --git a/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap b/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap index b82625342e..c1e2062753 100644 --- a/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap +++ b/packages/state-manager/src/sagas/publicChannels/__snapshots__/publicChannels.selectors.test.ts.snap @@ -2,7 +2,7 @@ exports[`publicChannelsSelectors get messages sorted by date 1`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "1", "message": "message_1", @@ -14,7 +14,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 2`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "2", "message": "message_2", @@ -26,7 +26,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 3`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "3", "message": "message_3", @@ -38,7 +38,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 4`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "4", "message": "message_4", @@ -50,7 +50,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 5`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "5", "message": "message_5", @@ -62,7 +62,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 6`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "6", "message": "message_6", @@ -74,7 +74,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 7`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "7", "message": "message_7", @@ -86,7 +86,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 8`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "8", "message": "message_8", @@ -98,7 +98,7 @@ Object { exports[`publicChannelsSelectors get messages sorted by date 9`] = ` Object { - "channelAddress": "general_ec4bca1fa76046c53dff1e49979c3647", + "channelId": "general_ec4bca1fa76046c53dff1e49979c3647", "createdAt": Any, "id": "9", "message": "message_9", diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts index 75340bc9ee..a3cab9188d 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts @@ -14,7 +14,7 @@ import { DateTime } from 'luxon' import { publicChannelsSelectors } from '../publicChannels.selectors' import { messagesActions } from '../../messages/messages.slice' import { channelDeletionResponseSaga } from './channelDeletionResponse.saga' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('channelDeletionResponseSaga', () => { let store: Store @@ -52,7 +52,7 @@ describe('channelDeletionResponseSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: generateChannelAddress('photo') + id: generateChannelId('photo') } } ) @@ -60,41 +60,41 @@ describe('channelDeletionResponseSaga', () => { }) describe('handle saga logic as owner of community', () => { test('delete standard channel', async () => { - const channelAddress = photoChannel.address + const channelId = photoChannel.id const reducer = combineReducers(reducers) await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channelAddress + channelId }) ) .withReducer(reducer) .withState(store.getState()) - .put(publicChannelsActions.clearMessagesCache({ channelAddress })) - .put(messagesActions.deleteChannelEntry({ channelAddress })) - .put(publicChannelsActions.deleteChannelFromStore({ channelAddress })) - .put(messagesActions.sendDeletionMessage({ channelAddress })) + .put(publicChannelsActions.clearMessagesCache({ channelId })) + .put(messagesActions.deleteChannelEntry({ channelId })) + .put(publicChannelsActions.deleteChannelFromStore({ channelId })) + .put(messagesActions.sendDeletionMessage({ channelId })) .run() }) test('delete general channel', async () => { - const channelAddress = generalChannel.address + const channelId = generalChannel.id const reducer = combineReducers(reducers) await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channelAddress + channelId }) ) .withReducer(reducer) .withState(store.getState()) .put(publicChannelsActions.startGeneralRecreation()) - .put(publicChannelsActions.clearMessagesCache({ channelAddress })) - .put(messagesActions.deleteChannelEntry({ channelAddress })) - .put(publicChannelsActions.deleteChannelFromStore({ channelAddress })) + .put(publicChannelsActions.clearMessagesCache({ channelId })) + .put(messagesActions.deleteChannelEntry({ channelId })) + .put(publicChannelsActions.deleteChannelFromStore({ channelId })) .provide({ call: (effect, next) => {} }) @@ -109,39 +109,39 @@ describe('channelDeletionResponseSaga', () => { store.dispatch(communitiesActions.updateCommunityData({ ...community, CA: '' })) }) test('delete standard channel', async () => { - const channelAddress = photoChannel.address + const channelId = photoChannel.id const reducer = combineReducers(reducers) await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channelAddress + channelId }) ) .withReducer(reducer) .withState(store.getState()) - .put(publicChannelsActions.clearMessagesCache({ channelAddress })) - .put(messagesActions.deleteChannelEntry({ channelAddress })) - .put(publicChannelsActions.deleteChannelFromStore({ channelAddress })) + .put(publicChannelsActions.clearMessagesCache({ channelId })) + .put(messagesActions.deleteChannelEntry({ channelId })) + .put(publicChannelsActions.deleteChannelFromStore({ channelId })) .run() }) test('delete general channel', async () => { - const channelAddress = generalChannel.address + const channelId = generalChannel.id const reducer = combineReducers(reducers) await expectSaga( channelDeletionResponseSaga, publicChannelsActions.channelDeletionResponse({ - channelAddress + channelId }) ) .withReducer(reducer) .withState(store.getState()) .put(publicChannelsActions.startGeneralRecreation()) - .put(publicChannelsActions.clearMessagesCache({ channelAddress })) - .put(messagesActions.deleteChannelEntry({ channelAddress })) - .put(publicChannelsActions.deleteChannelFromStore({ channelAddress })) + .put(publicChannelsActions.clearMessagesCache({ channelId })) + .put(messagesActions.deleteChannelEntry({ channelId })) + .put(publicChannelsActions.deleteChannelFromStore({ channelId })) .run() }) }) diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts index 9ff5e35dce..510afee942 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts @@ -11,23 +11,23 @@ const log = logger('publicChannels') export function* channelDeletionResponseSaga( action: PayloadAction['payload']> ): Generator { - log(`Deleted channel ${action.payload.channelAddress} saga`) + log(`Deleted channel ${action.payload.channelId} saga`) - const { channelAddress } = action.payload + const { channelId } = action.payload const generalChannel = yield* select(publicChannelsSelectors.generalChannel) - const isGeneral = channelAddress === generalChannel.address + const isGeneral = channelId === generalChannel.id if (isGeneral) { yield* put(publicChannelsActions.startGeneralRecreation()) } - yield* put(publicChannelsActions.clearMessagesCache({ channelAddress })) + yield* put(publicChannelsActions.clearMessagesCache({ channelId })) - yield* put(messagesActions.deleteChannelEntry({ channelAddress })) + yield* put(messagesActions.deleteChannelEntry({ channelId })) - yield* put(publicChannelsActions.deleteChannelFromStore({ channelAddress })) + yield* put(publicChannelsActions.deleteChannelFromStore({ channelId })) const community = yield* select(communitiesSelectors.currentCommunity) @@ -38,7 +38,7 @@ export function* channelDeletionResponseSaga( yield* delay(1000) yield* put(publicChannelsActions.createGeneralChannel()) } else { - yield* put(messagesActions.sendDeletionMessage({ channelAddress })) + yield* put(messagesActions.sendDeletionMessage({ channelId })) } } } diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts index 88d99414e9..f78d51b7e7 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts @@ -14,7 +14,7 @@ import { channelsReplicatedSaga } from './channelsReplicated.saga' import { DateTime } from 'luxon' import { publicChannelsSelectors } from '../publicChannels.selectors' import { messagesActions } from '../../messages/messages.slice' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('channelsReplicatedSaga', () => { let store: Store @@ -44,7 +44,7 @@ describe('channelsReplicatedSaga', () => { generalChannel = publicChannelsSelectors.generalChannel(store.getState()) store.dispatch( - publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address }) + publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id }) ) sailingChannel = ( await factory.build('PublicChannel', { @@ -54,7 +54,7 @@ describe('channelsReplicatedSaga', () => { description: 'Welcome to #sailing', timestamp: DateTime.utc().valueOf(), owner: 'owner', - address: generateChannelAddress('sailing') + id: generateChannelId('sailing') } }) ).payload.channel @@ -67,7 +67,7 @@ describe('channelsReplicatedSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: 'owner', - address: generateChannelAddress('photo') + id: generateChannelId('photo') } }) ).payload.channel @@ -80,7 +80,7 @@ describe('channelsReplicatedSaga', () => { channelsReplicatedSaga, publicChannelsActions.channelsReplicated({ channels: { - [sailingChannel.address]: sailingChannel + [sailingChannel.id]: sailingChannel } }) ) @@ -100,8 +100,8 @@ describe('channelsReplicatedSaga', () => { channelsReplicatedSaga, publicChannelsActions.channelsReplicated({ channels: { - [generalChannel.address]: generalChannel, - [sailingChannel.address]: sailingChannel + [generalChannel.id]: generalChannel, + [sailingChannel.id]: sailingChannel } }) ) @@ -126,7 +126,7 @@ describe('channelsReplicatedSaga', () => { channelsReplicatedSaga, publicChannelsActions.channelsReplicated({ channels: { - [sailingChannel.address]: sailingChannel + [sailingChannel.id]: sailingChannel } }) ) @@ -139,7 +139,7 @@ describe('channelsReplicatedSaga', () => { ) .put( messagesActions.addPublicChannelsMessagesBase({ - channelAddress: sailingChannel.address + channelId: sailingChannel.id }) ) .run() @@ -151,8 +151,8 @@ describe('channelsReplicatedSaga', () => { channelsReplicatedSaga, publicChannelsActions.channelsReplicated({ channels: { - [generalChannel.address]: generalChannel, - [sailingChannel.address]: sailingChannel + [generalChannel.id]: generalChannel, + [sailingChannel.id]: sailingChannel } }) ) @@ -165,7 +165,7 @@ describe('channelsReplicatedSaga', () => { ) .put( messagesActions.addPublicChannelsMessagesBase({ - channelAddress: sailingChannel.address + channelId: sailingChannel.id }) ) .not.put( @@ -175,7 +175,7 @@ describe('channelsReplicatedSaga', () => { ) .not.put( messagesActions.addPublicChannelsMessagesBase({ - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .run() @@ -191,7 +191,7 @@ describe('channelsReplicatedSaga', () => { type: MessageType.Basic, message: (Math.random() * 10 ** 18).toString(36), createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' } @@ -200,7 +200,7 @@ describe('channelsReplicatedSaga', () => { store.dispatch( publicChannels.actions.cacheMessages({ messages: [], - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) @@ -209,8 +209,8 @@ describe('channelsReplicatedSaga', () => { channelsReplicatedSaga, publicChannelsActions.channelsReplicated({ channels: { - [generalChannel.address]: generalChannel, - [sailingChannel.address]: sailingChannel + [generalChannel.id]: generalChannel, + [sailingChannel.id]: sailingChannel } }) ) @@ -230,7 +230,7 @@ describe('channelsReplicatedSaga', () => { type: MessageType.Basic, message: (Math.random() * 10 ** 18).toString(36), createdAt: DateTime.utc().valueOf(), - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' } @@ -241,8 +241,8 @@ describe('channelsReplicatedSaga', () => { channelsReplicatedSaga, publicChannelsActions.channelsReplicated({ channels: { - [generalChannel.address]: generalChannel, - [sailingChannel.address]: sailingChannel + [generalChannel.id]: generalChannel, + [sailingChannel.id]: sailingChannel } }) ) @@ -260,8 +260,8 @@ describe('channelsReplicatedSaga', () => { channelsReplicatedSaga, publicChannelsActions.channelsReplicated({ channels: { - [generalChannel.address]: generalChannel, - [sailingChannel.address]: sailingChannel + [generalChannel.id]: generalChannel, + [sailingChannel.id]: sailingChannel } }) ) @@ -272,7 +272,7 @@ describe('channelsReplicatedSaga', () => { channel: sailingChannel }) ) - .put(publicChannelsActions.deleteChannel({ channelAddress: photoChannel.address })) + .put(publicChannelsActions.deleteChannel({ channelId: photoChannel.id })) .run() }) }) diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts index 9e1ca2823e..d4a279c06a 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts @@ -15,15 +15,15 @@ export function* channelsReplicatedSaga( log('INSIDE CHANNELS REPLICATED SAGA') const _locallyStoredChannels = yield* select(publicChannelsSelectors.publicChannels) - const locallyStoredChannels = _locallyStoredChannels.map(channel => channel.address) + const locallyStoredChannels = _locallyStoredChannels.map(channel => channel.id) const databaseStoredChannels = Object.values(action.payload.channels) - const databaseStoredChannelsAddresses = databaseStoredChannels.map(channel => channel.address) - console.log({ locallyStoredChannels, databaseStoredChannelsAddresses }) + const databaseStoredChannelsIds = databaseStoredChannels.map(channel => channel.id) + console.log({ locallyStoredChannels, databaseStoredChannelsIds }) // Upserting channels to local storage // KACPER!!! for (const channel of databaseStoredChannels) { - if (!locallyStoredChannels.includes(channel.address)) { + if (!locallyStoredChannels.includes(channel.id)) { log(`ADDING #${channel.name} TO LOCAL STORAGE`) yield* put( publicChannelsActions.addChannel({ @@ -32,17 +32,17 @@ export function* channelsReplicatedSaga( ) yield* put( messagesActions.addPublicChannelsMessagesBase({ - channelAddress: channel.address + channelId: channel.id }) ) } } // Removing channels from store - for (const channelAddress of locallyStoredChannels) { - if (!databaseStoredChannelsAddresses.includes(channelAddress)) { - log(`REMOVING #${channelAddress} FROM STORE`) - yield* put(publicChannelsActions.deleteChannel({ channelAddress })) + for (const channelId of locallyStoredChannels) { + if (!databaseStoredChannelsIds.includes(channelId)) { + log(`REMOVING #${channelId} FROM STORE`) + yield* put(publicChannelsActions.deleteChannel({ channelId })) } } diff --git a/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts index 71af1d68b5..26fec10bb3 100644 --- a/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createChannel/createChannel.saga.test.ts @@ -23,7 +23,7 @@ import { FactoryGirl } from 'factory-girl' import { setupCrypto } from '@quiet/identity' import { prepareStore } from '../../../utils/tests/prepareStore' import { getFactory } from '../../../utils/tests/factories' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('createChannelSaga', () => { let store: Store @@ -42,7 +42,7 @@ describe('createChannelSaga', () => { description: 'desc', owner: 'Howdy', timestamp: Date.now(), - address: generateChannelAddress('general') + id: generateChannelId('general') } test('ask for missing messages', async () => { diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts index 28c117e73b..447f0e2cc2 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.test.ts @@ -12,7 +12,7 @@ import { Identity } from '../../identity/identity.types' import { identityActions } from '../../identity/identity.slice' import { createGeneralChannelSaga, getChannelTimestamp } from './createGeneralChannel.saga' import { communitiesActions, Community } from '../../communities/communities.slice' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('createGeneralChannelSaga', () => { let store: Store @@ -39,12 +39,12 @@ describe('createGeneralChannelSaga', () => { test('create general channel', async () => { const reducer = combineReducers(reducers) - const generalAddress = generateChannelAddress('general') + const generalId = generateChannelId('general') const channel = { name: 'general', description: 'Welcome to #general', owner: alice.nickname, - address: generalAddress, + id: generalId, timestamp: 0 } console.log({ channel }) @@ -53,7 +53,7 @@ describe('createGeneralChannelSaga', () => { .withState(store.getState()) .provide([ [call.fn(getChannelTimestamp), 0], - [call.fn(generateChannelAddress), generalAddress] + [call.fn(generateChannelId), generalId] ]) .put( publicChannelsActions.createChannel({ @@ -62,7 +62,7 @@ describe('createGeneralChannelSaga', () => { ) .put( publicChannelsActions.setCurrentChannel({ - channelAddress: generalAddress + channelId: generalId }) ) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts index 2c08ac3e96..f679de48eb 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/createGeneralChannel.saga.ts @@ -5,7 +5,7 @@ import { identitySelectors } from '../../identity/identity.selectors' import { DateTime } from 'luxon' import { PublicChannel } from '../publicChannels.types' import logger from '../../../utils/logger' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' const log = logger('publicChannels') @@ -14,13 +14,13 @@ export function* createGeneralChannelSaga(): Generator { log(`Creating general channel for ${identity.nickname}`) const timestamp = yield* call(getChannelTimestamp) - const address = yield* call(generateChannelAddress, 'general') + const id = yield* call(generateChannelId, 'general') const channel: PublicChannel = { name: 'general', description: 'Welcome to #general', owner: identity.nickname, - address, + id, timestamp: timestamp } @@ -32,7 +32,7 @@ export function* createGeneralChannelSaga(): Generator { yield* put( publicChannelsActions.setCurrentChannel({ - channelAddress: channel.address + channelId: channel.id }) ) } diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts index ab1457faaa..937c21ad29 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.test.ts @@ -14,7 +14,7 @@ import { DateTime } from 'luxon' import { publicChannelsSelectors } from '../publicChannels.selectors' import { combineReducers } from '@reduxjs/toolkit' import { reducers } from '../../reducers' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('sendInitialChannelMessageSaga', () => { let store: Store @@ -53,7 +53,7 @@ describe('sendInitialChannelMessageSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: generateChannelAddress('photo'), + id: generateChannelId('photo'), } } ) @@ -66,7 +66,7 @@ describe('sendInitialChannelMessageSaga', () => { sendInitialChannelMessageSaga, publicChannelsActions.sendInitialChannelMessage({ channelName: channel.name, - channelAddress: channel.address + channelId: channel.id }) ) .withReducer(reducer) @@ -75,7 +75,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `Created #${channel.name}`, - channelAddress: channel.address + channelId: channel.id }) ) .run() @@ -88,7 +88,7 @@ describe('sendInitialChannelMessageSaga', () => { sendInitialChannelMessageSaga, publicChannelsActions.sendInitialChannelMessage({ channelName: generalChannel.name, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .withReducer(reducer) @@ -97,7 +97,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${owner.nickname} deleted all messages in #general`, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts index 8186efb654..ac31004230 100644 --- a/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/createGeneralChannel/sendInitialChannelMessage.saga.ts @@ -11,10 +11,10 @@ export function* sendInitialChannelMessageSaga( ReturnType['payload'] > ): Generator { - const { channelName, channelAddress } = action.payload + const { channelName, channelId } = action.payload const generalChannel = yield* select(publicChannelsSelectors.generalChannel) - const isGeneral = channelAddress === generalChannel.address + const isGeneral = channelId === generalChannel.id const pendingGeneralChannelRecreation = yield* select( publicChannelsSelectors.pendingGeneralChannelRecreation @@ -30,7 +30,7 @@ export function* sendInitialChannelMessageSaga( const payload: WriteMessagePayload = { type: MessageType.Info, message, - channelAddress: channelAddress + channelId: channelId } if (isGeneral) { diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts index bbd83b41ae..586abc5846 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts @@ -15,7 +15,7 @@ import { publicChannelsSelectors } from '../publicChannels.selectors' import { messagesActions } from '../../messages/messages.slice' import { deleteChannelSaga } from './deleteChannel.saga' import { Socket } from 'socket.io-client' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('deleteChannelSaga', () => { let store: Store @@ -55,7 +55,7 @@ describe('deleteChannelSaga', () => { description: 'Welcome to #photo', timestamp: DateTime.utc().valueOf(), owner: owner.nickname, - address: generateChannelAddress('photo') + id: generateChannelId('photo') } } ) @@ -64,42 +64,42 @@ describe('deleteChannelSaga', () => { test('delete standard channel', async () => { console.log({ generalChannel }) - const channelAddress = photoChannel.address + const channelId = photoChannel.id const reducer = combineReducers(reducers) await expectSaga( deleteChannelSaga, socket, - publicChannelsActions.deleteChannel({ channelAddress }) + publicChannelsActions.deleteChannel({ channelId }) ) .withReducer(reducer) .withState(store.getState()) .apply(socket, socket.emit, [ SocketActionTypes.DELETE_CHANNEL, { - channelAddress + channelId } ]) - .put(publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address })) - .put(publicChannelsActions.disableChannel({ channelAddress })) + .put(publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id })) + .put(publicChannelsActions.disableChannel({ channelId })) .run() }) test('delete general channel', async () => { - const channelAddress = generalChannel.address + const channelId = generalChannel.id const reducer = combineReducers(reducers) await expectSaga( deleteChannelSaga, socket, - publicChannelsActions.deleteChannel({ channelAddress }) + publicChannelsActions.deleteChannel({ channelId }) ) .withReducer(reducer) .withState(store.getState()) .apply(socket, socket.emit, [ SocketActionTypes.DELETE_CHANNEL, { - channelAddress + channelId } ]) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts index 64d8daa58f..84dc0435a4 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts @@ -12,22 +12,22 @@ export function* deleteChannelSaga( socket: Socket, action: PayloadAction['payload']> ): Generator { - const channelAddress = action.payload.channelAddress + const channelId = action.payload.channelId const generalChannel = yield* select(publicChannelsSelectors.generalChannel) - const isGeneral = channelAddress === generalChannel.address + const isGeneral = channelId === generalChannel.id - log(`Deleting channel ${channelAddress}`) + log(`Deleting channel ${channelId}`) yield* apply( socket, socket.emit, applyEmitParams(SocketActionTypes.DELETE_CHANNEL, { - channelAddress + channelId }) ) if (!isGeneral) { - yield* put(publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address })) - yield* put(publicChannelsActions.disableChannel({ channelAddress })) + yield* put(publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id })) + yield* put(publicChannelsActions.disableChannel({ channelId })) } } diff --git a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts index 53446fdee0..04c02d3b00 100644 --- a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.test.ts @@ -12,7 +12,7 @@ import { identityActions } from '../../identity/identity.slice' import { DateTime } from 'luxon' import { markUnreadChannelsSaga } from './markUnreadChannels.saga' import { messagesActions } from '../../messages/messages.slice' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('markUnreadChannelsSaga', () => { let store: Store @@ -51,19 +51,19 @@ describe('markUnreadChannelsSaga', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress(name) + id: generateChannelId(name) } }) - channelAdresses = [...channelAdresses, channel.channel.address] + channelAdresses = [...channelAdresses, channel.channel.id] } }) test('mark unread channels', async () => { - const messagesAddresses = channelAdresses + const messagesides = channelAdresses const messages: ChannelMessage[] = [] // Automatically create messages - for (const address of messagesAddresses) { + for (const id of messagesides) { const message = ( await factory.build('Message', { identity: alice, @@ -72,7 +72,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: address, + channelId: id, signature: '', pubKey: '' }, @@ -93,7 +93,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 99999999999999, - channelAddress: channelAdresses.find((address) => address.includes('enya')), + channelId: channelAdresses.find((id) => id.includes('enya')), signature: '', pubKey: '' }, @@ -115,19 +115,19 @@ describe('markUnreadChannelsSaga', () => { .withState(store.getState()) .put( publicChannelsActions.markUnreadChannel({ - channelAddress: channelAdresses.find((address) => address.includes('memes')), + channelId: channelAdresses.find((id) => id.includes('memes')), message: messages[0] }) ) .not.put( publicChannelsActions.markUnreadChannel({ - channelAddress: channelAdresses.find((address) => address.includes('enya')), + channelId: channelAdresses.find((id) => id.includes('enya')), message: messages[2] }) ) .put( publicChannelsActions.markUnreadChannel({ - channelAddress: channelAdresses.find((address) => address.includes('travels')), + channelId: channelAdresses.find((id) => id.includes('travels')), message: messages[3] }) ) @@ -135,7 +135,7 @@ describe('markUnreadChannelsSaga', () => { }) test('do not mark unread channels if message is older than user', async () => { - const messagesAddresses = channelAdresses + const messagesides = channelAdresses const messages: ChannelMessage[] = [] const community = await factory.create< @@ -147,7 +147,7 @@ describe('markUnreadChannelsSaga', () => { >('Identity', { id: community.id, nickname: 'alice', joinTimestamp: 9239423949 }) // Automatically create older messages - for (const address of messagesAddresses) { + for (const id of messagesides) { const message = ( await factory.build('Message', { identity: alice, @@ -156,7 +156,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 123, - channelAddress: address, + channelId: id, signature: '', pubKey: '' }, @@ -177,7 +177,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 99999999999999, - channelAddress: channelAdresses.find((address) => address.includes('enya')), + channelId: channelAdresses.find((id) => id.includes('enya')), signature: '', pubKey: '' }, @@ -199,19 +199,19 @@ describe('markUnreadChannelsSaga', () => { .withState(store.getState()) .not.put( publicChannelsActions.markUnreadChannel({ - channelAddress: channelAdresses.find((address) => address.includes('memes')), + channelId: channelAdresses.find((id) => id.includes('memes')), message: messages[1] }) ) .put( publicChannelsActions.markUnreadChannel({ - channelAddress: channelAdresses.find((address) => address.includes('enya')), + channelId: channelAdresses.find((id) => id.includes('enya')), message: message }) ) .not.put( publicChannelsActions.markUnreadChannel({ - channelAddress: channelAdresses.find((address) => address.includes('travels')), + channelId: channelAdresses.find((id) => id.includes('travels')), message: messages[3] }) ) diff --git a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts index dd5a92f2bb..117f37925f 100644 --- a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts @@ -9,15 +9,15 @@ import { identitySelectors } from '../../identity/identity.selectors' export function* markUnreadChannelsSaga( action: PayloadAction['payload']> ): Generator { - const currentChannelAddress = yield* select(publicChannelsSelectors.currentChannelAddress) + const currentchannelId = yield* select(publicChannelsSelectors.currentchannelId) const { messages } = action.payload for (const message of messages) { // Do not proceed for current channel - if (message.channelAddress !== currentChannelAddress) { + if (message.channelId !== currentchannelId) { const payload: MarkUnreadChannelPayload = { - channelAddress: message.channelAddress, + channelId: message.channelId, message: message } @@ -28,7 +28,7 @@ export function* markUnreadChannelsSaga( // For all messages created before user joined don't show notifications if (joinTimestamp > message.createdAt * 1000) continue // If there are newer messages in the channel, don't show notification - if (statuses[message.channelAddress]?.newestMessage?.createdAt > message.createdAt) continue + if (statuses[message.channelId]?.newestMessage?.createdAt > message.createdAt) continue yield* put( publicChannelsActions.markUnreadChannel(payload) @@ -40,13 +40,13 @@ export function* markUnreadChannelsSaga( export function* clearUnreadChannelsSaga( action: PayloadAction['payload']> ): Generator { - const { channelAddress } = action.payload + const { channelId } = action.payload // Do not proceed with invalid channel - if (channelAddress === '') return + if (channelId === '') return const payload: MarkUnreadChannelPayload = { - channelAddress: channelAddress + channelId: channelId } yield* put( diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.adapter.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.adapter.ts index 9eea3f1be4..561208d1c6 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.adapter.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.adapter.ts @@ -3,15 +3,15 @@ import { PublicChannelStatus, PublicChannelStorage, PublicChannelSubscription } import { ChannelMessage } from '../..' export const publicChannelsAdapter = createEntityAdapter({ - selectId: (channel) => channel.address + selectId: (channel) => channel.id }) export const publicChannelsStatusAdapter = createEntityAdapter({ - selectId: (channel) => channel.address + selectId: (channel) => channel.id }) export const publicChannelsSubscriptionsAdapter = createEntityAdapter({ - selectId: (channel) => channel.address + selectId: (channel) => channel.id }) export const channelMessagesAdapter = createEntityAdapter() diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts index 7769fc9b63..904dd923d1 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts @@ -22,7 +22,7 @@ import { } from '../../utils/functions/dates/formatMessageDisplayDate' import { displayableMessage } from '../../utils/functions/dates/formatDisplayableMessage' import { DateTime } from 'luxon' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' describe('publicChannelsSelectors', () => { let store: Store @@ -33,7 +33,7 @@ describe('publicChannelsSelectors', () => { let john: Identity let generalChannel: PublicChannel - let channelAddresses: string[] = [] + let channelIdes: string[] = [] const msgs: { [id: string]: ChannelMessage } = {} const msgsOwners: { [id: string]: string } = {} @@ -57,13 +57,13 @@ describe('publicChannelsSelectors', () => { { id: community.id, nickname: 'alice' } ) generalChannel = publicChannelsSelectors.generalChannel(store.getState()) - channelAddresses = [...channelAddresses, generalChannel.address] + channelIdes = [...channelIdes, generalChannel.id] john = await factory.create['payload']>( 'Identity', { id: community.id, nickname: 'john' } ) store.dispatch( - publicChannelsActions.setCurrentChannel({ channelAddress: generalChannel.address }) + publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id }) ) // Setup channels const channelNames = ['croatia', 'allergies', 'sailing', 'pets', 'antiques'] @@ -77,10 +77,10 @@ describe('publicChannelsSelectors', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress(name) + id: generateChannelId(name) } }) - channelAddresses = [...channelAddresses, channel.channel.address] + channelIdes = [...channelIdes, channel.channel.id] } /* Messages ids are being used only for veryfing proper order... @@ -212,7 +212,7 @@ describe('publicChannelsSelectors', () => { type: item.type || MessageType.Basic, message: `message_${item.id}`, createdAt: item.createdAt, - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -231,7 +231,7 @@ describe('publicChannelsSelectors', () => { ...prev, { ...curr, - channelAddress: 'general_ec4bca1fa76046c53dff1e49979c3647' + channelId: 'general_ec4bca1fa76046c53dff1e49979c3647' } ] }, []) @@ -290,7 +290,7 @@ describe('publicChannelsSelectors', () => { }) it("don't select messages without author", async () => { - const channelAddress = generateChannelAddress('utah') + const channelId = generateChannelId('utah') const channel = ( await factory.create['payload']>( 'PublicChannel', @@ -300,7 +300,7 @@ describe('publicChannelsSelectors', () => { description: 'Welcome to #utah', timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: channelAddress + id: channelId } } ) @@ -316,7 +316,7 @@ describe('publicChannelsSelectors', () => { store.dispatch( publicChannelsActions.setCurrentChannel({ - channelAddress: channelAddress + channelId: channelId }) ) @@ -329,7 +329,7 @@ describe('publicChannelsSelectors', () => { type: MessageType.Basic, message: 'elouise_message', createdAt: DateTime.now().valueOf(), - channelAddress: channelAddress, + channelId: channelId, signature: '', pubKey: '' }, @@ -372,16 +372,16 @@ describe('publicChannelsSelectors', () => { }) it('unreadChannels selector returns only unread channels', async () => { - const channelAddress = channelAddresses.find(channelAddress => - channelAddress.includes('allergies') + const channelId = channelIdes.find(channelId => + channelId.includes('allergies') ) store.dispatch( publicChannelsActions.markUnreadChannel({ - channelAddress + channelId }) ) const unreadChannels = publicChannelsSelectors.unreadChannels(store.getState()) - expect(unreadChannels).toEqual([channelAddress]) + expect(unreadChannels).toEqual([channelId]) }) }) diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts index 0b2c96d675..e9b49428e3 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts @@ -12,7 +12,7 @@ import { formatMessageDisplayDay } from '../../utils/functions/dates/formatMessa import { displayableMessage } from '../../utils/functions/dates/formatDisplayableMessage' import { DisplayableMessage, - INITIAL_CURRENT_CHANNEL_ADDRESS, + INITIAL_CURRENT_CHANNEL_ID, MessagesDailyGroups, PublicChannel, PublicChannelStatus @@ -40,7 +40,7 @@ export const subscribedChannels = createSelector( selectChannelsSubscriptions, (subscriptions) => { return subscriptions.map(subscription => { - if (subscription.subscribed) return subscription.address + if (subscription.subscribed) return subscription.id }) } ) @@ -53,7 +53,7 @@ export const selectGeneralChannel = createSelector(selectChannels, channels => { description: draft.description, owner: draft.owner, timestamp: draft.timestamp, - address: draft.address + id: draft.id } return channel }) @@ -87,11 +87,11 @@ export const sortedChannels = createSelector(publicChannels, (channels) => { return sorted }) -export const currentChannelAddress_OLD = createSelector( +export const currentchannelId_OLD = createSelector( selectState, (state) => { if (!state) return undefined - return state.currentChannelAddress + return state.currentchannelId } ) @@ -99,7 +99,7 @@ export const generalChannel = createSelector(publicChannels, publicChannelsSelec return publicChannelsSelector.find(channel => channel.name === 'general') }) -export const currentChannelAddress = createSelector( +export const currentchannelId = createSelector( selectState, generalChannel, (state, general) => { @@ -107,14 +107,14 @@ export const currentChannelAddress = createSelector( if (!state) { return undefined } - if (state.currentChannelAddress === INITIAL_CURRENT_CHANNEL_ADDRESS) { + if (state.currentchannelId === INITIAL_CURRENT_CHANNEL_ID) { if (general) { - return general.address + return general.id } else { return 'general'// case for tests when is no channel in store } } else { - return state.currentChannelAddress + return state.currentchannelId } } ) @@ -149,11 +149,11 @@ export const dynamicSearchedChannels = (channelInput: string) => // Is being used in tests export const currentChannel = createSelector( - currentChannelAddress, + currentchannelId, selectChannels, - (address, channels) => { - if (!address) return undefined - return channels.find(channel => channel.address === address) + (id, channels) => { + if (!id) return undefined + return channels.find(channel => channel.id === id) } ) @@ -283,7 +283,7 @@ export const unreadChannels = createSelector( status => { return Object.values(status).reduce((result: string[], channel: PublicChannelStatus) => { if (channel.unread) { - result.push(channel.address) + result.push(channel.id) } return result }, []) @@ -293,7 +293,7 @@ export const unreadChannels = createSelector( export const publicChannelsSelectors = { publicChannels, subscribedChannels, - currentChannelAddress, + currentchannelId, currentChannelName, currentChannel, currentChannelMessages, diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index ce57c3e74e..248b40adf7 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -26,7 +26,7 @@ import { DeleteChannelFromStorePayload, ClearMessagesCachePayload, DisableChannelPayload, - INITIAL_CURRENT_CHANNEL_ADDRESS + INITIAL_CURRENT_CHANNEL_ID } from './publicChannels.types' import logger from '../../utils/logger' @@ -34,7 +34,7 @@ import { Identity } from '../identity/identity.types' const log = logger('publicChannels') export class PublicChannelsState { - public currentChannelAddress: string = INITIAL_CURRENT_CHANNEL_ADDRESS + public currentchannelId: string = INITIAL_CURRENT_CHANNEL_ID public pendingGeneralChannelRecreation: boolean = false @@ -56,25 +56,25 @@ export const publicChannelsSlice = createSlice({ channelDeletionResponse: (state, _action: PayloadAction) => state, deleteChannelFromStore: (state, action: PayloadAction) => { - const { channelAddress } = action.payload + const { channelId } = action.payload - publicChannelsSubscriptionsAdapter.removeOne(state.channelsSubscriptions, channelAddress) - publicChannelsStatusAdapter.removeOne(state.channelsStatus, channelAddress) - publicChannelsAdapter.removeOne(state.channels, channelAddress) + publicChannelsSubscriptionsAdapter.removeOne(state.channelsSubscriptions, channelId) + publicChannelsStatusAdapter.removeOne(state.channelsStatus, channelId) + publicChannelsAdapter.removeOne(state.channels, channelId) }, disableChannel: (state, action: PayloadAction) => { - const { channelAddress } = action.payload + const { channelId } = action.payload publicChannelsAdapter.updateOne(state.channels, { - id: channelAddress, + id: channelId, changes: { disabled: true } }) }, clearMessagesCache: (state, action: PayloadAction) => { - const { channelAddress } = action.payload + const { channelId } = action.payload console.log('clearMessagesCache', action.payload) - channelMessagesAdapter.setAll(state.channels.entities[channelAddress].messages, []) + channelMessagesAdapter.setAll(state.channels.entities[channelId].messages, []) }, startGeneralRecreation: state => { state.pendingGeneralChannelRecreation = true @@ -93,41 +93,41 @@ export const publicChannelsSlice = createSlice({ messages: channelMessagesAdapter.getInitialState() }) publicChannelsStatusAdapter.addOne(state.channelsStatus, { - address: channel.address, + id: channel.id, unread: false, newestMessage: null }) }, setChannelSubscribed: (state, action: PayloadAction) => { - const { channelAddress } = action.payload + const { channelId } = action.payload publicChannelsSubscriptionsAdapter.upsertOne(state.channelsSubscriptions, { - address: channelAddress, + id: channelId, subscribed: true }) }, channelsReplicated: (state, _action: PayloadAction) => state, setCurrentChannel: (state, action: PayloadAction) => { - const { channelAddress } = action.payload - state.currentChannelAddress = channelAddress + const { channelId } = action.payload + state.currentchannelId = channelId }, cacheMessages: (state, action: PayloadAction) => { - const { messages, channelAddress } = action.payload - channelMessagesAdapter.setAll(state.channels.entities[channelAddress].messages, messages) + const { messages, channelId } = action.payload + channelMessagesAdapter.setAll(state.channels.entities[channelId].messages, messages) }, markUnreadChannel: (state, action: PayloadAction) => { - const { channelAddress } = action.payload + const { channelId } = action.payload publicChannelsStatusAdapter.updateOne(state.channelsStatus, { - id: channelAddress, + id: channelId, changes: { unread: true } }) }, clearUnreadChannel: (state, action: PayloadAction) => { - const { channelAddress } = action.payload + const { channelId } = action.payload publicChannelsStatusAdapter.updateOne(state.channelsStatus, { - id: channelAddress, + id: channelId, changes: { unread: false } @@ -136,7 +136,7 @@ export const publicChannelsSlice = createSlice({ updateNewestMessage: (state, action: PayloadAction) => { const { message } = action.payload publicChannelsStatusAdapter.updateOne(state.channelsStatus, { - id: message.channelAddress, + id: message.channelId, changes: { newestMessage: message } @@ -154,7 +154,7 @@ export const publicChannelsSlice = createSlice({ const { message } = action.payload console.log({ message }) channelMessagesAdapter.addOne( - state.channels.entities[message.channelAddress].messages, + state.channels.entities[message.channelId].messages, message ) } diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts index ed31e62846..96f1946a07 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts @@ -10,10 +10,10 @@ export const PublicChannelsTransform = createTransform( (outboundState: PublicChannelsState, _key) => { return { ...outboundState, - currentChannelAddress: publicChannelsAdapter + currentchannelId: publicChannelsAdapter .getSelectors() .selectAll(outboundState.channels) - .find(channel => channel.name === 'general').address, + .find(channel => channel.name === 'general').id, channels: outboundState.channels, channelsStatus: outboundState.channelsStatus, channelsSubscriptions: publicChannelsSubscriptionsAdapter.getInitialState() diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts index 1e420f20db..3b7463c584 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts @@ -1,14 +1,14 @@ import { Dictionary, EntityState } from '@reduxjs/toolkit' import { FileMetadata } from '../files/files.types' -export const INITIAL_CURRENT_CHANNEL_ADDRESS = 'initialCurrentChannelAddress' +export const INITIAL_CURRENT_CHANNEL_ID = 'initialCurrentchannelId' export interface PublicChannel { name: string description: string owner: string timestamp: number - address: string + id: string disabled?: boolean } @@ -17,13 +17,13 @@ export interface PublicChannelStorage extends PublicChannel { } export interface PublicChannelStatus { - address: string + id: string unread: boolean newestMessage: ChannelMessage } export interface PublicChannelSubscription { - address: string + id: string subscribed: boolean } @@ -32,7 +32,7 @@ export interface ChannelMessage { type: number message: string createdAt: number - channelAddress: string + channelId: string signature: string pubKey: string media?: FileMetadata @@ -61,10 +61,10 @@ export interface CreateChannelPayload { } export interface DeleteChannelPayload { - channelAddress: string + channelId: string } export interface ChannelDeletionResponsePayload { - channelAddress: string + channelId: string } export interface CreatedChannelResponse { @@ -72,16 +72,16 @@ export interface CreatedChannelResponse { } export interface SetChannelSubscribedPayload { - channelAddress: string + channelId: string } export interface SetCurrentChannelPayload { - channelAddress: string + channelId: string } export interface SetChannelMessagesSliceValuePayload { messagesSlice: number - channelAddress: string + channelId: string } export interface PendingMessage { @@ -90,7 +90,7 @@ export interface PendingMessage { export interface SendInitialChannelMessagePayload { channelName: string - channelAddress: string + channelId: string } export interface SendNewUserInfoMessagePayload { certificates: string[] @@ -103,11 +103,11 @@ export interface IncomingMessages { export interface CacheMessagesPayload { messages: ChannelMessage[] - channelAddress: string + channelId: string } export interface MarkUnreadChannelPayload { - channelAddress: string + channelId: string message?: ChannelMessage } @@ -116,17 +116,17 @@ export interface UpdateNewestMessagePayload { } export interface DeleteChannelFromStorePayload { - channelAddress: string + channelId: string } export interface ClearMessagesCachePayload { - channelAddress: string + channelId: string } export interface DisableChannelPayload { - channelAddress: string + channelId: string } export function instanceOfChannelMessage(object: any): object is ChannelMessage { - return 'channelAddress' in object + return 'channelId' in object } diff --git a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts index f999e26e6c..3750ae91ff 100644 --- a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.test.ts @@ -70,7 +70,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2.nickname} has joined ${communityName}! 🎉`, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .run() @@ -111,7 +111,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2.nickname} has joined ${communityName}! 🎉`, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .run() @@ -142,7 +142,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2} has joined ${community1.name}! 🎉`, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .run() @@ -189,7 +189,7 @@ describe('sendInitialChannelMessageSaga', () => { messagesActions.sendMessage({ type: 3, message: `@${user2.nickname} has joined ${communityName}! 🎉`, - channelAddress: generalChannel.address + channelId: generalChannel.id }) ) .run() diff --git a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts index b1561bc519..1538fe5d20 100644 --- a/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/sendNewUserInfoMessage/sendNewUserInfoMessage.saga.ts @@ -49,7 +49,7 @@ export function* sendNewUserInfoMessageSaga( const payload: WriteMessagePayload = { type: MessageType.Info, message: `@${user} has joined ${communityName}! 🎉`, - channelAddress: generalChannel.address + channelId: generalChannel.id } yield* put(messagesActions.sendMessage(payload)) diff --git a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts index efe0a6ed7b..ff72948dfc 100644 --- a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.test.ts @@ -12,7 +12,7 @@ import { identityActions } from '../../identity/identity.slice' import { DateTime } from 'luxon' import { updateNewestMessageSaga } from './updateNewestMessage.saga' import { messagesActions } from '../../messages/messages.slice' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' import { publicChannelsSelectors } from '../publicChannels.selectors' describe('markUnreadChannelsSaga', () => { @@ -42,7 +42,7 @@ describe('markUnreadChannelsSaga', () => { { id: community.id, nickname: 'alice' } ) generalChannel = publicChannelsSelectors.generalChannel(store.getState()) - channelAdresses = [...channelAdresses, generalChannel.address] + channelAdresses = [...channelAdresses, generalChannel.id] const channelNames = ['memes', 'pets', 'travels'] // Automatically create channels @@ -55,19 +55,19 @@ describe('markUnreadChannelsSaga', () => { description: `Welcome to #${name}`, timestamp: DateTime.utc().valueOf(), owner: alice.nickname, - address: generateChannelAddress(name) + id: generateChannelId(name) } }) - channelAdresses = [...channelAdresses, channel.channel.address] + channelAdresses = [...channelAdresses, channel.channel.id] } }) test('Update newest message if there is no newest message', async () => { - const messagesAddresses = channelAdresses + const messagesides = channelAdresses const messages: ChannelMessage[] = [] // Automatically create messages - for (const address of messagesAddresses) { + for (const id of messagesides) { const message = ( await factory.build('Message', { identity: alice, @@ -76,7 +76,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: address, + channelId: id, signature: '', pubKey: '' }, @@ -101,11 +101,11 @@ describe('markUnreadChannelsSaga', () => { }) test('update newest message if incoming message is newer', async () => { - const messagesAddresses = [generalChannel.address] + const messagesides = [generalChannel.id] const messages: ChannelMessage[] = [] // Automatically create messages - for (const address of messagesAddresses) { + for (const id of messagesides) { const message = ( await factory.build('Message', { identity: alice, @@ -114,7 +114,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: address, + channelId: id, signature: '', pubKey: '' }, @@ -135,7 +135,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 9999, - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, @@ -159,11 +159,11 @@ describe('markUnreadChannelsSaga', () => { .run() }) test('do not update newest message if incoming message is older', async () => { - const messagesAddresses = [generalChannel.address] + const messagesides = [generalChannel.id] const messages: ChannelMessage[] = [] // Automatically create messages - for (const address of messagesAddresses) { + for (const id of messagesides) { const message = ( await factory.build('Message', { identity: alice, @@ -172,7 +172,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: DateTime.utc().valueOf(), - channelAddress: address, + channelId: id, signature: '', pubKey: '' }, @@ -193,7 +193,7 @@ describe('markUnreadChannelsSaga', () => { type: MessageType.Basic, message: 'message', createdAt: 99999999999999, - channelAddress: generalChannel.address, + channelId: generalChannel.id, signature: '', pubKey: '' }, diff --git a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.ts b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.ts index 68080dc9ae..0ed075f3dd 100644 --- a/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/updateNewestMessage/updateNewestMessage.saga.ts @@ -11,10 +11,10 @@ export function* updateNewestMessageSaga( const statuses = yield* select(publicChannelsSelectors.channelsStatus) for (const message of messages) { - if (!statuses[message.channelAddress]) return + if (!statuses[message.channelId]) return if ( - !statuses[message.channelAddress].newestMessage || - statuses[message.channelAddress].newestMessage.createdAt < message.createdAt + !statuses[message.channelId].newestMessage || + statuses[message.channelId].newestMessage.createdAt < message.createdAt ) { yield* put(publicChannelsActions.updateNewestMessage({ message })) } 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 f8640f854d..5cf950fad3 100644 --- a/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts +++ b/packages/state-manager/src/sagas/socket/startConnection/startConnection.saga.ts @@ -130,14 +130,14 @@ export function subscribe(socket: Socket) { socket.on(SocketActionTypes.CREATED_CHANNEL, (payload: CreatedChannelResponse) => { emit( messagesActions.addPublicChannelsMessagesBase({ - channelAddress: payload.channel.address + channelId: payload.channel.id }) ) emit(publicChannelsActions.addChannel(payload)) emit( publicChannelsActions.sendInitialChannelMessage({ channelName: payload.channel.name, - channelAddress: payload.channel.address + channelId: payload.channel.id }) ) }) diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index d3368998e5..202b35277b 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -23,7 +23,7 @@ import { MessageType, SendingStatus } from '../../sagas/messages/messages.types' import { DateTime } from 'luxon' import { messagesActions } from '../../sagas/messages/messages.slice' import { publicChannelsActions } from '../../sagas/publicChannels/publicChannels.slice' -import { generateChannelAddress } from '@quiet/common' +import { generateChannelId } from '@quiet/common' export const getFactory = async (store: Store) => { // @ts-ignore @@ -63,7 +63,7 @@ export const getFactory = async (store: Store) => { description: 'Welcome to channel #general', timestamp: DateTime.utc().toSeconds(), owner: 'alice', - address: generateChannelAddress('general') + id: generateChannelId('general') } }) return payload @@ -130,11 +130,11 @@ export const getFactory = async (store: Store) => { }) factory.define('PublicChannelsMessagesBase', messages.actions.addPublicChannelsMessagesBase, { - channelAddress: factory.assoc('PublicChannel', 'address') + channelId: factory.assoc('PublicChannel', 'id') }) factory.define('PublicChannelSubscription', publicChannels.actions.setChannelSubscribed, { - channelAddress: factory.assoc('PublicChannel', 'address') + channelId: factory.assoc('PublicChannel', 'id') }) factory.define( @@ -146,7 +146,7 @@ export const getFactory = async (store: Store) => { description: 'Description', timestamp: DateTime.utc().toSeconds(), owner: factory.assoc('Identity', 'nickname'), - address: generateChannelAddress( + id: generateChannelId( factory.sequence('PublicChannel.name', n => `publicChannel${n}`).toString() ) } @@ -156,10 +156,10 @@ export const getFactory = async (store: Store) => { payload: ReturnType['payload'] ) => { await factory.create('PublicChannelsMessagesBase', { - channelAddress: payload.channel.address + channelId: payload.channel.id }) await factory.create('PublicChannelSubscription', { - channelAddress: payload.channel.address + channelId: payload.channel.id }) return payload } @@ -176,7 +176,7 @@ export const getFactory = async (store: Store) => { type: MessageType.Basic, message: factory.sequence('Message.message', n => `message_${n}`), createdAt: DateTime.utc().valueOf(), - channelAddress: generateChannelAddress('general'), + channelId: generateChannelId('general'), signature: '', pubKey: '' }, @@ -239,7 +239,7 @@ export const getFactory = async (store: Store) => { factory.define('CacheMessages', publicChannelsActions.cacheMessages, { messages: [], - channelAddress: factory.assoc('PublicChannel', 'address'), + channelId: factory.assoc('PublicChannel', 'id'), communityId: factory.assoc('Community', 'id') }) diff --git a/packages/types/src/channel.ts b/packages/types/src/channel.ts index 6fe517c9f7..9b1c4c7172 100644 --- a/packages/types/src/channel.ts +++ b/packages/types/src/channel.ts @@ -6,7 +6,7 @@ export interface PublicChannel { description: string owner: string timestamp: number - address: string + id: string } export interface PublicChannelStorage extends PublicChannel { @@ -14,13 +14,13 @@ export interface PublicChannelStorage extends PublicChannel { } export interface PublicChannelStatus { - address: string + id: string unread: boolean newestMessage: ChannelMessage } export interface PublicChannelSubscription { - address: string + id: string subscribed: boolean } @@ -29,7 +29,7 @@ export interface ChannelMessage { type: number message: string createdAt: number - channelAddress: string + channelId: string signature: string pubKey: string media?: FileMetadata @@ -69,16 +69,16 @@ export interface CreatedChannelResponse { } export interface SetChannelSubscribedPayload { - channelAddress: string + channelId: string } export interface SetCurrentChannelPayload { - channelAddress: string + channelId: string } export interface SetChannelMessagesSliceValuePayload { messagesSlice: number - channelAddress: string + channelId: string } export interface PendingMessage { @@ -87,7 +87,7 @@ export interface PendingMessage { export interface SendInitialChannelMessagePayload { channelName: string - channelAddress: string + channelId: string } export interface SendNewUserInfoMessagePayload { certificates: string[] @@ -100,11 +100,11 @@ export interface IncomingMessages { export interface CacheMessagesPayload { messages: ChannelMessage[] - channelAddress: string + channelId: string } export interface MarkUnreadChannelPayload { - channelAddress: string + channelId: string message?: ChannelMessage } @@ -113,13 +113,13 @@ export interface UpdateNewestMessagePayload { } export interface DeleteChannelFromStorePayload { - channelAddress: string + channelId: string } export interface ClearMessagesCachePayload { - channelAddress: string + channelId: string } export function instanceOfChannelMessage(object: any): object is ChannelMessage { - return 'channelAddress' in object + return 'channelId' in object } diff --git a/packages/types/src/files.ts b/packages/types/src/files.ts index afdf0c95dd..a205808a33 100644 --- a/packages/types/src/files.ts +++ b/packages/types/src/files.ts @@ -14,7 +14,7 @@ export interface FileContent { export interface FileMessage { id: string - channelAddress: string + channelId: string } export interface UploadFilePayload { diff --git a/packages/types/src/message.ts b/packages/types/src/message.ts index 3bc7021af8..5ee50ab877 100644 --- a/packages/types/src/message.ts +++ b/packages/types/src/message.ts @@ -29,7 +29,7 @@ export interface PushNotificationPayload { export interface WriteMessagePayload { message: string id?: string - channelAddress?: string + channelId?: string type?: MessageType media?: FileMetadata } @@ -40,17 +40,17 @@ export interface PublicKeyMappingPayload { } export interface AddPublicChannelsMessagesBasePayload { - channelAddress: string + channelId: string } export interface PublicChannelsMessagesBase { - channelAddress: string + channelId: string messages: EntityState display: number } export interface SetDisplayedMessagesNumberPayload { - channelAddress: string + channelId: string display: number } @@ -72,22 +72,22 @@ export interface MessageSendingStatus { export interface AskForMessagesPayload { ids: string[] peerId: string - channelAddress: string + channelId: string communityId: string } export interface ChannelMessagesIdsResponse { ids: string[] - channelAddress: string + channelId: string communityId: string } export interface DeleteChannelEntryPayload { - channelAddress: string + channelId: string } export interface SendDeletionMessagePayload { - channelAddress: string + channelId: string } export interface TestMessage { From 99d7b9f76e50c6db31ee9b6712aa3fe741dd73de Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Fri, 19 May 2023 12:17:06 +0200 Subject: [PATCH 23/35] fix notifications --- .../sagas/notifications/notifications.saga.ts | 10 +++++---- .../sagas/notifications/notifications.test.ts | 22 +++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts index 01deb54e55..fba00c8bc9 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts @@ -36,6 +36,7 @@ export function* displayMessageNotificationSaga( const incomingMessages = action.payload.messages const currentchannelId = yield* select(publicChannels.selectors.currentchannelId) + const publicChannelsSelector = yield* select(publicChannels.selectors.publicChannels) const currentIdentity = yield* select(identity.selectors.currentIdentity) const certificatesMapping = yield* select(users.selectors.certificatesMapping) @@ -49,6 +50,7 @@ export function* displayMessageNotificationSaga( for (const message of incomingMessages) { const focused = yield* call(isWindowFocused) + const channelName = publicChannelsSelector.find((channel) => channel.id === message.channelId).name // Do not display notifications for active channel (when the app is in foreground) if (focused && message.channelId === currentchannelId) return @@ -66,12 +68,12 @@ export function* displayMessageNotificationSaga( // Do not display when message is not verified if (!action.payload.isVerified) return - let label = `New message from @${sender} in #${message.channelId}` + let label = `New message from @${sender} in #${channelName}` let body = `${message.message.substring(0, 64)}${message.message.length > 64 ? '...' : ''}` // Change notification's label for the image if (message.type === MessageType.Image) { - label = `@${sender} sent an image in #${message.channelId}` + label = `@${sender} sent an image in #${channelName}` body = undefined } @@ -79,11 +81,11 @@ export function* displayMessageNotificationSaga( if (message.type === MessageType.File) { const status = downloadStatuses[message.id] - label = `@${sender} sends file in #${message.channelId}` + label = `@${sender} sends file in #${channelName}` body = undefined if (status?.downloadState === DownloadState.Completed) { - label = `@${sender} sent a file in #${message.channelId}` + label = `@${sender} sent a file in #${channelName}` body = 'Download complete. Click to show file in folder.' } } diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts index 13542f247a..2d626a3071 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.test.ts @@ -183,14 +183,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.id}`, + label: `New message from @${bob.nickname} in #${sailingChannel.name}`, body: message.message, channel: sailingChannel.id, sound: NotificationsSounds.pow }) .run() - expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.id}`, { + expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.name}`, { body: message.message, icon: '../../build/icon.png', silent: true @@ -292,14 +292,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.id}`, + label: `New message from @${bob.nickname} in #${sailingChannel.name}`, body: message.message, channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.id}`, { + expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.name}`, { body: message.message, icon: '../../build/icon.png', silent: true @@ -323,14 +323,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), true]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.id}`, + label: `New message from @${bob.nickname} in #${sailingChannel.name}`, body: message.message, channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.id}`, { + expect(notification).toBeCalledWith(`New message from @${bob.nickname} in #${sailingChannel.name}`, { body: message.message, icon: '../../build/icon.png', silent: true @@ -415,7 +415,7 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `New message from @${bob.nickname} in #${sailingChannel.id}`, + label: `New message from @${bob.nickname} in #${sailingChannel.name}`, body: message.message, channel: sailingChannel.id, sound: NotificationsSounds.none @@ -477,14 +477,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `@${bob.nickname} sent an image in #${sailingChannel.id}`, + label: `@${bob.nickname} sent an image in #${sailingChannel.name}`, body: undefined, channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`@${bob.nickname} sent an image in #${sailingChannel.id}`, { + expect(notification).toBeCalledWith(`@${bob.nickname} sent an image in #${sailingChannel.name}`, { body: undefined, icon: '../../build/icon.png', silent: true @@ -518,14 +518,14 @@ describe('displayNotificationsSaga', () => { .withState(store.getState()) .provide([[call.fn(isWindowFocused), false]]) .call(createNotification, { - label: `@${bob.nickname} sends file in #${sailingChannel.id}`, + label: `@${bob.nickname} sends file in #${sailingChannel.name}`, body: undefined, channel: sailingChannel.id, sound: NotificationsSounds.librarianShhh }) .run() - expect(notification).toBeCalledWith(`@${bob.nickname} sends file in #${sailingChannel.id}`, { + expect(notification).toBeCalledWith(`@${bob.nickname} sends file in #${sailingChannel.name}`, { body: undefined, icon: '../../build/icon.png', silent: true From edb27c90b047534e14ac4b3dcfe82d284dbe6944 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Fri, 19 May 2023 13:57:33 +0200 Subject: [PATCH 24/35] E2E test - correct channel replication after removal in user's absence --- .../e2e-tests/src/tests/twoClients.test.ts | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/e2e-tests/src/tests/twoClients.test.ts b/packages/e2e-tests/src/tests/twoClients.test.ts index a5d6be3269..74b72d1572 100644 --- a/packages/e2e-tests/src/tests/twoClients.test.ts +++ b/packages/e2e-tests/src/tests/twoClients.test.ts @@ -220,23 +220,6 @@ describe('Two Clients', () => { expect(channels.length).toEqual(2) }) - it('Channel deletion - Owner recreate general channel', async () => { - const isGeneralChannel = await generalChannel.messageInput.isDisplayed() - expect(isGeneralChannel).toBeTruthy() - await channelContextMenu.openMenu() - await channelContextMenu.openDeletionChannelModal() - await channelContextMenu.deleteChannel() - const channels = await sidebar.getChannelList() - expect(channels.length).toEqual(2) - }) - it('Channel deletion - User see information about recreation general channel', async () => { - await sidebar2.switchChannel('general') - await new Promise(resolve => setTimeout(() => resolve(), 2000)) - const messages = await generalChannel2.getUserMessages(ownerUsername) - const text = await messages[0].getText() - expect(text).toEqual(`@${ownerUsername} deleted all messages in #general`) - }) - it('Leave community', async () => { const settingsModal = await new Sidebar(guestApp.driver).openSettings() const isSettingsModal = await settingsModal.element.isDisplayed() @@ -250,6 +233,18 @@ describe('Two Clients', () => { await debugModal.close() }) } + // Delete general channel while guest is absent + it('Channel deletion - Owner recreate general channel', async () => { + await new Promise(resolve => setTimeout(() => resolve(), 2000)) + const isGeneralChannel = await generalChannel.messageInput.isDisplayed() + expect(isGeneralChannel).toBeTruthy() + await channelContextMenu.openMenu() + await channelContextMenu.openDeletionChannelModal() + await channelContextMenu.deleteChannel() + const channels = await sidebar.getChannelList() + expect(channels.length).toEqual(2) + }) + it('Leave community - Guest re-join to community successfully', async () => { const joinCommunityModal = new JoinCommunityModal(guestApp.driver) const isJoinCommunityModal = await joinCommunityModal.element.isDisplayed() @@ -264,6 +259,20 @@ describe('Two Clients', () => { await registerModal2.typeUsername(joiningUserUsername2) await registerModal2.submit() }) + + // Check correct channels replication + it('Channel deletion - User see information about recreation general channel and see correct amount of messages', async () => { + generalChannel2 = new Channel(guestApp.driver, 'general') + await generalChannel2.element.isDisplayed() + await new Promise(resolve => setTimeout(() => resolve(), 10000)) + const messages = await generalChannel2.getUserMessages(ownerUsername) + const text1 = await messages[0].getText() + const text2 = await messages[1].getText() + expect(messages.length).toEqual(2) + expect(text1).toEqual(`@${ownerUsername} deleted all messages in #general`) + expect(text2).toEqual(`@${joiningUserUsername2} has joined Testcommunity! 🎉`) + }) + it('Leave community - Guest sends a message', async () => { generalChannel2 = new Channel(guestApp.driver, 'general') await generalChannel2.element.isDisplayed() From 731a8b5a6b74380eb90ef2ff0b8bc6f7d5bf69f5 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Mon, 22 May 2023 09:38:36 +0200 Subject: [PATCH 25/35] fix typo --- .../src/renderer/components/Channel/Channel.tsx | 10 +++++----- .../ChannelsPanel/ChannelsPanel.test.tsx | 2 +- .../Sidebar/ChannelsPanel/ChannelsPanel.tsx | 6 +++--- .../components/Sidebar/Sidebar.stories.tsx | 2 +- .../src/renderer/components/Sidebar/Sidebar.tsx | 4 ++-- .../widgets/channels/DirectMessageInput.tsx | 4 ++-- .../notifications/notifications.click.test.ts | 4 ++-- .../sagas/notifications/notifications.saga.ts | 4 ++-- .../desktop/src/rtl-tests/channel.main.test.tsx | 17 ++++++++++++++++- .../files/uploadFile/uploadFile.saga.test.ts | 4 ++-- .../sagas/files/uploadFile/uploadFile.saga.ts | 2 +- .../incomingMessages/incomingMessages.saga.ts | 4 ++-- .../manageCache/extendChannelCache.saga.ts | 2 +- .../manageCache/resetChannelCache.saga.ts | 2 +- .../src/sagas/messages/messages.selectors.ts | 4 ++-- .../sendMessage/sendMessage.saga.test.ts | 6 +++--- .../messages/sendMessage/sendMessage.saga.ts | 2 +- .../markUnreadChannels.saga.ts | 4 ++-- .../publicChannels/publicChannels.selectors.ts | 14 +++++++------- .../publicChannels/publicChannels.slice.ts | 4 ++-- .../publicChannels/publicChannels.transform.ts | 2 +- .../publicChannels/publicChannels.types.ts | 2 +- 22 files changed, 60 insertions(+), 45 deletions(-) diff --git a/packages/desktop/src/renderer/components/Channel/Channel.tsx b/packages/desktop/src/renderer/components/Channel/Channel.tsx index 2661d45329..678a348107 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.tsx @@ -33,7 +33,7 @@ const Channel = () => { const user = useSelector(identity.selectors.currentIdentity) - const currentchannelId = useSelector(publicChannels.selectors.currentchannelId) + const currentChannelId = useSelector(publicChannels.selectors.currentChannelId) const currentChannelName = useSelector(publicChannels.selectors.currentChannelName) const currentChannelMessagesCount = useSelector( @@ -205,11 +205,11 @@ const Channel = () => { useEffect(() => { dispatch(messages.actions.resetCurrentPublicChannelCache()) - }, [currentchannelId]) + }, [currentChannelId]) const channelComponentProps: ChannelComponentProps = { user: user, - channelId: currentchannelId, + channelId: currentChannelId, channelName: currentChannelName, messages: { count: currentChannelMessagesCount, @@ -245,12 +245,12 @@ const Channel = () => { return ( <> - {currentchannelId && ( + {currentChannelId && ( )} diff --git a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx index 07a1f09659..4f06db7684 100644 --- a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.test.tsx @@ -57,7 +57,7 @@ describe('Channels panel', () => { channels={channels} unreadChannels={[]} setCurrentChannel={function (_id: string): void {}} - currentchannelId={generalChannel.id} + currentChannelId={generalChannel.id} createChannelModal={{ open: false, handleOpen: function (_args?: any): any {}, diff --git a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx index 85d0b90e99..e5607da7c9 100644 --- a/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/ChannelsPanel/ChannelsPanel.tsx @@ -10,7 +10,7 @@ export interface ChannelsPanelProps { channels: PublicChannel[] unreadChannels: string[] setCurrentChannel: (id: string) => void - currentchannelId: string + currentChannelId: string createChannelModal: ReturnType } @@ -18,7 +18,7 @@ const ChannelsPanel: React.FC = ({ channels, unreadChannels, setCurrentChannel, - currentchannelId, + currentChannelId, createChannelModal }) => { return ( @@ -35,7 +35,7 @@ const ChannelsPanel: React.FC = ({ {channels.map((channel, index) => { const unread = unreadChannels.some(id => id === channel.id) - const selected = currentchannelId === channel.id + const selected = currentChannelId === channel.id return ( = args => { position: 'relative' }}> - + diff --git a/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx b/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx index 5946a24ba6..493b7cda88 100644 --- a/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx +++ b/packages/desktop/src/renderer/components/Sidebar/Sidebar.tsx @@ -17,7 +17,7 @@ const Sidebar = () => { const currentCommunity = useSelector(communities.selectors.currentCommunity) - const currentchannelId = useSelector(publicChannels.selectors.currentchannelId) + const currentChannelId = useSelector(publicChannels.selectors.currentChannelId) // Workaround for Redux bug, issue: https://github.com/TryQuiet/quiet/issues/1332 useSelector(publicChannels.selectors.sortedChannels) @@ -40,7 +40,7 @@ const Sidebar = () => { channels: publicChannelsSelector, unreadChannels: unreadChannels, setCurrentChannel: setCurrentChannel, - currentchannelId: currentchannelId, + currentChannelId: currentChannelId, createChannelModal: createChannelModal } diff --git a/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx b/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx index 5dc6cfbb96..706f06e3bc 100644 --- a/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx +++ b/packages/desktop/src/renderer/containers/widgets/channels/DirectMessageInput.tsx @@ -31,13 +31,13 @@ export const ChannelInput = () => { const { onChange, onEnter, resetDebounce } = useDirectMessageInputActions() - const currentchannelId = useSelector(publicChannels.selectors.currentchannelId) + const currentChannelId = useSelector(publicChannels.selectors.currentChannelId) const currentChannelName = useSelector(publicChannels.selectors.currentChannelName) const user = useSelector(identity.selectors.currentIdentity) return ( { store.dispatch(publicChannels.actions.setCurrentChannel({ channelId: generalId })) // Verify current channel is 'general - expect(publicChannels.selectors.currentchannelId(store.getState())).toBe(generalId) + expect(publicChannels.selectors.currentChannelId(store.getState())).toBe(generalId) runSaga(function* (): Generator { const notification = yield* call(createNotification, notificationData) @@ -75,7 +75,7 @@ describe('clicking in notification', () => { }) // Confirm current channel address has changed - expect(publicChannels.selectors.currentchannelId(store.getState())).toBe(sailingId) + expect(publicChannels.selectors.currentChannelId(store.getState())).toBe(sailingId) }) it('opens file explorer', async () => { diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts index fba00c8bc9..8f843a9e9b 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts @@ -35,7 +35,7 @@ export function* displayMessageNotificationSaga( ): Generator { const incomingMessages = action.payload.messages - const currentchannelId = yield* select(publicChannels.selectors.currentchannelId) + const currentChannelId = yield* select(publicChannels.selectors.currentChannelId) const publicChannelsSelector = yield* select(publicChannels.selectors.publicChannels) const currentIdentity = yield* select(identity.selectors.currentIdentity) @@ -53,7 +53,7 @@ export function* displayMessageNotificationSaga( const channelName = publicChannelsSelector.find((channel) => channel.id === message.channelId).name // Do not display notifications for active channel (when the app is in foreground) - if (focused && message.channelId === currentchannelId) return + if (focused && message.channelId === currentChannelId) return // Do not display notifications for own messages const sender = certificatesMapping[message.pubKey]?.username diff --git a/packages/desktop/src/rtl-tests/channel.main.test.tsx b/packages/desktop/src/rtl-tests/channel.main.test.tsx index 25d9eb0817..aa40ec14a5 100644 --- a/packages/desktop/src/rtl-tests/channel.main.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.main.test.tsx @@ -138,7 +138,7 @@ describe('Channel', () => { expect(messageInput).toBeVisible() }) - it('filters out suspicious messages', async () => { + it.only('filters out suspicious messages', async () => { const { store, runSaga } = await prepareStore( {}, socket // Fork state manager's sagas @@ -154,6 +154,12 @@ describe('Channel', () => { const generalId = Object.keys(entities).find(key => entities[key].name === 'general') + console.log({ generalId }) + + await act(async () => { + store.dispatch(publicChannels.actions.setCurrentChannel({ channelId: generalId })) + }) + const alice = await factory.create< ReturnType['payload'] >('Identity', { id: community.id, nickname: 'alice' }) @@ -185,6 +191,15 @@ describe('Channel', () => { ...( await factory.build('Message', { identity: alice + // message: { + // id: Math.random().toString(36).substr(2.9), + // type: MessageType.Basic, + // message: 'message', + // createdAt: DateTime.utc().valueOf(), + // channelId: generalId, + // signature: '', + // pubKey: johnPublicKey + // } }) ).payload.message, id: Math.random().toString(36).substr(2.9), diff --git a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts index 093018f125..6ad424add0 100644 --- a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts +++ b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.test.ts @@ -16,7 +16,7 @@ import { uploadFileSaga } from './uploadFile.saga' import { FactoryGirl } from 'factory-girl' import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' -import { currentchannelId } from '../../publicChannels/publicChannels.selectors' +import { currentChannelId } from '../../publicChannels/publicChannels.selectors' import { DownloadState, FileMetadata } from '../../files/files.types' import { filesActions } from '../files.slice' import { generateMessageId } from '../../messages/utils/message.utils' @@ -70,7 +70,7 @@ describe('uploadFileSaga', () => { test('uploading file', async () => { const socket = { emit: jest.fn() } as unknown as Socket - const currentChannel = currentchannelId(store.getState()) + const currentChannel = currentChannelId(store.getState()) const peerId = alice.peerId.id diff --git a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts index 835a803ef6..aa4939830d 100644 --- a/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts +++ b/packages/state-manager/src/sagas/files/uploadFile/uploadFile.saga.ts @@ -16,7 +16,7 @@ export function* uploadFileSaga( ): Generator { const identity = yield* select(identitySelectors.currentIdentity) - const currentChannel = yield* select(publicChannelsSelectors.currentchannelId) + const currentChannel = yield* select(publicChannelsSelectors.currentChannelId) const id = yield* call(generateMessageId) diff --git a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts index 1cb768b054..4df2001dc7 100644 --- a/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts +++ b/packages/state-manager/src/sagas/messages/incomingMessages/incomingMessages.saga.ts @@ -11,8 +11,8 @@ export function* incomingMessagesSaga( ): Generator { for (const incomingMessage of action.payload.messages) { // Proceed only for messages from current channel - const currentchannelId = yield* select(publicChannelsSelectors.currentchannelId) - if (incomingMessage.channelId !== currentchannelId) { + const currentChannelId = yield* select(publicChannelsSelectors.currentChannelId) + if (incomingMessage.channelId !== currentChannelId) { return } diff --git a/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts b/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts index 4dbda3bb9c..7e692ae2b8 100644 --- a/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts +++ b/packages/state-manager/src/sagas/messages/manageCache/extendChannelCache.saga.ts @@ -9,7 +9,7 @@ import { SetDisplayedMessagesNumberPayload } from '../messages.types' export function* extendCurrentPublicChannelCacheSaga(): Generator { const communityId = yield* select(communitiesSelectors.currentCommunityId) - const channelId = yield* select(publicChannelsSelectors.currentchannelId) + const channelId = yield* select(publicChannelsSelectors.currentChannelId) const channelMessagesChunkSize = 50 diff --git a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts index 7083c3c4d7..24ef367ef6 100644 --- a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts +++ b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.ts @@ -7,7 +7,7 @@ import { messagesActions } from '../messages.slice' import { SetDisplayedMessagesNumberPayload } from '../messages.types' export function* resetCurrentPublicChannelCacheSaga(): Generator { - const channelId = yield* select(publicChannelsSelectors.currentchannelId) + const channelId = yield* select(publicChannelsSelectors.currentChannelId) const channelMessagesChunkSize = 50 diff --git a/packages/state-manager/src/sagas/messages/messages.selectors.ts b/packages/state-manager/src/sagas/messages/messages.selectors.ts index 6389bfa61e..2c0beee932 100644 --- a/packages/state-manager/src/sagas/messages/messages.selectors.ts +++ b/packages/state-manager/src/sagas/messages/messages.selectors.ts @@ -1,7 +1,7 @@ import { createSelector } from 'reselect' import { AUTODOWNLOAD_SIZE_LIMIT } from '../../constants' import { channelMessagesAdapter } from '../publicChannels/publicChannels.adapter' -import { currentchannelId } from '../publicChannels/publicChannels.selectors' +import { currentChannelId } from '../publicChannels/publicChannels.selectors' import { StoreKeys } from '../store.keys' import { CreatedSelectors, StoreState } from '../store.types' import { certificatesMapping } from '../users/users.selectors' @@ -38,7 +38,7 @@ export const publicChannelsMessagesBase = createSelector(messagesSlice, reducerS export const currentPublicChannelMessagesBase = createSelector( publicChannelsMessagesBase, - currentchannelId, + currentChannelId, (base, address) => { return base[address] } diff --git a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts index 0209ab8bf0..78eb2e6831 100644 --- a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.test.ts @@ -21,7 +21,7 @@ import { messagesActions } from '../messages.slice' import { generateMessageId, getCurrentTime } from '../utils/message.utils' import { sendMessageSaga } from './sendMessage.saga' import { FactoryGirl } from 'factory-girl' -import { currentchannelId } from '../../publicChannels/publicChannels.selectors' +import { currentChannelId } from '../../publicChannels/publicChannels.selectors' import { PublicChannel } from '../../publicChannels/publicChannels.types' import { publicChannelsActions } from '../../publicChannels/publicChannels.slice' import { DateTime } from 'luxon' @@ -69,7 +69,7 @@ describe('sendMessageSaga', () => { test('sign and send message in current channel', async () => { const socket = { emit: jest.fn() } as unknown as Socket - const currentChannel = currentchannelId(store.getState()) + const currentChannel = currentChannelId(store.getState()) const reducer = combineReducers(reducers) await expectSaga( @@ -150,7 +150,7 @@ describe('sendMessageSaga', () => { const socket = { emit: jest.fn() } as unknown as Socket const messageId = Math.random().toString(36).substr(2.9) - const currentChannel = currentchannelId(store.getState()) + const currentChannel = currentChannelId(store.getState()) const media: FileMetadata = { cid: 'cid', diff --git a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts index a64a1ba2ba..ef598a283a 100644 --- a/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts +++ b/packages/state-manager/src/sagas/messages/sendMessage/sendMessage.saga.ts @@ -28,7 +28,7 @@ export function* sendMessageSaga( const signatureArrayBuffer = yield* call(sign, action.payload.message, keyObject) const signature = yield* call(arrayBufferToString, signatureArrayBuffer) - const currentChannel = yield* select(publicChannelsSelectors.currentchannelId) + const currentChannel = yield* select(publicChannelsSelectors.currentChannelId) const createdAt = yield* call(getCurrentTime) diff --git a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts index 117f37925f..356193c1c0 100644 --- a/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/markUnreadChannels/markUnreadChannels.saga.ts @@ -9,13 +9,13 @@ import { identitySelectors } from '../../identity/identity.selectors' export function* markUnreadChannelsSaga( action: PayloadAction['payload']> ): Generator { - const currentchannelId = yield* select(publicChannelsSelectors.currentchannelId) + const currentChannelId = yield* select(publicChannelsSelectors.currentChannelId) const { messages } = action.payload for (const message of messages) { // Do not proceed for current channel - if (message.channelId !== currentchannelId) { + if (message.channelId !== currentChannelId) { const payload: MarkUnreadChannelPayload = { channelId: message.channelId, message: message diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts index e9b49428e3..99fe5cb4b6 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts @@ -87,11 +87,11 @@ export const sortedChannels = createSelector(publicChannels, (channels) => { return sorted }) -export const currentchannelId_OLD = createSelector( +export const currentChannelId_OLD = createSelector( selectState, (state) => { if (!state) return undefined - return state.currentchannelId + return state.currentChannelId } ) @@ -99,7 +99,7 @@ export const generalChannel = createSelector(publicChannels, publicChannelsSelec return publicChannelsSelector.find(channel => channel.name === 'general') }) -export const currentchannelId = createSelector( +export const currentChannelId = createSelector( selectState, generalChannel, (state, general) => { @@ -107,14 +107,14 @@ export const currentchannelId = createSelector( if (!state) { return undefined } - if (state.currentchannelId === INITIAL_CURRENT_CHANNEL_ID) { + if (state.currentChannelId === INITIAL_CURRENT_CHANNEL_ID) { if (general) { return general.id } else { return 'general'// case for tests when is no channel in store } } else { - return state.currentchannelId + return state.currentChannelId } } ) @@ -149,7 +149,7 @@ export const dynamicSearchedChannels = (channelInput: string) => // Is being used in tests export const currentChannel = createSelector( - currentchannelId, + currentChannelId, selectChannels, (id, channels) => { if (!id) return undefined @@ -293,7 +293,7 @@ export const unreadChannels = createSelector( export const publicChannelsSelectors = { publicChannels, subscribedChannels, - currentchannelId, + currentChannelId, currentChannelName, currentChannel, currentChannelMessages, diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts index 248b40adf7..c0f4b83113 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.slice.ts @@ -34,7 +34,7 @@ import { Identity } from '../identity/identity.types' const log = logger('publicChannels') export class PublicChannelsState { - public currentchannelId: string = INITIAL_CURRENT_CHANNEL_ID + public currentChannelId: string = INITIAL_CURRENT_CHANNEL_ID public pendingGeneralChannelRecreation: boolean = false @@ -108,7 +108,7 @@ export const publicChannelsSlice = createSlice({ channelsReplicated: (state, _action: PayloadAction) => state, setCurrentChannel: (state, action: PayloadAction) => { const { channelId } = action.payload - state.currentchannelId = channelId + state.currentChannelId = channelId }, cacheMessages: (state, action: PayloadAction) => { const { messages, channelId } = action.payload diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts index 96f1946a07..006498557d 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts @@ -10,7 +10,7 @@ export const PublicChannelsTransform = createTransform( (outboundState: PublicChannelsState, _key) => { return { ...outboundState, - currentchannelId: publicChannelsAdapter + currentChannelId: publicChannelsAdapter .getSelectors() .selectAll(outboundState.channels) .find(channel => channel.name === 'general').id, diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts index 3b7463c584..64ae09cb96 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.types.ts @@ -1,7 +1,7 @@ import { Dictionary, EntityState } from '@reduxjs/toolkit' import { FileMetadata } from '../files/files.types' -export const INITIAL_CURRENT_CHANNEL_ID = 'initialCurrentchannelId' +export const INITIAL_CURRENT_CHANNEL_ID = 'initialcurrentChannelId' export interface PublicChannel { name: string From eadc4dda0905d5c1bcc213d8d253db3e2b8904f5 Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Mon, 22 May 2023 15:21:23 +0200 Subject: [PATCH 26/35] temporary adjust storage to support both old and new channels and messages data structures --- packages/backend/src/storage/storage.ts | 60 +++++++++++++++---- packages/backend/src/validation/validators.ts | 9 ++- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index a24178307d..08429a15a3 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -8,6 +8,7 @@ import { verifyUserCert } from '@quiet/identity' import type { IPFS, create as createType } from 'ipfs-core' +import { create } from 'ipfs-core' import type { Libp2p } from 'libp2p' import OrbitDB from 'orbit-db' import EventStore from 'orbit-db-eventstore' @@ -32,7 +33,6 @@ import { stringToArrayBuffer } from 'pvutils' import { StorageEvents } from './types' import { IpfsFilesManager, IpfsFilesManagerEvents } from './ipfsFileManager' -import { create } from 'ipfs-core' import { CID } from 'multiformats/cid' import { ChannelMessage, ConnectionProcessInfo, FileMetadata, NoCryptoEngineError, PublicChannel, PushNotificationPayload, SaveCertificatePayload, SocketActionTypes, User } from '@quiet/types' @@ -249,6 +249,12 @@ export class Storage extends EventEmitter { }) } + private async migrateChannelsDb() { + // if owner migrateChannelsDb + // do it only once + // if new channel db has general return and do nothing + } + private async createDbForChannels() { log('createDbForChannels init') this.channels = await this.orbitdb.keyvalue('public-channels', { @@ -355,6 +361,11 @@ export class Storage extends EventEmitter { public async subscribeToChannel(channelData: PublicChannel): Promise { let db: EventStore + // @ts-ignore + if (channelData.address) { + // @ts-ignore + channelData.id = channelData.address + } let repo = this.publicChannelsRepos.get(channelData.id) if (repo) { db = repo.db @@ -387,12 +398,14 @@ export class Storage extends EventEmitter { db.events.on('replicate.progress', async (address, _hash, entry, progress, total) => { log(`progress ${progress as string}/${total as string}. Address: ${address as string}`) - const message = entry.payload.value + const messages = this.transformMessages([entry.payload.value]) - const verified = await this.verifyMessage(message) + const verified = await this.verifyMessage(messages[0]) + + const message = messages[0] this.emit(StorageEvents.LOAD_MESSAGES, { - messages: [entry.payload.value], + messages: [message], isVerified: verified }) @@ -401,6 +414,7 @@ export class Storage extends EventEmitter { if (!verified) return // Do not notify about old messages + // @ts-ignore if (parseInt(message.createdAt) < parseInt(process.env.CONNECTION_TIME || '')) return const username = this.getUserNameFromCert(message.pubKey) @@ -444,14 +458,34 @@ export class Storage extends EventEmitter { }) } + public transformMessages(msgs: ChannelMessage[]) { + console.log('---------------- TRANSFORMING MESSAGES ----------------------') + const messages = msgs.map((msg) => { + console.log('processing message ', msg.id) + // @ts-ignore + if (msg.channelAddress) { + console.log('message before transformation ', msg) + // @ts-ignore + msg.channelId = msg.channelAddress + // @ts-ignore + delete msg.channelAddress + console.log('transformed message to new format ', msg) + return msg + } + return msg + }) + return messages + } + public async askForMessages(channelId: string, ids: string[]) { const repo = this.publicChannelsRepos.get(channelId) if (!repo) return const messages = this.getAllEventLogEntries(repo.db) - const filteredMessages: ChannelMessage[] = [] + let filteredMessages: ChannelMessage[] = [] for (const id of ids) { filteredMessages.push(...messages.filter(i => i.id === id)) } + filteredMessages = this.transformMessages(filteredMessages) this.emit(StorageEvents.LOAD_MESSAGES, { messages: filteredMessages, isVerified: true @@ -460,14 +494,18 @@ export class Storage extends EventEmitter { } private async createChannel(data: PublicChannel): Promise> { + console.log('creating channel') if (!validate.isChannel(data)) { log.error('STORAGE: Invalid channel format') throw new Error('Create channel validation error') } log(`Creating channel ${data.id}`) + // @ts-ignore + const channelId = data.id || data.address + const db: EventStore = await this.orbitdb.log( - `channels.${data.id}`, + `channels.${channelId}`, { accessController: { type: 'messagesaccess', @@ -476,9 +514,9 @@ export class Storage extends EventEmitter { } ) - const channel = this.channels.get(data.id) + const channel = this.channels.get(channelId) if (channel === undefined) { - await this.channels.put(data.id, { + await this.channels.put(channelId, { ...data }) this.emit(StorageEvents.CREATED_CHANNEL, { @@ -486,11 +524,11 @@ export class Storage extends EventEmitter { }) } - this.publicChannelsRepos.set(data.id, { db, eventsAttached: false }) - log(`Set ${data.id} to local channels`) + this.publicChannelsRepos.set(channelId, { db, eventsAttached: false }) + log(`Set ${channelId} to local channels`) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await db.load({ fetchEntryTimeout: 2000 }) - log(`Created channel ${data.id}`) + log(`Created channel ${channelId}`) return db } diff --git a/packages/backend/src/validation/validators.ts b/packages/backend/src/validation/validators.ts index 6c0696c4d9..1902c1aa18 100644 --- a/packages/backend/src/validation/validators.ts +++ b/packages/backend/src/validation/validators.ts @@ -14,7 +14,8 @@ const messageMediaSchema = joi.object({ height: joi.number().allow(null), message: joi.object({ id: joi.string().required(), - channelId: joi.string().required() + channelId: joi.string(), + channelAddress: joi.string() }) }) @@ -24,7 +25,8 @@ const messageSchema = joi.object({ message: joi.alternatives(joi.string(), joi.binary()).required(), media: messageMediaSchema, createdAt: joi.number().required(), - channelId: joi.string().required(), + channelId: joi.string(), + channelAddress: joi.string(), signature: joi.string().required(), pubKey: joi.string().required() }) @@ -34,7 +36,8 @@ const channelSchema = joi.object({ description: joi.string().required(), owner: joi.string().required(), timestamp: joi.number().required(), - id: joi.string().required() + id: joi.string(), + address: joi.string() }) export const isUser = (publicKey: string, halfKey: string): boolean => { From 0aad48608296dfd8f75d2df156aadf055073198f Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Mon, 22 May 2023 15:57:17 +0200 Subject: [PATCH 27/35] transform channel on replication --- packages/backend/src/storage/storage.ts | 41 +++++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index 08429a15a3..004f8ebb85 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -252,7 +252,7 @@ export class Storage extends EventEmitter { private async migrateChannelsDb() { // if owner migrateChannelsDb // do it only once - // if new channel db has general return and do nothing + // if new channel db has general return and do nothing } private async createDbForChannels() { @@ -269,15 +269,29 @@ export class Storage extends EventEmitter { }) this.channels.events.on('replicated', async () => { + log('REPLICATED: Channels') this.emit(SocketActionTypes.CONNECTION_PROCESS_INFO, ConnectionProcessInfo.CHANNELS_REPLICATED) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await this.channels.load({ fetchEntryTimeout: 2000 }) + + const channels = Object.values(this.channels.all).map(channel => { + return this.transformChannel(channel) + }) + + const keyValueChannels: { + [key: string]: PublicChannel, + } = {} + + channels.forEach(channel => { + keyValueChannels[channel.id] = channel + }) + this.emit(StorageEvents.LOAD_PUBLIC_CHANNELS, { - channels: this.channels.all as unknown as { [key: string]: PublicChannel } + channels: keyValueChannels }) - Object.values(this.channels.all).forEach(async (channel: PublicChannel) => { + channels.forEach(async (channel: PublicChannel) => { await this.subscribeToChannel(channel) }) }) @@ -287,6 +301,7 @@ export class Storage extends EventEmitter { log('ALL CHANNELS COUNT:', Object.keys(this.channels.all).length) log('ALL CHANNELS COUNT:', Object.keys(this.channels.all)) Object.values(this.channels.all).forEach(async (channel: PublicChannel) => { + channel = this.transformChannel(channel) await this.subscribeToChannel(channel) }) log('STORAGE: Finished createDbForChannels') @@ -477,6 +492,20 @@ export class Storage extends EventEmitter { return messages } + public transformChannel(channel: PublicChannel) { + // @ts-ignore + if (channel.address) { + console.log('channel before transformation ', channel) + // @ts-ignore + channel.id = channel.address + // @ts-ignore + delete channel.address + console.log('transformed channel to new format ', channel) + return channel + } + return channel + } + public async askForMessages(channelId: string, ids: string[]) { const repo = this.publicChannelsRepos.get(channelId) if (!repo) return @@ -532,9 +561,9 @@ export class Storage extends EventEmitter { return db } - public async deleteChannel(payload: {channelId: string}) { - const channelId = payload.channelId - log('deleteChannel:channelId', channelId) + public async deleteChannel(payload: { channelId: string }) { + const channelId = payload.channelId + log('deleteChannel:channelId', channelId) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await this.channels.load({ fetchEntryTimeout: 15000 }) const channel = this.channels.get(channelId) From f8c5fbb13f415d0778de9dff1bd3e238d16f91a7 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 23 May 2023 11:07:01 +0200 Subject: [PATCH 28/35] state channels transform --- .../publicChannels.transform.ts | 95 ++++++++++++++++++- 1 file changed, 90 insertions(+), 5 deletions(-) diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts index 8434f5c9ba..f46b26158c 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts @@ -1,3 +1,5 @@ +import { ChannelMessage, PublicChannelStatus, PublicChannelStorage } from '@quiet/types' +import { Dictionary, EntityState } from '@reduxjs/toolkit' import { createTransform } from 'redux-persist' import { StoreKeys } from '../store.keys' import { publicChannelsAdapter, publicChannelsSubscriptionsAdapter } from './publicChannels.adapter' @@ -8,12 +10,21 @@ export const PublicChannelsTransform = createTransform( return { ...inboundState } }, (outboundState: PublicChannelsState, _key: any) => { - const selectors = publicChannelsAdapter.getSelectors() - const publicChannelStorage = selectors.selectAll(outboundState.channels) - const generalChannel = publicChannelStorage.find(channel => channel.name === 'general') - const generalChannelId = generalChannel?.id || '' + const generalChannelId = getGeneralChannelId(outboundState) + + const transformedOutboundState = { ...outboundState } as any + if (transformedOutboundState.currentChannelAddress) { + delete transformedOutboundState.currentChannelAddress + } + + outboundState.channels.entities = transformChannelsEntities(outboundState.channels.entities) + + outboundState.channelsStatus.entities = transformChannelStatusEntities( + outboundState.channelsStatus.entities + ) + return { - ...outboundState, + ...transformedOutboundState, currentChannelId: generalChannelId, channels: outboundState.channels, channelsStatus: outboundState.channelsStatus, @@ -22,3 +33,77 @@ export const PublicChannelsTransform = createTransform( }, { whitelist: [StoreKeys.PublicChannels] } ) + +const getGeneralChannelId = (state: PublicChannelsState) => { + const selectors = publicChannelsAdapter.getSelectors() + const publicChannelStorage = selectors.selectAll(state.channels) + const generalChannel = publicChannelStorage.find(channel => channel.name === 'general') + const generalChannelId = generalChannel?.id || 'general' + + return generalChannelId +} + +const transformChannelsEntities = (channelsEntities: Dictionary) => { + const messagesRefactor = (messages: EntityState) => { + const transformedMessagesEntities = messages.entities + for (const [key, _message] of Object.entries(transformedMessagesEntities)) { + const message = { ..._message } as any + if (message.channelAddress) { + const transformedMessage = { + ...message, + channelId: message.channelAddress + } + delete transformedMessage.channelAddress + + transformedMessagesEntities[key] = transformedMessage + } + } + + return transformedMessagesEntities + } + + for (const [key, _channel] of Object.entries(channelsEntities)) { + const channel = { ..._channel } as any + if (channel.address) { + const messages = messagesRefactor(channel.messages) + const transformedChannel = { + ...channel, + messages, + id: channel.address + } + delete transformedChannel.address + + channelsEntities[key] = transformedChannel + } + } + return channelsEntities +} + +const transformChannelStatusEntities = ( + channelsStatusEntities: Dictionary +) => { + const transformedChannelsStatusEntities = { ...channelsStatusEntities } + for (const [key, _channel] of Object.entries(transformedChannelsStatusEntities)) { + const channel = { ..._channel } as any + if (channel.address) { + let transformedNewestMessage = { ...channel.newestMessage } + if (transformedNewestMessage.channelAddress) { + transformedNewestMessage = { + channelId: channel.address, + ...transformedNewestMessage + } + delete transformedNewestMessage.channelAddress + } + const transformedChannel = { + ...channel, + id: channel.address, + newestMessage: transformedNewestMessage + } + delete transformedChannel.address + + transformedChannelsStatusEntities[key] = transformedChannel + } + } + + return transformedChannelsStatusEntities +} From cb4e5a7b2125679255b8eb052ed7ca2a2ffa6c86 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 23 May 2023 12:23:25 +0200 Subject: [PATCH 29/35] messages state transform --- .../src/sagas/messages/messages.transform.ts | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/packages/state-manager/src/sagas/messages/messages.transform.ts b/packages/state-manager/src/sagas/messages/messages.transform.ts index 48fdc40733..9160685729 100644 --- a/packages/state-manager/src/sagas/messages/messages.transform.ts +++ b/packages/state-manager/src/sagas/messages/messages.transform.ts @@ -1,3 +1,5 @@ +import { PublicChannelsMessagesBase, ChannelMessage } from '@quiet/types' +import { Dictionary, EntityState } from '@reduxjs/toolkit' import { createTransform } from 'redux-persist' import { StoreKeys } from '../store.keys' import { messageSendingStatusAdapter } from './messages.adapter.ts' @@ -8,11 +10,54 @@ export const MessagesTransform = createTransform( return { ...inboundState } }, (outboundState: MessagesState, _key: any) => { + outboundState.publicChannelsMessagesBase.entities = transformPublicChannelsMessagesBaseEntities( + outboundState.publicChannelsMessagesBase.entities + ) + return { ...outboundState, publicKeyMapping: {}, - messageSendingStatus: messageSendingStatusAdapter.getInitialState(), + publicChannelsMessagesBase: outboundState.publicChannelsMessagesBase, + messageSendingStatus: messageSendingStatusAdapter.getInitialState() } }, { whitelist: [StoreKeys.Messages] } ) + +const transformPublicChannelsMessagesBaseEntities = ( + messagesBaseEntities: Dictionary +) => { + const messagesRefactor = (messages: EntityState) => { + const transformedMessagesEntities = messages.entities + for (const [key, _message] of Object.entries(transformedMessagesEntities)) { + const message = { ..._message } as any + if (message.channelAddress) { + const transformedMessage = { + ...message, + channelId: message.channelAddress + } + delete transformedMessage.channelAddress + + transformedMessagesEntities[key] = transformedMessage + } + } + + return transformedMessagesEntities + } + + for (const [key, _message] of Object.entries(messagesBaseEntities)) { + const message = { ..._message } as any + if (message.channelAddress) { + const messages = messagesRefactor(message.messages) + const transformedMessage = { + ...message, + messages, + channelId: message.channelAddress + } + delete transformedMessage.channelAddress + + messagesBaseEntities[key] = transformedMessage + } + } + return messagesBaseEntities +} From 6fc117fda624ecba68773f6e68248bb81054b9f6 Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 23 May 2023 12:46:13 +0200 Subject: [PATCH 30/35] fix messages adapter problem --- packages/state-manager/src/sagas/messages/messages.transform.ts | 2 +- .../src/sagas/publicChannels/publicChannels.transform.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/state-manager/src/sagas/messages/messages.transform.ts b/packages/state-manager/src/sagas/messages/messages.transform.ts index 9160685729..2f2dcab043 100644 --- a/packages/state-manager/src/sagas/messages/messages.transform.ts +++ b/packages/state-manager/src/sagas/messages/messages.transform.ts @@ -48,7 +48,7 @@ const transformPublicChannelsMessagesBaseEntities = ( for (const [key, _message] of Object.entries(messagesBaseEntities)) { const message = { ..._message } as any if (message.channelAddress) { - const messages = messagesRefactor(message.messages) + const messages = { ...message.messages, entities: messagesRefactor(message.messages) } const transformedMessage = { ...message, messages, diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts index f46b26158c..36bea5c84f 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.transform.ts @@ -65,7 +65,7 @@ const transformChannelsEntities = (channelsEntities: Dictionary Date: Tue, 23 May 2023 13:46:09 +0200 Subject: [PATCH 31/35] fix channel.main.test.tsx --- .../src/rtl-tests/channel.main.test.tsx | 30 +++++++--------- .../resetChannelCache.saga.test.ts | 35 ++++++++++--------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/packages/desktop/src/rtl-tests/channel.main.test.tsx b/packages/desktop/src/rtl-tests/channel.main.test.tsx index ed2b145ae6..cd93ada81b 100644 --- a/packages/desktop/src/rtl-tests/channel.main.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.main.test.tsx @@ -139,7 +139,7 @@ describe('Channel', () => { expect(messageInput).toBeVisible() }) - it.only('filters out suspicious messages', async () => { + it('filters out suspicious messages', async () => { const { store, runSaga } = await prepareStore( {}, socket // Fork state manager's sagas @@ -155,8 +155,6 @@ describe('Channel', () => { const generalId = Object.keys(entities).find(key => entities[key].name === 'general') - console.log({ generalId }) - await act(async () => { store.dispatch(publicChannels.actions.setCurrentChannel({ channelId: generalId })) }) @@ -178,7 +176,7 @@ describe('Channel', () => { message: { id: Math.random().toString(36).substr(2.9), type: MessageType.Basic, - message: 'message', + message: 'authenticMessage', createdAt: DateTime.utc().valueOf(), channelId: generalId, signature: '', @@ -191,20 +189,18 @@ describe('Channel', () => { const spoofedMessage: ChannelMessage = { ...( await factory.build('Message', { - identity: alice - // message: { - // id: Math.random().toString(36).substr(2.9), - // type: MessageType.Basic, - // message: 'message', - // createdAt: DateTime.utc().valueOf(), - // channelId: generalId, - // signature: '', - // pubKey: johnPublicKey - // } + identity: alice, + message: { + id: Math.random().toString(36).substr(2.9), + type: MessageType.Basic, + message: 'spoofedMessage', + createdAt: DateTime.utc().valueOf(), + channelId: generalId, + signature: '', + pubKey: johnPublicKey + } }) - ).payload.message, - id: Math.random().toString(36).substr(2.9), - pubKey: johnPublicKey + ).payload.message } window.HTMLElement.prototype.scrollTo = jest.fn() diff --git a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts index 65d5abb528..2d4d157508 100644 --- a/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/manageCache/resetChannelCache.saga.test.ts @@ -24,7 +24,7 @@ describe('resetChannelCacheSaga', () => { let community: Community let alice: Identity - let generalChannel: PublicChannel + let generalChannel: PublicChannel beforeAll(async () => { setupCrypto() @@ -34,7 +34,7 @@ describe('resetChannelCacheSaga', () => { factory = await getFactory(store) community = await factory.create< - ReturnType['payload'] + ReturnType['payload'] >('Community') alice = await factory.create['payload']>( @@ -61,20 +61,23 @@ describe('resetChannelCacheSaga', () => { const iterations = 80 ;[...Array(iterations)].map(async (_, index) => { const item = ( - await factory.create['payload']>('Message', { - identity: alice, - message: { - id: Math.random().toString(36).substr(2.9), - type: MessageType.Basic, - message: 'message', - createdAt: - DateTime.utc().valueOf() + DateTime.utc().minus({ minutes: index }).valueOf(), - channelId: generalChannel.id, - signature: '', - pubKey: '' - }, - verifyAutomatically: true - }) + await factory.create['payload']>( + 'Message', + { + identity: alice, + message: { + id: Math.random().toString(36).substr(2.9), + type: MessageType.Basic, + message: 'message', + createdAt: + DateTime.utc().valueOf() + DateTime.utc().minus({ minutes: index }).valueOf(), + channelId: generalChannel.id, + signature: '', + pubKey: '' + }, + verifyAutomatically: true + } + ) ).message messages.push(item) if (messages.length === iterations) { From b6233cb53defc58f8a4eacf444dd7b69e2f71426 Mon Sep 17 00:00:00 2001 From: Vin Kabuki Date: Tue, 23 May 2023 14:53:49 +0200 Subject: [PATCH 32/35] fix rtl test snapshot --- packages/desktop/src/rtl-tests/community.join.test.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/desktop/src/rtl-tests/community.join.test.tsx b/packages/desktop/src/rtl-tests/community.join.test.tsx index 3ae050d375..1ad412ac7c 100644 --- a/packages/desktop/src/rtl-tests/community.join.test.tsx +++ b/packages/desktop/src/rtl-tests/community.join.test.tsx @@ -173,7 +173,7 @@ describe('User', () => { await userEvent.click(createUsernameButton) // Wait for the actions that updates the store - await act(async () => {}) + await act(async () => { }) // Check if join/username modals are gone expect(joinCommunityTitle).not.toBeVisible() @@ -210,6 +210,9 @@ describe('User', () => { "PublicChannels/addChannel", "Messages/addPublicChannelsMessagesBase", "Modals/closeModal", + "Messages/lazyLoading", + "Messages/resetCurrentPublicChannelCache", + "Messages/resetCurrentPublicChannelCache" ] `) }) @@ -299,7 +302,7 @@ describe('User', () => { await userEvent.click(createUsernameButton) // Wait for the actions that updates the store - await act(async () => {}) + await act(async () => { }) // Check if 'username taken' error message is visible expect(createUsernameTitle).toBeVisible() @@ -415,7 +418,7 @@ describe('User', () => { await userEvent.click(createUsernameButton) // Wait for the actions that updates the store - await act(async () => {}) + await act(async () => { }) // Check if 'username taken' error message disappeared expect(await screen.queryByText(ErrorMessages.USERNAME_TAKEN)).toBeNull() From 8cc19fbfbbfafaa83ac2d0204bfbad580c2bf63a Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Tue, 23 May 2023 16:26:27 +0200 Subject: [PATCH 33/35] general deletion saga fix --- .../desktop/src/renderer/components/Channel/Channel.tsx | 2 +- .../channelDeletionResponse.saga.test.ts | 4 ++++ .../channelDeletionResponse.saga.ts | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/desktop/src/renderer/components/Channel/Channel.tsx b/packages/desktop/src/renderer/components/Channel/Channel.tsx index 678a348107..a51e5df894 100644 --- a/packages/desktop/src/renderer/components/Channel/Channel.tsx +++ b/packages/desktop/src/renderer/components/Channel/Channel.tsx @@ -61,7 +61,7 @@ const Channel = () => { const pendingGeneralChannelRecreation = pendingGeneralChannelRecreationSelector && - currentChannelName === 'general' && + (currentChannelName === 'general' || currentChannelName === '') && currentChannelMessagesCount === 0 let enableContextMenu: boolean = false diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts index f60b7ba7ab..b1cf4b9f93 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts @@ -144,6 +144,10 @@ describe('channelDeletionResponseSaga', () => { .put(publicChannelsActions.clearMessagesCache({ channelId })) .put(messagesActions.deleteChannelEntry({ channelId })) .put(publicChannelsActions.deleteChannelFromStore({ channelId })) + .provide({ + call: (effect, next) => {} + }) + // here should be also put setCurrentChannel to new general channel .run() }) }) diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts index a8f5101492..552ad25b03 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.ts @@ -41,5 +41,12 @@ export function* channelDeletionResponseSaga( } else { yield* put(messagesActions.sendDeletionMessage({ channelId })) } + } else { + if (isGeneral) { + yield* delay(3000) + const generalChannel = yield* select(publicChannelsSelectors.generalChannel) + if (!generalChannel) return + yield* put(publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id })) + } } } From 52c2f5814b53aa56ec839e8aad5d42104783f8fa Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 24 May 2023 11:51:47 +0200 Subject: [PATCH 34/35] fix mobile deletion, lint, rtl test snapshot --- .../backend/src/libp2p/connectionsManager.ts | 2 +- packages/backend/src/storage/storage.ts | 3 +-- .../src/rtl-tests/community.join.test.tsx | 19 ++++++++++--------- packages/mobile/e2e/starter.test.js | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/backend/src/libp2p/connectionsManager.ts b/packages/backend/src/libp2p/connectionsManager.ts index 8263088f07..e3c590c18c 100644 --- a/packages/backend/src/libp2p/connectionsManager.ts +++ b/packages/backend/src/libp2p/connectionsManager.ts @@ -622,7 +622,7 @@ export class ConnectionsManager extends EventEmitter { this.dataServer.on(SocketActionTypes.DELETE_FILES_FROM_CHANNEL, async (payload: DeleteFilesFromChannelSocketPayload) => { log('DELETE_FILES_FROM_CHANNEL : payload', payload) await this.deleteFilesFromChannel(payload) - await this.deleteFilesFromTemporaryDir() + // await this.deleteFilesFromTemporaryDir() //crashes on mobile, will be fixes in next versions }) } diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index 004f8ebb85..5d0e43f663 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -269,7 +269,6 @@ export class Storage extends EventEmitter { }) this.channels.events.on('replicated', async () => { - log('REPLICATED: Channels') this.emit(SocketActionTypes.CONNECTION_PROCESS_INFO, ConnectionProcessInfo.CHANNELS_REPLICATED) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' @@ -280,7 +279,7 @@ export class Storage extends EventEmitter { }) const keyValueChannels: { - [key: string]: PublicChannel, + [key: string]: PublicChannel } = {} channels.forEach(channel => { diff --git a/packages/desktop/src/rtl-tests/community.join.test.tsx b/packages/desktop/src/rtl-tests/community.join.test.tsx index 1ad412ac7c..07aa088cca 100644 --- a/packages/desktop/src/rtl-tests/community.join.test.tsx +++ b/packages/desktop/src/rtl-tests/community.join.test.tsx @@ -91,11 +91,12 @@ describe('User', () => { const payload = data[0] const user = identity.selectors.currentIdentity(store.getState()) // This community serves only as a mocked object for generating valid crytpo data (certificate, rootCA) - const communityHelper: ReturnType['payload'] = ( - await factory.build('Community', { - id: data[0] - }) - ).payload + const communityHelper: ReturnType['payload'] = + ( + await factory.build('Community', { + id: data[0] + }) + ).payload const certificateHelper = await createUserCertificateTestHelper( { nickname: user.nickname, @@ -173,7 +174,7 @@ describe('User', () => { await userEvent.click(createUsernameButton) // Wait for the actions that updates the store - await act(async () => { }) + await act(async () => {}) // Check if join/username modals are gone expect(joinCommunityTitle).not.toBeVisible() @@ -212,7 +213,7 @@ describe('User', () => { "Modals/closeModal", "Messages/lazyLoading", "Messages/resetCurrentPublicChannelCache", - "Messages/resetCurrentPublicChannelCache" + "Messages/resetCurrentPublicChannelCache", ] `) }) @@ -302,7 +303,7 @@ describe('User', () => { await userEvent.click(createUsernameButton) // Wait for the actions that updates the store - await act(async () => { }) + await act(async () => {}) // Check if 'username taken' error message is visible expect(createUsernameTitle).toBeVisible() @@ -418,7 +419,7 @@ describe('User', () => { await userEvent.click(createUsernameButton) // Wait for the actions that updates the store - await act(async () => { }) + await act(async () => {}) // Check if 'username taken' error message disappeared expect(await screen.queryByText(ErrorMessages.USERNAME_TAKEN)).toBeNull() diff --git a/packages/mobile/e2e/starter.test.js b/packages/mobile/e2e/starter.test.js index 0f4baf688a..25544c03a3 100644 --- a/packages/mobile/e2e/starter.test.js +++ b/packages/mobile/e2e/starter.test.js @@ -72,7 +72,7 @@ describe('User', () => { test('sees channels list', async () => { await waitFor(element(by.id('channels_list'))) .toBeVisible() - .withTimeout(5000) + .withTimeout(10000) }) test('enters #general channel', async () => { From dd0dd16580f2ebc441088e70ff43f3ff5cc5562d Mon Sep 17 00:00:00 2001 From: Kacper Michalik Date: Wed, 24 May 2023 17:49:41 +0200 Subject: [PATCH 35/35] CR fixes --- packages/backend/src/storage/storage.test.ts | 32 ++++------------- packages/backend/src/storage/storage.ts | 8 +---- .../sagas/notifications/notifications.saga.ts | 1 - .../src/rtl-tests/channel.main.test.tsx | 13 ++----- .../src/rtl-tests/channel.switch.test.tsx | 15 ++------ .../src/integrationTests/appActions.ts | 2 +- packages/mobile/package.json | 1 + .../menus/ChannelContextMenu.container.tsx | 3 +- packages/mobile/src/route.params.ts | 3 +- .../ChannelList/ChannelList.screen.tsx | 14 ++------ .../CreateChannel/CreateChannel.screen.tsx | 5 +-- .../DeleteChannel/DeleteChannel.screen.tsx | 5 ++- packages/state-manager/src/index.ts | 2 +- .../autoDownloadFiles.saga.test.ts | 24 ++----------- .../checkForMessages.saga.test.ts | 15 ++------ .../channelDeletionResponse.saga.test.ts | 25 ++++++++++---- .../channelsReplicated.saga.test.ts | 22 ++---------- .../channelsReplicated.saga.ts | 1 - .../deleteChannel/deleteChannel.saga.test.ts | 14 ++------ .../deleteChannel/deleteChannel.saga.ts | 5 ++- .../publicChannels.selectors.ts | 34 +++++++++++++++++-- .../src/utils/tests/factories.ts | 19 ++++++++++- packages/types/src/channel.ts | 9 +++++ 23 files changed, 118 insertions(+), 154 deletions(-) diff --git a/packages/backend/src/storage/storage.test.ts b/packages/backend/src/storage/storage.test.ts index 556d1d63ea..7c2ebdd7ef 100644 --- a/packages/backend/src/storage/storage.test.ts +++ b/packages/backend/src/storage/storage.test.ts @@ -14,9 +14,8 @@ import { jest, beforeEach, describe, it, expect, afterEach, beforeAll } from '@j import { sleep } from '../sleep' import { StorageEvents } from './types' import type { Storage as StorageType } from './storage' -import { ChannelMessage, Community, Identity, MessageType, PublicChannel, TestMessage } from '@quiet/types' -import { Store, getFactory, prepareStore, publicChannels } from '@quiet/state-manager' -import { DateTime } from 'luxon' +import { ChannelMessage, Community, Identity, PublicChannel, TestMessage } from '@quiet/types' +import { Store, getFactory, prepareStore, publicChannels, generateMessageFactoryContentWithId } from '@quiet/state-manager' const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) @@ -58,23 +57,6 @@ let utils: ComonUtilsModuleType jest.setTimeout(50000) -const generateMessageFactoryContent = () => { - const obj = { - message: { - id: (Math.random() * 10 ** 18).toString(36), - type: MessageType.Basic, - message: (Math.random() * 10 ** 18).toString(36), - createdAt: DateTime.utc().valueOf(), - channelId: channel.id, - signature: '', - pubKey: '' - }, - verifyAutomatically: false - } - - return obj -} - beforeAll(async () => { store = prepareStore().store factory = await getFactory(store) @@ -106,7 +88,7 @@ beforeAll(async () => { 'Message', { identity: alice, - ...generateMessageFactoryContent() + message: generateMessageFactoryContentWithId(channel.id) } ) ).message @@ -332,7 +314,7 @@ describe('Certificate', () => { ReturnType['payload'] >('Message', { identity: alice, - ...generateMessageFactoryContent() + message: generateMessageFactoryContentWithId(channel.id) }) storage = new Storage(tmpAppDataPath, community.id, { createPaths: false }) @@ -380,14 +362,14 @@ describe('Certificate', () => { ReturnType['payload'] >('Message', { identity: alice, - ...generateMessageFactoryContent() + message: generateMessageFactoryContentWithId(channel.id) }) const johnMessage = await factory.create< ReturnType['payload'] >('Message', { identity: john, - ...generateMessageFactoryContent() + message: generateMessageFactoryContentWithId(channel.id) }) @@ -493,7 +475,7 @@ describe('Message access controller', () => { ReturnType['payload'] >('Message', { identity: alice, - ...generateMessageFactoryContent() + message: generateMessageFactoryContentWithId(channel.id) }) // @ts-expect-error userCertificate can be undefined const johnCertificate: string = john.userCertificate diff --git a/packages/backend/src/storage/storage.ts b/packages/backend/src/storage/storage.ts index 9576ceec30..afe40ac4c3 100644 --- a/packages/backend/src/storage/storage.ts +++ b/packages/backend/src/storage/storage.ts @@ -249,12 +249,6 @@ export class Storage extends EventEmitter { }) } - private async migrateChannelsDb() { - // if owner migrateChannelsDb - // do it only once - // if new channel db has general return and do nothing - } - private async createDbForChannels() { log('createDbForChannels init') this.channels = await this.orbitdb.keyvalue('public-channels', { @@ -556,7 +550,7 @@ export class Storage extends EventEmitter { log(`Set ${channelId} to local channels`) // @ts-expect-error - OrbitDB's type declaration of `load` lacks 'options' await db.load({ fetchEntryTimeout: 2000, }) - log(`Created channel ${data.id}`) + log(`Created channel ${channelId}`) return db } diff --git a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts index 8f843a9e9b..cf960a43f4 100644 --- a/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts +++ b/packages/desktop/src/renderer/sagas/notifications/notifications.saga.ts @@ -156,7 +156,6 @@ function subscribeNotificationEvents( const [browserWindow] = remote.BrowserWindow.getAllWindows() browserWindow.show() // Emit store action - // KACPER emit(publicChannels.actions.setCurrentChannel({ channelId: channel })) } } diff --git a/packages/desktop/src/rtl-tests/channel.main.test.tsx b/packages/desktop/src/rtl-tests/channel.main.test.tsx index cd93ada81b..b49ea8d83a 100644 --- a/packages/desktop/src/rtl-tests/channel.main.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.main.test.tsx @@ -33,7 +33,8 @@ import { SendMessagePayload, MessageVerificationStatus, network, - connection + connection, + generateMessageFactoryContentWithId } from '@quiet/state-manager' import { keyFromCertificate, parseCertificate } from '@quiet/identity' @@ -359,15 +360,7 @@ describe('Channel', () => { 'Message', { identity: alice, - message: { - id: Math.random().toString(36).substr(2.9), - type: MessageType.Basic, - message: 'message', - createdAt: DateTime.utc().valueOf(), - channelId: generalId, - signature: '', - pubKey: '' - }, + message: generateMessageFactoryContentWithId(generalId), verifyAutomatically: true } ) diff --git a/packages/desktop/src/rtl-tests/channel.switch.test.tsx b/packages/desktop/src/rtl-tests/channel.switch.test.tsx index 96d1fd646f..4169c3c180 100644 --- a/packages/desktop/src/rtl-tests/channel.switch.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.switch.test.tsx @@ -24,7 +24,8 @@ import { SocketActionTypes, MessageType, ChannelMessage, - messages + messages, + generateMessageFactoryContentWithId } from '@quiet/state-manager' import { FactoryGirl } from 'factory-girl' @@ -110,17 +111,7 @@ describe('Switch channels', () => { ReturnType['payload'] >('Message', { identity: alice, - - message: { - id: (Math.random() * 10 ** 18).toString(36), - type: MessageType.Basic, - message: (Math.random() * 10 ** 18).toString(36), - createdAt: DateTime.utc().valueOf(), - channelId: generalId, - signature: '', - pubKey: '' - }, - + message: generateMessageFactoryContentWithId(generalId), verifyAutomatically: true }) diff --git a/packages/integration-tests/src/integrationTests/appActions.ts b/packages/integration-tests/src/integrationTests/appActions.ts index e4b2442e41..5b5e4638c3 100644 --- a/packages/integration-tests/src/integrationTests/appActions.ts +++ b/packages/integration-tests/src/integrationTests/appActions.ts @@ -247,7 +247,7 @@ export async function sendMessage( log(message, 'sendMessage') const communityId = store.getState().Communities.communities.ids[0] -// KACPER + if (channelName) { store.dispatch( publicChannels.actions.setCurrentChannel({ diff --git a/packages/mobile/package.json b/packages/mobile/package.json index f5d8af38bf..5054ce3a75 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -25,6 +25,7 @@ "@quiet/backend": "^1.2.1-alpha.4", "@quiet/common": "^1.2.1-alpha.3", "@quiet/identity": "^1.2.1-alpha.2", + "@quiet/types": "^1.2.1-alpha.2", "@quiet/state-manager": "^1.2.1-alpha.3", "@react-native-clipboard/clipboard": "^1.11.2", "@react-navigation/native": "^6.0.0", diff --git a/packages/mobile/src/components/ContextMenu/menus/ChannelContextMenu.container.tsx b/packages/mobile/src/components/ContextMenu/menus/ChannelContextMenu.container.tsx index 8bff2a7d2b..d0dbe9df11 100644 --- a/packages/mobile/src/components/ContextMenu/menus/ChannelContextMenu.container.tsx +++ b/packages/mobile/src/components/ContextMenu/menus/ChannelContextMenu.container.tsx @@ -49,7 +49,8 @@ export const ChannelContextMenu: FC = () => { title: 'Delete channel', action: () => redirect(ScreenNames.DeleteChannelScreen, { - channel: channel?.name + channelName: channel?.name, + channelId: channel?.id }) } ] diff --git a/packages/mobile/src/route.params.ts b/packages/mobile/src/route.params.ts index cb9c481e03..d02982f96f 100644 --- a/packages/mobile/src/route.params.ts +++ b/packages/mobile/src/route.params.ts @@ -18,7 +18,8 @@ export type RootStackParamList = { [ScreenNames.ChannelScreen]: undefined [ScreenNames.CreateChannelScreen]: undefined [ScreenNames.DeleteChannelScreen]: { - channel: string + channelName: string + channelId: string } [ScreenNames.SuccessScreen]: { onPress: () => void diff --git a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx index 73cfcfd1f1..60ac10130d 100644 --- a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx +++ b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx @@ -33,20 +33,10 @@ export const ChannelListScreen: FC = () => { ) const community = useSelector(communities.selectors.currentCommunity) - const channelsStatusSortedSelector = useSelector(publicChannels.selectors.channelsStatusSorted) - const publicChannelsSelector = useSelector(publicChannels.selectors.publicChannels) - const channels = channelsStatusSortedSelector.reduce((prev, curr) => { - return [ - ...prev, - { - ...curr, - name: publicChannelsSelector.find(channel => curr.id.includes(channel.name)).name - } - ] - }, []) + const channelsStatusWithName = useSelector(publicChannels.selectors.channelsStatusWithName) - const tiles = channels.map(status => { + const tiles = channelsStatusWithName.map(status => { const newestMessage = status.newestMessage const message = newestMessage?.message || '...' diff --git a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx index 9c2a4c456c..ba20aff213 100644 --- a/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx +++ b/packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx @@ -16,14 +16,11 @@ import { navigationSelectors } from '../../store/navigation/navigation.selectors import { ScreenNames } from '../../const/ScreenNames.enum' import { navigationActions } from '../../store/navigation/navigation.slice' import { generateChannelId } from '@quiet/common' +import { ChannelStructure } from '@quiet/types' export const CreateChannelScreen: FC = () => { const dispatch = useDispatch() - interface ChannelStructure { - channelName: string | null - channelId: string | null - } const [channel, setChannel] = useState({ channelId: null, channelName: null diff --git a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx index a0dd9879e6..36033b785c 100644 --- a/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx +++ b/packages/mobile/src/screens/DeleteChannel/DeleteChannel.screen.tsx @@ -10,7 +10,7 @@ import { navigationSelectors } from '../../store/navigation/navigation.selectors export const DeleteChannelScreen: FC = ({ route }) => { const dispatch = useDispatch() - const { channel: channelName } = route.params + const { channelName, channelId } = route.params const channels = useSelector(publicChannels.selectors.publicChannels) @@ -25,10 +25,9 @@ export const DeleteChannelScreen: FC = ({ route }) => }, [dispatch, screen, channels]) const deleteChannel = useCallback(() => { - const deletedChannel = channels.find((channel) => channel.name === channelName) dispatch( publicChannels.actions.deleteChannel({ - channelId: deletedChannel.id + channelId }) ) }, [dispatch, channels, channelName]) diff --git a/packages/state-manager/src/index.ts b/packages/state-manager/src/index.ts index c3cbb7ad62..08b37cc094 100644 --- a/packages/state-manager/src/index.ts +++ b/packages/state-manager/src/index.ts @@ -63,7 +63,7 @@ export { StoreKeys } from './sagas/store.keys' export { prepareStore } from './utils/tests/prepareStore' export { useIO } from './sagas/socket/startConnection/startConnection.saga' -export { getFactory } from './utils/tests/factories' +export { getFactory, generateMessageFactoryContentWithId } from './utils/tests/factories' export * from './utils/tests/helpers' export { Community } from './sagas/communities/communities.slice' // TODO: remove after setting strict in 'desktop' and 'mobile' packages diff --git a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts index 7aa3e86957..8ee1f37785 100644 --- a/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts +++ b/packages/state-manager/src/sagas/files/autoDownloadFiles/autoDownloadFiles.saga.test.ts @@ -1,6 +1,6 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' -import { getFactory, publicChannels } from '../../..' +import { generateMessageFactoryContentWithId, getFactory, publicChannels } from '../../..' import { prepareStore, reducers } from '../../../utils/tests/prepareStore' import { combineReducers } from '@reduxjs/toolkit' import { expectSaga } from 'redux-saga-test-plan' @@ -203,16 +203,7 @@ describe('downloadFileSaga', () => { 'Message', { identity: alice, - message: { - id: id, - type: MessageType.File, - message: '', - createdAt: DateTime.utc().valueOf(), - channelId: generalChannel.id, - signature: '', - pubKey: '', - media: media - } + message: generateMessageFactoryContentWithId(generalChannel.id), } ) ).message @@ -264,16 +255,7 @@ describe('downloadFileSaga', () => { 'Message', { identity: alice, - message: { - id: id, - type: MessageType.File, - message: '', - createdAt: DateTime.utc().valueOf(), - channelId: generalChannel.id, - signature: '', - pubKey: '', - media: media - } + message: generateMessageFactoryContentWithId(generalChannel.id), } ) ).message diff --git a/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts b/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts index 4c3f79c685..5fd1cdfaaa 100644 --- a/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts +++ b/packages/state-manager/src/sagas/messages/checkForMessages/checkForMessages.saga.test.ts @@ -1,6 +1,6 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' -import { getFactory, publicChannels } from '../../..' +import { generateMessageFactoryContentWithId, getFactory, publicChannels } from '../../..' import { prepareStore, reducers } from '../../../utils/tests/prepareStore' import { messagesActions } from './../messages.slice' import { communitiesActions } from '../../communities/communities.slice' @@ -9,9 +9,8 @@ import { FactoryGirl } from 'factory-girl' import { combineReducers } from 'redux' import { expectSaga } from 'redux-saga-test-plan' import { checkForMessagesSaga } from './checkForMessages.saga' -import { DateTime } from 'luxon' import { selectGeneralChannel } from '../../publicChannels/publicChannels.selectors' -import { Community, Identity, MessageType, PublicChannel } from '@quiet/types' +import { Community, Identity, PublicChannel } from '@quiet/types' describe('checkForMessagesSaga', () => { let store: Store @@ -55,15 +54,7 @@ describe('checkForMessagesSaga', () => { 'Message', { identity: alice, - message: { - id: Math.random().toString(36).substr(2.9), - type: MessageType.Basic, - message: 'message', - createdAt: DateTime.utc().valueOf(), - channelId: generalChannel.id, - signature: '', - pubKey: '' - }, + message: generateMessageFactoryContentWithId(generalChannel.id), verifyAutomatically: true } ) diff --git a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts index b1cf4b9f93..8a2dffc4fb 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelDeletionResponse/channelDeletionResponse.saga.test.ts @@ -15,6 +15,9 @@ import { channelDeletionResponseSaga } from './channelDeletionResponse.saga' import { generateChannelId } from '@quiet/common' import { Community, Identity, PublicChannel } from '@quiet/types' import { publicChannelsSelectors } from '../publicChannels.selectors' +import { select } from 'redux-saga-test-plan/matchers' + +const provideDelay = ({ fn }: any, next: () => any) => (fn.name === 'delayP' ? null : next()) describe('channelDeletionResponseSaga', () => { let store: Store @@ -97,9 +100,7 @@ describe('channelDeletionResponseSaga', () => { .put(publicChannelsActions.clearMessagesCache({ channelId })) .put(messagesActions.deleteChannelEntry({ channelId })) .put(publicChannelsActions.deleteChannelFromStore({ channelId })) - .provide({ - call: (effect, next) => {} - }) + .provide([{ call: provideDelay }]) .put(publicChannelsActions.createGeneralChannel()) .run() @@ -144,10 +145,20 @@ describe('channelDeletionResponseSaga', () => { .put(publicChannelsActions.clearMessagesCache({ channelId })) .put(messagesActions.deleteChannelEntry({ channelId })) .put(publicChannelsActions.deleteChannelFromStore({ channelId })) - .provide({ - call: (effect, next) => {} - }) - // here should be also put setCurrentChannel to new general channel + .provide([ + { call: provideDelay }, + [ + select(publicChannelsSelectors.generalChannel), + { + name: 'general', + description: 'general_description', + owner: 'general_owner', + timestamp: 'general_timestamp', + id: channelId + } + ] + ]) + .put(publicChannelsActions.setCurrentChannel({ channelId: channelId })) .run() }) }) diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts index 61a3c9a943..6e10c56625 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.test.ts @@ -1,7 +1,7 @@ import { setupCrypto } from '@quiet/identity' import { Store } from '../../store.types' import { prepareStore } from '../../../utils/tests/prepareStore' -import { getFactory, messages, publicChannels } from '../../..' +import { generateMessageFactoryContentWithId, getFactory, messages, publicChannels } from '../../..' import { FactoryGirl } from 'factory-girl' import { combineReducers } from 'redux' import { reducers } from '../../reducers' @@ -188,15 +188,7 @@ describe('channelsReplicatedSaga', () => { ReturnType['payload'] >('Message', { identity: alice, - message: { - id: (Math.random() * 10 ** 18).toString(36), - type: MessageType.Basic, - message: (Math.random() * 10 ** 18).toString(36), - createdAt: DateTime.utc().valueOf(), - channelId: generalChannel.id, - signature: '', - pubKey: '' - } + message: generateMessageFactoryContentWithId(generalChannel.id) }) store.dispatch( @@ -227,15 +219,7 @@ describe('channelsReplicatedSaga', () => { ReturnType['payload'] >('Message', { identity: alice, - message: { - id: (Math.random() * 10 ** 18).toString(36), - type: MessageType.Basic, - message: (Math.random() * 10 ** 18).toString(36), - createdAt: DateTime.utc().valueOf(), - channelId: generalChannel.id, - signature: '', - pubKey: '' - } + message: generateMessageFactoryContentWithId(generalChannel.id) }) const reducer = combineReducers(reducers) diff --git a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts index 0016ac787f..3de1845c55 100644 --- a/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/channelsReplicated/channelsReplicated.saga.ts @@ -24,7 +24,6 @@ export function* channelsReplicatedSaga( const databaseStoredChannelsIds = databaseStoredChannels.map(channel => channel.id) console.log({ locallyStoredChannels, databaseStoredChannelsIds }) // Upserting channels to local storage - // KACPER!!! for (const channel of databaseStoredChannels) { if (!locallyStoredChannels.includes(channel.id)) { log(`ADDING #${channel.name} TO LOCAL STORAGE`) diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts index 5dd0e79ad1..b869ea92f1 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.test.ts @@ -67,13 +67,9 @@ describe('deleteChannelSaga', () => { test('delete standard channel', async () => { console.log({ generalChannel }) const channelId = photoChannel.id - + store.dispatch(publicChannelsActions.setCurrentChannel({ channelId })) const reducer = combineReducers(reducers) - await expectSaga( - deleteChannelSaga, - socket, - publicChannelsActions.deleteChannel({ channelId }) - ) + await expectSaga(deleteChannelSaga, socket, publicChannelsActions.deleteChannel({ channelId })) .withReducer(reducer) .withState(store.getState()) .apply(socket, socket.emit, [ @@ -91,11 +87,7 @@ describe('deleteChannelSaga', () => { const channelId = generalChannel.id const reducer = combineReducers(reducers) - await expectSaga( - deleteChannelSaga, - socket, - publicChannelsActions.deleteChannel({ channelId }) - ) + await expectSaga(deleteChannelSaga, socket, publicChannelsActions.deleteChannel({ channelId })) .withReducer(reducer) .withState(store.getState()) .apply(socket, socket.emit, [ diff --git a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts index 719b2a1675..1d3c6503b6 100644 --- a/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts +++ b/packages/state-manager/src/sagas/publicChannels/deleteChannel/deleteChannel.saga.ts @@ -15,6 +15,7 @@ export function* deleteChannelSaga( ): Generator { const channelId = action.payload.channelId const generalChannel = yield* select(publicChannelsSelectors.generalChannel) + const currentChannelId = yield* select(publicChannelsSelectors.currentChannelId) if (generalChannel === undefined) { return } @@ -33,7 +34,9 @@ export function* deleteChannelSaga( yield* put(filesActions.deleteFilesFromChannel({ channelId })) if (!isGeneral) { - yield* put(publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id })) + if (currentChannelId === channelId) { + yield* put(publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id })) + } yield* put(publicChannelsActions.disableChannel({ channelId })) } } diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts index 5ea935c4a1..72b966f7bd 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.ts @@ -19,7 +19,9 @@ import { MessagesGroupsType, PublicChannel, PublicChannelStatus, - INITIAL_CURRENT_CHANNEL_ID + INITIAL_CURRENT_CHANNEL_ID, + PublicChannelStatusWithName, + PublicChannelStorage } from '@quiet/types' const selectState: CreatedSelectors[StoreKeys.PublicChannels] = (state: StoreState) => @@ -96,7 +98,6 @@ export const generalChannel = createSelector(publicChannels, publicChannelsSelec }) export const currentChannelId = createSelector(selectState, generalChannel, (state, general) => { - // KACPER - test for it - IMPORTANT !!!! if (!state) { return undefined } @@ -283,6 +284,32 @@ export const unreadChannels = createSelector(channelsStatus, status => { }, []) }) +export const channelsStatusWithName = createSelector( + publicChannels, + channelsStatusSorted, + (publicChannelsSelector, channelsStatusSelector) => { + const channels = channelsStatusSelector.reduce( + (prev: PublicChannelStatusWithName[], curr: PublicChannelStatus) => { + const channel: PublicChannelStorage | undefined = publicChannelsSelector.find(channel => + curr.id.includes(channel.name) + ) + if (!channel?.name) return [] + const name = channel.name + return [ + ...prev, + { + ...curr, + name + } + ] + }, + [] + ) + + return channels + } +) + export const publicChannelsSelectors = { publicChannels, subscribedChannels, @@ -302,5 +329,6 @@ export const publicChannelsSelectors = { dynamicSearchedChannels, sortedChannels, pendingGeneralChannelRecreation, - generalChannel + generalChannel, + channelsStatusWithName } diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index b88bb98d7b..208293542c 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -16,7 +16,24 @@ import { keyObjectFromString, verifySignature } from '@quiet/identity' -import { MessageType, SendingStatus } from '@quiet/types' +import { ChannelMessage, FileMetadata, MessageType, SendingStatus } from '@quiet/types' + +export const generateMessageFactoryContentWithId = ( + channelId: string, + type?: MessageType, + media?: FileMetadata +): ChannelMessage => { + return { + id: (Math.random() * 10 ** 18).toString(36), + type: type || MessageType.Basic, + message: (Math.random() * 10 ** 18).toString(36), + createdAt: DateTime.utc().valueOf(), + channelId: channelId, + signature: '', + pubKey: '', + media: media || undefined + } +} export const getFactory = async (store: Store) => { // @ts-ignore diff --git a/packages/types/src/channel.ts b/packages/types/src/channel.ts index 9777e1a521..ab77a2b004 100644 --- a/packages/types/src/channel.ts +++ b/packages/types/src/channel.ts @@ -22,6 +22,10 @@ export interface PublicChannelStatus { newestMessage: ChannelMessage | null } +export interface PublicChannelStatusWithName extends PublicChannelStatus { + name: string +} + export interface PublicChannelSubscription { id: string subscribed: boolean @@ -131,6 +135,11 @@ export interface DisableChannelPayload { channelId: string } +export interface ChannelStructure { + channelName: string | null + channelId: string | null +} + export function instanceOfChannelMessage(object: any): object is ChannelMessage { return 'channelId' in object }