2020-04-13 13:56:30 +00:00
|
|
|
import RocketChat from '../lib/rocketchat';
|
2021-02-25 16:41:44 +00:00
|
|
|
import reduxStore from '../lib/createStore';
|
2020-04-13 13:56:30 +00:00
|
|
|
|
2021-02-25 16:41:44 +00:00
|
|
|
const canPostReadOnly = async({ rid }) => {
|
|
|
|
// 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 RocketChat.hasPermission([postReadOnlyPermission], rid);
|
|
|
|
return permission[0];
|
2020-04-13 13:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const isMuted = (room, user) => room && room.muted && room.muted.find && !!room.muted.find(m => m === user.username);
|
|
|
|
|
|
|
|
export const isReadOnly = async(room, user) => {
|
|
|
|
if (room.archived) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-26 20:22:56 +00:00
|
|
|
if (isMuted(room, user)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (room?.ro) {
|
2021-02-25 16:41:44 +00:00
|
|
|
const allowPost = await canPostReadOnly(room);
|
2020-06-26 20:22:56 +00:00
|
|
|
if (allowPost) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2020-04-13 13:56:30 +00:00
|
|
|
}
|
2020-06-26 20:22:56 +00:00
|
|
|
return false;
|
2020-04-13 13:56:30 +00:00
|
|
|
};
|