Skip to content

Commit

Permalink
Merge from 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed Apr 5, 2024
2 parents af7844b + bc34b16 commit 6e88e98
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Fixes

* Allow JPEG and GIF files as profile photos ([#2332](https://github.com/TryQuiet/quiet/issues/2332))
* Fixes issues with recreating general channel when deleted while offline ([#2334](https://github.com/TryQuiet/quiet/issues/2334))

# New Features

Expand Down
14 changes: 7 additions & 7 deletions packages/backend/src/nest/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,15 +620,15 @@ export class StorageService extends EventEmitter {
}
}
await repo.db.load()
const allEntries = this.getAllEventLogRawEntries(repo.db)
// const allEntries = this.getAllEventLogRawEntries(repo.db)
await repo.db.close()
await repo.db.drop()
const hashes = allEntries.map(e => CID.parse(e.hash))
const files = allEntries
.map(e => {
return e.payload.value.media
})
.filter(isDefined)
// const hashes = allEntries.map(e => CID.parse(e.hash))
// const files = allEntries
// .map(e => {
// return e.payload.value.media
// })
// .filter(isDefined)
// await this.deleteChannelFiles(files)
// await this.deleteChannelMessages(hashes)
this.publicChannelsRepos.delete(channelId)
Expand Down
97 changes: 73 additions & 24 deletions packages/e2e-tests/src/tests/multipleClients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('Multiple Clients', () => {
let secondChannelOwner: Channel
let secondChannelUser1: Channel

let thirdChannelOwner: Channel

let channelContextMenuOwner: ChannelContextMenu

let invitationCode: string
Expand All @@ -40,6 +42,7 @@ describe('Multiple Clients', () => {
const displayedCommunityName = 'Testcommunity'
const newChannelName = 'mid-night-club'
const generalChannelName = 'general'
const thirdChannelName = 'delete-this'

beforeAll(async () => {
const commonApp = new App()
Expand Down Expand Up @@ -439,34 +442,80 @@ describe('Multiple Clients', () => {
const channels = await sidebarOwner.getChannelList()
expect(channels.length).toEqual(2)
})
})

describe('Channel Deletion - Issue #2334', () => {
it('Owner creates third channel', async () => {
await sidebarOwner.addNewChannel(thirdChannelName)
await sidebarOwner.switchChannel(thirdChannelName)
thirdChannelOwner = new Channel(users.owner.app.driver, thirdChannelName)
const messages = await thirdChannelOwner.getUserMessages(users.owner.username)
expect(messages.length).toEqual(1)
await sleep(2000)
const channels = await sidebarUser1.getChannelList()
expect(channels.length).toEqual(3)
})

// End of tests for Windows
if (process.platform !== 'win32') {
it('Leave community', async () => {
console.log('TEST 2')
const settingsModal = await new Sidebar(users.user1.app.driver).openSettings()
const isSettingsModal = await settingsModal.element.isDisplayed()
expect(isSettingsModal).toBeTruthy()
await settingsModal.openLeaveCommunityModal()
await settingsModal.leaveCommunityButton()
})

// Delete general channel while guest is absent
it('Owner recreates general channel', async () => {
console.log('TEST 3')
await sleep(10000)
const isGeneralChannel = await generalChannelOwner.messageInput.isDisplayed()
expect(isGeneralChannel).toBeTruthy()
await channelContextMenuOwner.openMenu()
await channelContextMenuOwner.openDeletionChannelModal()
await channelContextMenuOwner.deleteChannel()
const channels = await sidebarOwner.getChannelList()
expect(channels.length).toEqual(2)
})
}
it('User 1 closes app', async () => {
console.log('User 1 closes app')
await users.user1.app?.close()
await sleep(30000)
})

// Delete third channel while guest is absent
it('Owner deletes third channel', async () => {
await sleep(10000)
const isThirdChannel = await thirdChannelOwner.messageInput.isDisplayed()
expect(isThirdChannel).toBeTruthy()
await channelContextMenuOwner.openMenu()
await channelContextMenuOwner.openDeletionChannelModal()
await channelContextMenuOwner.deleteChannel()
const channels = await sidebarOwner.getChannelList()
expect(channels.length).toEqual(2)
})

// Delete general channel while guest is absent
it('Owner recreates general channel', async () => {
console.log('TEST 3')
await sleep(10000)
const isGeneralChannel = await generalChannelOwner.messageInput.isDisplayed()
expect(isGeneralChannel).toBeTruthy()
await channelContextMenuOwner.openMenu()
await channelContextMenuOwner.openDeletionChannelModal()
await channelContextMenuOwner.deleteChannel()
const channels = await sidebarOwner.getChannelList()
expect(channels.length).toEqual(2)
})

it('User 1 re-opens app', async () => {
console.log('User 1 re-opens app')
await users.user1.app?.openWithRetries()
await sleep(30000)
})

// Check correct channels replication
it('User 1 sees information about recreation general channel and see correct amount of messages (#2334)', async () => {
generalChannelUser1 = new Channel(users.user1.app.driver, 'general')
await generalChannelUser1.element.isDisplayed()
await sleep(10000)

await generalChannelUser1.waitForUserMessage(
users.owner.username,
`@${users.owner.username} deleted all messages in #general`
)
})
})

describe('Leave Community', () => {
it('User 1 leaves community', async () => {
console.log('TEST 2')
const settingsModal = await new Sidebar(users.user1.app.driver).openSettings()
const isSettingsModal = await settingsModal.element.isDisplayed()
expect(isSettingsModal).toBeTruthy()
await settingsModal.openLeaveCommunityModal()
await settingsModal.leaveCommunityButton()
})

it('Guest re-join to community successfully', async () => {
console.log('TEST 4')
const debugModal = new DebugModeModal(users.user1.app.driver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function* channelDeletionResponseSaga(
let newGeneralChannel: PublicChannelStorage | undefined = yield* select(publicChannelsSelectors.generalChannel)
while (!newGeneralChannel) {
logger.info('General channel has not been replicated yet')
yield* delay(500)
yield* delay(1000)
newGeneralChannel = yield* select(publicChannelsSelectors.generalChannel)
}
yield* put(publicChannelsActions.setCurrentChannel({ channelId: newGeneralChannel.id }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const logger = createLogger('channels')
export function* channelsReplicatedSaga(
action: PayloadAction<ReturnType<typeof publicChannelsActions.channelsReplicated>['payload']>
): Generator {
logger.debug('Syncing channels')
logger.debug('Syncing channels', action.payload)
const { channels } = action.payload
const _locallyStoredChannels = yield* select(publicChannelsSelectors.publicChannels)
const locallyStoredChannels = _locallyStoredChannels.map(channel => channel.id)
Expand All @@ -24,17 +24,6 @@ export function* channelsReplicatedSaga(
const databaseStoredChannelsIds = databaseStoredChannels.map(channel => channel.id)
logger.debug({ locallyStoredChannels, databaseStoredChannelsIds })

// Removing channels from store
if (databaseStoredChannelsIds.length > 0) {
for (const channelId of locallyStoredChannels) {
if (!databaseStoredChannelsIds.includes(channelId)) {
logger.info(`Removing #${channelId} from store`)
yield* put(publicChannelsActions.deleteChannel({ channelId }))
yield* take(publicChannelsActions.completeChannelDeletion)
}
}
}

// Upserting channels to local storage
for (const channel of databaseStoredChannels) {
if (!locallyStoredChannels.includes(channel.id)) {
Expand All @@ -52,6 +41,17 @@ export function* channelsReplicatedSaga(
}
}

// Removing channels from store
if (databaseStoredChannelsIds.length > 0) {
for (const channelId of locallyStoredChannels) {
if (!databaseStoredChannelsIds.includes(channelId)) {
logger.info(`Removing #${channelId} from store`)
yield* put(publicChannelsActions.deleteChannel({ channelId }))
yield* take(publicChannelsActions.completeChannelDeletion)
}
}
}

const currentChannelCache = yield* select(publicChannelsSelectors.currentChannelMessages)
const currentChannelRepository = yield* select(messagesSelectors.currentPublicChannelMessagesEntries)

Expand Down

0 comments on commit 6e88e98

Please sign in to comment.