-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Users without preview permission subscribing to public channel s…
…tream (#34922) Co-authored-by: gabriellsh <[email protected]>
- Loading branch information
1 parent
baaee3f
commit 3c237b2
Showing
10 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
"@rocket.chat/i18n": minor | ||
--- | ||
|
||
Fixes an issue where users without the "Preview public channel" permission would receive new messages sent to the channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { IRoom } from '@rocket.chat/core-typings'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { sdk } from '../../app/utils/client/lib/SDKClient'; | ||
|
||
type UseJoinRoomMutationFunctionProps = { | ||
rid: IRoom['_id']; | ||
reference: string; | ||
type: IRoom['t']; | ||
}; | ||
|
||
export const useJoinRoom = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: async ({ rid, reference, type }: UseJoinRoomMutationFunctionProps) => { | ||
await sdk.call('joinRoom', rid); | ||
|
||
return { reference, type }; | ||
}, | ||
onSuccess: (data) => { | ||
queryClient.invalidateQueries({ | ||
queryKey: ['rooms', data], | ||
}); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { IRoom } from '@rocket.chat/core-typings'; | ||
|
||
import { RocketChatError } from './RocketChatError'; | ||
|
||
type NotSubscribedToRoomErrorDetails = { rid: IRoom['_id'] }; | ||
|
||
export class NotSubscribedToRoomError extends RocketChatError<'not-subscribed-room', NotSubscribedToRoomErrorDetails> { | ||
public declare readonly reason: string; | ||
|
||
public declare readonly details: NotSubscribedToRoomErrorDetails; | ||
|
||
constructor(message = 'Not subscribed to this room', details: NotSubscribedToRoomErrorDetails) { | ||
super('not-subscribed-room', message, details); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { IRoom } from '@rocket.chat/core-typings'; | ||
import { Box, States, StatesAction, StatesActions, StatesIcon, StatesSubtitle, StatesTitle } from '@rocket.chat/fuselage'; | ||
import { Header, HeaderToolbar } from '@rocket.chat/ui-client'; | ||
import { useLayout } from '@rocket.chat/ui-contexts'; | ||
import type { ReactElement } from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
|
||
import RoomLayout from './layout/RoomLayout'; | ||
import SidebarToggler from '../../components/SidebarToggler'; | ||
import { useJoinRoom } from '../../hooks/useJoinRoom'; | ||
|
||
type NotSubscribedRoomProps = { | ||
rid: IRoom['_id']; | ||
reference: string; | ||
type: IRoom['t']; | ||
}; | ||
|
||
const NotSubscribedRoom = ({ rid, reference, type }: NotSubscribedRoomProps): ReactElement => { | ||
const { t } = useTranslation(); | ||
|
||
const handleJoinClick = useJoinRoom(); | ||
// TODO: Handle onJoinClick error | ||
|
||
const { isMobile } = useLayout(); | ||
|
||
return ( | ||
<RoomLayout | ||
header={ | ||
isMobile && ( | ||
<Header justifyContent='start'> | ||
<HeaderToolbar> | ||
<SidebarToggler /> | ||
</HeaderToolbar> | ||
</Header> | ||
) | ||
} | ||
body={ | ||
<Box display='flex' justifyContent='center' height='full'> | ||
<States> | ||
<StatesIcon name='add-user' /> | ||
<StatesTitle>{t('Channel_not_joined')}</StatesTitle> | ||
<StatesSubtitle> | ||
<Box display='block'> | ||
<Trans | ||
i18nKey='Join_channel_to_view_history' | ||
values={{ channel: reference }} | ||
components={{ b: <Box is='span' fontWeight={600} /> }} | ||
/> | ||
</Box> | ||
</StatesSubtitle> | ||
<Box mbs={16}> | ||
<StatesActions> | ||
<StatesAction disabled={handleJoinClick.isPending} onClick={() => handleJoinClick.mutate({ rid, reference, type })}> | ||
{t('Join_channel')} | ||
</StatesAction> | ||
</StatesActions> | ||
</Box> | ||
</States> | ||
</Box> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default NotSubscribedRoom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters