From 8445bafad61ffc5751187e505c257543a694b15c Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 13 Apr 2020 10:56:30 -0300 Subject: [PATCH] [FIX] Lint (#2030) --- app/utils/isReadOnly.js | 24 ++++++++++++++++++++++++ app/utils/room.js | 24 ------------------------ app/views/RoomView/index.js | 3 ++- app/views/ShareView/index.js | 3 ++- 4 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 app/utils/isReadOnly.js diff --git a/app/utils/isReadOnly.js b/app/utils/isReadOnly.js new file mode 100644 index 000000000..8a6f9c36f --- /dev/null +++ b/app/utils/isReadOnly.js @@ -0,0 +1,24 @@ +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; + } + const allowPost = await canPost(room); + if (allowPost) { + return false; + } + return (room && room.ro) || isMuted(room, user); +}; diff --git a/app/utils/room.js b/app/utils/room.js index 6a58c1e8f..4775fa757 100644 --- a/app/utils/room.js +++ b/app/utils/room.js @@ -1,30 +1,6 @@ import moment from 'moment'; import I18n from '../i18n'; -import RocketChat from '../lib/rocketchat'; - -export const canPost = async({ rid }) => { - try { - const permission = await RocketChat.hasPermission(['post-readonly'], rid); - return permission && permission['post-readonly']; - } catch { - // do nothing - } - return false; -}; - -export 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; - } - const allowPost = await canPost(room); - if (allowPost) { - return false; - } - return (room && room.ro) || isMuted(room, user); -}; export const isBlocked = (room) => { if (room) { diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 001f33277..341df6ce6 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -34,7 +34,8 @@ import { themes } from '../../constants/colors'; import debounce from '../../utils/debounce'; import ReactionsModal from '../../containers/ReactionsModal'; import { LISTENER } from '../../containers/Toast'; -import { isReadOnly, isBlocked } from '../../utils/room'; +import { isBlocked } from '../../utils/room'; +import { isReadOnly } from '../../utils/isReadOnly'; import { isIOS, isTablet } from '../../utils/deviceInfo'; import { showErrorAlert } from '../../utils/info'; import { withTheme } from '../../theme'; diff --git a/app/views/ShareView/index.js b/app/views/ShareView/index.js index 1582b3524..84889d272 100644 --- a/app/views/ShareView/index.js +++ b/app/views/ShareView/index.js @@ -13,7 +13,8 @@ import styles from './styles'; import TextInput from '../../containers/TextInput'; import ActivityIndicator from '../../containers/ActivityIndicator'; import { CustomHeaderButtons, Item } from '../../containers/HeaderButton'; -import { isReadOnly, isBlocked } from '../../utils/room'; +import { isBlocked } from '../../utils/room'; +import { isReadOnly } from '../../utils/isReadOnly'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation';