Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions app/lib/methods/helpers/isReadOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@ import { store as reduxStore } from '../../store/auxStore';
import { type ISubscription } from '../../../definitions';
import { hasPermission } from './helpers';

const canPostReadOnly = async (room: Partial<ISubscription>, username: string) => {
const canPostReadOnly = async (room: Partial<ISubscription>, username: string, postReadOnlyPermission?: string[]) => {
// RC 6.4.0
const isUnmuted = !!room?.unmuted?.find(m => m === username);
// TODO: this is not reactive. If this permission changes, the component won't be updated
const postReadOnlyPermission = reduxStore.getState().permissions['post-readonly'];
const permission = await hasPermission([postReadOnlyPermission], room.rid);
// Use provided permission or fallback to static snapshot for backward compatibility
const permissionToCheck = postReadOnlyPermission ?? reduxStore.getState().permissions['post-readonly'];
const permission = await hasPermission([permissionToCheck], room.rid);
return permission[0] || isUnmuted;
};

const isMuted = (room: Partial<ISubscription>, username: string) =>
room && room.muted && room.muted.find && !!room.muted.find(m => m === username);

export const isReadOnly = async (room: Partial<ISubscription>, username: string): Promise<boolean> => {
export const isReadOnly = async (
room: Partial<ISubscription>,
username: string,
postReadOnlyPermission?: string[]
): Promise<boolean> => {
if (room.archived) {
return true;
}
if (isMuted(room, username)) {
return true;
}
if (room?.ro) {
const allowPost = await canPostReadOnly(room, username);
const allowPost = await canPostReadOnly(room, username, postReadOnlyPermission);
if (allowPost) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions app/views/RoomView/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface IRoomViewProps extends IActionSheetProvider, IBaseScreen<ChatsS
insets: EdgeInsets;
transferLivechatGuestPermission?: string[]; // TODO: Check if its the correct type
viewCannedResponsesPermission?: string[]; // TODO: Check if its the correct type
postReadOnlyPermission?: string[];
livechatAllowManualOnHold?: boolean;
inAppFeedback?: { [key: string]: string };
encryptionEnabled: boolean;
Expand Down
12 changes: 9 additions & 3 deletions app/views/RoomView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
shouldComponentUpdate(nextProps: IRoomViewProps, nextState: IRoomViewState) {
const { state } = this;
const { roomUpdate, member, isOnHold, isAutocompleteVisible } = state;
const { theme, insets, route, encryptionEnabled, airGappedRestrictionRemainingDays } = this.props;
const { theme, insets, route, encryptionEnabled, airGappedRestrictionRemainingDays, postReadOnlyPermission } = this.props;
if (theme !== nextProps.theme) {
return true;
}
Expand All @@ -258,6 +258,9 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
if (airGappedRestrictionRemainingDays !== nextProps.airGappedRestrictionRemainingDays) {
return true;
}
if (!dequal(postReadOnlyPermission, nextProps.postReadOnlyPermission)) {
return true;
}
if (member.statusText !== nextState.member.statusText) {
return true;
}
Expand Down Expand Up @@ -310,6 +313,8 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
if (insets.left !== prevProps.insets.left || insets.right !== prevProps.insets.right) {
this.setHeader();
}
// Update readOnly when permission changes or room updates
// Always call setReadOnly to ensure it's up to date (it will only update state if value changed)
this.setReadOnly();
}

Expand Down Expand Up @@ -568,8 +573,8 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {

setReadOnly = async () => {
const { room } = this.state;
const { user } = this.props;
const readOnly = await isReadOnly(room as ISubscription, user.username as string);
const { user, postReadOnlyPermission } = this.props;
const readOnly = await isReadOnly(room as ISubscription, user.username as string, postReadOnlyPermission);
this.setState({ readOnly });
};

Expand Down Expand Up @@ -1576,6 +1581,7 @@ const mapStateToProps = (state: IApplicationState) => ({
Hide_System_Messages: state.settings.Hide_System_Messages as string[],
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest'],
viewCannedResponsesPermission: state.permissions['view-canned-responses'],
postReadOnlyPermission: state.permissions['post-readonly'],
livechatAllowManualOnHold: state.settings.Livechat_allow_manual_on_hold as boolean,
airGappedRestrictionRemainingDays: state.settings.Cloud_Workspace_AirGapped_Restrictions_Remaining_Days,
inAppFeedback: state.inAppFeedback,
Expand Down