Skip to content

Commit

Permalink
fix: Enable channel context menu for all users (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
leblowl committed Jan 16, 2024
1 parent 968a5f2 commit 02f6809
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[2.1.0] - unreleased

* fix: Enable channel context menu for all users

* Fix channel creation message impersonation bug by removing username from channel creation message

* Reduce file download concurrency as a quick fix for large file downloads
Expand Down
7 changes: 0 additions & 7 deletions packages/desktop/src/renderer/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ const Channel = () => {
(currentChannelName === 'general' || currentChannelName === '') &&
currentChannelMessagesCount === 0

let enableContextMenu = false
if (community) {
// Enable only for community owner
enableContextMenu = Boolean(community.CA)
}

const pendingMessages = useSelector(messages.selectors.messagesSendingStatus)

const uploadedFileModal = useModal<{ src: string }>(ModalName.uploadedFileModal)
Expand Down Expand Up @@ -220,7 +214,6 @@ const Channel = () => {
handleClipboardFiles: handleClipboardFiles,
uploadedFileModal: uploadedFileModal,
openContextMenu: openContextMenu,
enableContextMenu: enableContextMenu,
pendingGeneralChannelRecreation: pendingGeneralChannelRecreation,
unregisteredUsernameModalHandleOpen,
duplicatedUsernameModalHandleOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const ChannelComponent: React.FC<ChannelComponentProps & UploadFilesPrevi
downloadFile,
cancelDownload,
openContextMenu,
enableContextMenu = false,
enableContextMenu = true,
pendingGeneralChannelRecreation,
unregisteredUsernameModalHandleOpen,
duplicatedUsernameModalHandleOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,21 @@ export const ChannelContextMenu: FC = () => {

const deleteChannelModal = useModal(ModalName.deleteChannel)

let items: ContextMenuItemProps[] = []
const items: ContextMenuItemProps[] = [
{
title: 'Export messages',
action: () => channel && exportChats(channel?.name, channelMessages),
},
]

if (community?.CA) {
items = [
...items,
{
title: 'Delete',
action: () => {
channelContextMenu.handleClose() // Dismiss context menu before displaying modal
deleteChannelModal.handleOpen()
},
items.unshift({
title: 'Delete',
action: () => {
channelContextMenu.handleClose() // Dismiss context menu before displaying modal
deleteChannelModal.handleOpen()
},
{
title: 'Export messages',
action: () => channel && exportChats(channel?.name, channelMessages),
},
]
})
}

// @ts-expect-error
Expand Down
34 changes: 19 additions & 15 deletions packages/desktop/src/rtl-tests/channel.menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,38 @@ describe('Channel menu', () => {

const factory = await getFactory(store)

await factory.create<ReturnType<typeof communities.actions.addNewCommunity>['payload']>('Community', {
id: '0',
name: 'community',
CA: null,
registrarUrl: 'http://ugmx77q2tnm5fliyfxfeen5hsuzjtbsz44tsldui2ju7vl5xj4d447yd.onion',
rootCa: '',
peerList: [],
})
const community = await factory.create<ReturnType<typeof communities.actions.addNewCommunity>['payload']>(
'Community',
{
id: '0',
name: 'community',
CA: null,
registrarUrl: 'http://ugmx77q2tnm5fliyfxfeen5hsuzjtbsz44tsldui2ju7vl5xj4d447yd.onion',
rootCa: '',
peerList: [],
}
)

/* Context menu is not visible to non-owners at all, for now */
store.dispatch(navigationActions.openMenu({ menu: MenuName.Channel }))
await factory.create<ReturnType<typeof identity.actions.addNewIdentity>['payload']>('Identity', {
id: community.id,
nickname: 'alice',
})

window.HTMLElement.prototype.scrollTo = jest.fn()

renderComponent(
<>
<Channel />
<ChannelContextMenu />
<DeleteChannel />
</>,
store
)

/* Context menu is not visible to non-owners at all, for now */

// const menu = screen.getByTestId('channelContextMenuButton')
// expect(menu).toBeVisible()
const menu = screen.getByTestId('channelContextMenuButton')
expect(menu).toBeVisible()

// await userEvent.click(menu)
await userEvent.click(menu)

const channelContextMenu = screen.getByTestId('contextMenu')
expect(channelContextMenu).toBeVisible()
Expand Down

0 comments on commit 02f6809

Please sign in to comment.