Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Enable channel context menu for all users #2206

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
leblowl marked this conversation as resolved.
Show resolved Hide resolved

* 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
leblowl marked this conversation as resolved.
Show resolved Hide resolved
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
Loading