-
Notifications
You must be signed in to change notification settings - Fork 11k
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: Users without preview permission subscribing to public channel stream #34922
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { IMessage, ISubscription } from '@rocket.chat/core-typings'; | ||
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts'; | ||
import { usePermission, useToastMessageDispatch } from '@rocket.chat/ui-contexts'; | ||
import type { ReactElement, ReactNode } from 'react'; | ||
import { memo, useCallback, useMemo } from 'react'; | ||
|
||
|
@@ -29,6 +29,7 @@ const ComposerMessage = ({ tmid, onSend, ...props }: ComposerMessageProps): Reac | |
const chat = useChat(); | ||
const room = useRoom(); | ||
const dispatchToastMessage = useToastMessageDispatch(); | ||
const hasPreviewPublicRoomPermission = usePermission('preview-c-room'); | ||
|
||
const composerProps = useMemo( | ||
() => ({ | ||
|
@@ -53,7 +54,7 @@ const ComposerMessage = ({ tmid, onSend, ...props }: ComposerMessageProps): Reac | |
isSlashCommandAllowed?: boolean; | ||
}): Promise<void> => { | ||
try { | ||
await chat?.action.stop('typing'); | ||
chat?.action.stop('typing'); | ||
const newMessageSent = await chat?.flows.sendMessage({ | ||
text, | ||
tshow, | ||
|
@@ -85,11 +86,31 @@ const ComposerMessage = ({ tmid, onSend, ...props }: ComposerMessageProps): Reac | |
useCallback(() => LegacyRoomManager.getOpenedRoomByRid(room._id)?.streamActive ?? false, [room._id]), | ||
); | ||
|
||
if (!publicationReady) { | ||
if (!publicationReady && hasPreviewPublicRoomPermission) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if I'm part of the room and I don't have this permission? Won't it break the loading composer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because publicationReady turns into |
||
return <ComposerSkeleton />; | ||
} | ||
|
||
return <MessageBox key={room._id} tmid={tmid} {...composerProps} showFormattingTips={true} {...props} />; | ||
const subscribe = () => { | ||
if (!hasPreviewPublicRoomPermission) { | ||
// Get room subscription | ||
LegacyRoomManager.open({ rid: room._id, typeName: room.t }); | ||
LegacyRoomManager.computation.invalidate(); | ||
} | ||
}; | ||
Comment on lines
+93
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but a lot of other things too. And it does not do the |
||
|
||
return ( | ||
<MessageBox | ||
key={room._id} | ||
tmid={tmid} | ||
{...composerProps} | ||
showFormattingTips={true} | ||
onJoin={async () => { | ||
await composerProps.onJoin(); | ||
subscribe(); | ||
}} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default memo(ComposerMessage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
if (record.streamActive !== true) {
check come first?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because if stream not active we will have exactly what we are trying to avoid, load the stream.
In this case we have another check who comes first, and it's related to preview the public room with no subscriptions...