diff --git a/app/presentation/RoomItem/Touchable.js b/app/presentation/RoomItem/Touchable.js index 2bfb1aa01..a78ca4fa1 100644 --- a/app/presentation/RoomItem/Touchable.js +++ b/app/presentation/RoomItem/Touchable.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import { Animated } from 'react-native'; import { PanGestureHandler, State } from 'react-native-gesture-handler'; +import Touch from '../../utils/touch'; import { ACTION_WIDTH, SMALL_SWIPE, @@ -10,7 +11,6 @@ import { } from './styles'; import { isRTL } from '../../i18n'; import { LeftActions, RightActions } from './Actions'; -import Touch from '../../utils/touch'; class Touchable extends React.Component { static propTypes = { diff --git a/app/sagas/createChannel.js b/app/sagas/createChannel.js index e02f59ad8..72ffa2e57 100644 --- a/app/sagas/createChannel.js +++ b/app/sagas/createChannel.js @@ -44,8 +44,7 @@ const handleRequest = function* handleRequest({ data }) { broadcast, encrypted } = data; - // TODO: Create event CT_CREATE - logEvent(events.CR_CREATE, { + logEvent(events.CT_CREATE, { type, readOnly, broadcast, @@ -74,7 +73,7 @@ const handleRequest = function* handleRequest({ data }) { sub = yield call(createChannel, data); if (data.teamId) { - // TODO: Log when adding room to team + logEvent(events.CT_ADD_ROOM_TO_TEAM); const channels = yield call(addTeamRoom, { rooms: sub.rid, teamId: data.teamId }); if (channels.success) { sub.teamId = channels.rooms[0].teamId; diff --git a/app/utils/log/events.js b/app/utils/log/events.js index 490f0dfd3..b978d4d0a 100644 --- a/app/utils/log/events.js +++ b/app/utils/log/events.js @@ -101,12 +101,16 @@ export default { // CREATE CHANNEL VIEW CR_CREATE: 'cr_create', + CT_CREATE: 'ct_create', CR_CREATE_F: 'cr_create_f', + CT_CREATE_F: 'ct_create_f', CR_TOGGLE_TYPE: 'cr_toggle_type', CR_TOGGLE_READ_ONLY: 'cr_toggle_read_only', CR_TOGGLE_BROADCAST: 'cr_toggle_broadcast', CR_TOGGLE_ENCRYPTED: 'cr_toggle_encrypted', CR_REMOVE_USER: 'cr_remove_user', + CT_ADD_ROOM_TO_TEAM: 'ct_add_room_to_team', + CT_ADD_ROOM_TO_TEAM_F: 'ct_add_room_to_team_f', // CREATE DISCUSSION VIEW CD_CREATE: 'cd_create', diff --git a/app/views/AddExistingChannelView.js b/app/views/AddExistingChannelView.js index 62d2263ec..6f6087fd9 100644 --- a/app/views/AddExistingChannelView.js +++ b/app/views/AddExistingChannelView.js @@ -14,7 +14,7 @@ import database from '../lib/database'; import RocketChat from '../lib/rocketchat'; import sharedStyles from './Styles'; import I18n from '../i18n'; -import log from '../utils/log'; +import log, { events, logEvent } from '../utils/log'; import SearchBox from '../containers/SearchBox'; import { CustomIcon } from '../lib/Icons'; import * as HeaderButton from '../containers/HeaderButton'; @@ -63,7 +63,8 @@ class AddExistingChannelView extends React.Component { token: PropTypes.string }), theme: PropTypes.string, - isMasterDetail: PropTypes.bool + isMasterDetail: PropTypes.bool, + addTeamChannelPermission: PropTypes.array }; constructor(props) { @@ -107,17 +108,24 @@ class AddExistingChannelView extends React.Component { // eslint-disable-next-line react/sort-comp init = async() => { try { + const { addTeamChannelPermission } = this.props; const db = database.active; const channels = await db.collections .get('subscriptions') .query( - Q.where('t', 'p'), - Q.where('team_id', ''), + Q.and(Q.where('team_id', ''), Q.or(Q.where('t', 'c'), Q.where('t', 'p'))), Q.experimentalTake(QUERY_SIZE), Q.experimentalSortBy('room_updated_at', Q.desc) ) .fetch(); - this.setState({ channels }); + const filteredChannels = channels.filter(async(channel) => { + const permissions = await RocketChat.hasPermission([addTeamChannelPermission], channel.rid); + if (!permissions[0]) { + return; + } + return channel; + }); + this.setState({ channels: filteredChannels }); } catch (e) { log(e); } @@ -145,14 +153,14 @@ class AddExistingChannelView extends React.Component { this.setState({ loading: true }); try { - // TODO: Log request + logEvent(events.CT_ADD_ROOM_TO_TEAM); const result = await RocketChat.addTeamRooms({ rooms: selected, teamId: this.teamId }); if (result.success) { this.setState({ loading: false }); goRoom({ item: result, isMasterDetail }); } } catch (e) { - // TODO: Log error + logEvent(events.CT_ADD_ROOM_TO_TEAM_F); this.setState({ loading: false }); } } @@ -250,7 +258,8 @@ class AddExistingChannelView extends React.Component { } const mapStateToProps = state => ({ - isMasterDetail: state.app.isMasterDetail + isMasterDetail: state.app.isMasterDetail, + addTeamChannelPermission: state.permissions['add-team-channel'] }); export default connect(mapStateToProps, null)(withTheme(AddExistingChannelView));