verdnatura-chat/app/utils/isReadOnly.js

31 lines
654 B
JavaScript
Raw Permalink Normal View History

2020-04-13 13:56:30 +00:00
import RocketChat from '../lib/rocketchat';
const canPost = async({ rid }) => {
try {
const permission = await RocketChat.hasPermission(['post-readonly'], rid);
return permission && permission['post-readonly'];
} catch {
// do nothing
}
return false;
};
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;
}
if (isMuted(room, user)) {
return true;
}
if (room?.ro) {
const allowPost = await canPost(room);
if (allowPost) {
return false;
}
return true;
2020-04-13 13:56:30 +00:00
}
return false;
2020-04-13 13:56:30 +00:00
};