Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Convert/Move Channel to Team #3164

Merged
merged 110 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
2f5f247
Added Create Team
gerzonc Apr 19, 2021
c8a88c9
Merge branch 'develop' into new.create-team
gerzonc Apr 19, 2021
585a9ae
Merge branch 'develop' into new.create-team
gerzonc Apr 19, 2021
8b82bd4
Added actionTypes, actions, ENG strings for Teams and updated NewMess…
gerzonc Apr 20, 2021
c8b8680
Added createTeam sagas, createTeam reducer, new Team string and updat…
gerzonc Apr 20, 2021
a245af6
Remove unnecessary actionTypes, reducers and sagas, e2e tests and nav…
gerzonc Apr 23, 2021
16fd575
Minor tweaks
gerzonc Apr 26, 2021
1ff7711
Show TeamChannelsView only if joined the team
gerzonc Apr 26, 2021
69214be
Minor tweak
gerzonc Apr 26, 2021
0cf173d
Added AddChannelTeamView
gerzonc Apr 26, 2021
27ced96
Merge branch 'develop' into new.create-team
gerzonc Apr 28, 2021
37421d3
Merge branch 'develop' into new.add-remove-channel-teams
gerzonc Apr 29, 2021
bb0632b
Added permissions, translations strings for teams, deleteTeamRoom an…
gerzonc Apr 30, 2021
c3ffa37
Refactor touch component and update removeRoom and deleteRoom methods
gerzonc May 4, 2021
69ae247
Minor tweaks
gerzonc May 5, 2021
4761e21
Minor tweaks for removing channels and addExistingChannelView
gerzonc May 5, 2021
7d2924e
Added missing events and fixed channels list
gerzonc May 5, 2021
4bac054
Minor tweaks for refactored touch component
gerzonc May 5, 2021
4b6e691
Added SelectListView and logic for leaving team
gerzonc May 6, 2021
b961fa0
Added addTeamMember and removeTeamMember
gerzonc May 6, 2021
04ea01b
Minor tweak
gerzonc May 6, 2021
9cf3e68
Merge branch 'new.delete-team' into new.add-remove-users-teams
gerzonc May 6, 2021
a305676
Added deleteTeam function
gerzonc May 7, 2021
7ecc76f
Minor tweak
gerzonc May 7, 2021
7e6a277
Minor tweaks
gerzonc May 11, 2021
cb44fdf
Merge branch 'develop' into new.add-remove-channel-teams
gerzonc May 11, 2021
c890ed3
Merge branch 'new.create-team' into new.add-remove-channel-teams
gerzonc May 11, 2021
feb7862
Merge branch 'new.add-remove-channel-teams' of https://github.com/Roc…
gerzonc May 11, 2021
be3517f
Remove unnecesary changes, update TeamChannelsView, AddExistingChanne…
gerzonc May 11, 2021
850e443
Merge branch 'new.add-remove-channel-teams' into new.delete-team
gerzonc May 11, 2021
d0f9560
Remove unnecesary prop
gerzonc May 11, 2021
b3975a4
Merge branch 'new.delete-team' into new.add-remove-users-teams
gerzonc May 11, 2021
7fb1e50
Merge branch 'develop' into new.add-remove-channel-teams
gerzonc May 13, 2021
2d50417
Add screens to ModalStack, events, autoJoin, update createChannel, ad…
gerzonc May 13, 2021
79b1123
Minor tweak
gerzonc May 13, 2021
70e503a
Update loadMessagesForRoom.js
gerzonc May 13, 2021
66e9041
Merge branch 'develop' into new.delete-team
gerzonc May 13, 2021
9a45b9e
Merge branch 'new.add-remove-channel-teams' into new.delete-team
gerzonc May 13, 2021
f42988a
Updated schema, tag component, touch, AddChannelTeamView, AddExisting…
gerzonc May 14, 2021
9820e6e
Fix unnecessary changes
gerzonc May 14, 2021
682dd21
Add i18n, update createChannel, AddExistingChannelTeamView, AddChanne…
gerzonc May 14, 2021
d3fb789
Updated styles, added tag story
gerzonc May 14, 2021
79334af
Minor tweak
gerzonc May 17, 2021
09d6307
Minor tweaks
gerzonc May 17, 2021
4859014
Auto-join tweak
diegolmello May 17, 2021
2fa4ebe
Minor tweaks
gerzonc May 18, 2021
30caba1
Minor tweak on search
gerzonc May 18, 2021
96d6ef0
Merge branch 'new.add-remove-channel-teams' into new.delete-team
gerzonc May 18, 2021
2939775
Merge branch 'develop' into new.delete-team
gerzonc May 20, 2021
43c31b3
Minor refactor to ListItem, add SelectListView to ModalStack, update …
gerzonc May 21, 2021
38c2637
Minor tweaks
gerzonc May 21, 2021
2ef6c70
Update SelectListView
gerzonc May 21, 2021
28e46b7
Update handleLeaveTeam, remove unnecessary method, add story
gerzonc May 21, 2021
3d4370f
Minor tweak
gerzonc May 21, 2021
94a8764
Merge branch 'new.delete-team' into new.delete-teams
gerzonc May 24, 2021
003a272
Minor visual tweaks
diegolmello May 24, 2021
d1a4a05
Merge branch 'new.delete-team' into new.add-remove-users-teams
gerzonc May 24, 2021
4deffca
Update SelectListView.js
gerzonc May 24, 2021
517d15e
Update index.js
gerzonc May 24, 2021
29122cb
Update RoomMembersView
gerzonc May 24, 2021
3f8a647
Updated SelectListView, RoomActionsView, leaveTeam method and string …
gerzonc May 24, 2021
a70c699
Update SelectListVIew
gerzonc May 24, 2021
5fd6514
Minor tweak
gerzonc May 24, 2021
d5912d3
Update SelectListView
gerzonc May 24, 2021
ec5bdb1
Minor tweak
gerzonc May 24, 2021
501a878
Merge branch 'new.delete-team' into new.add-remove-users-teams
gerzonc May 24, 2021
919ef34
Minor tweaks
gerzonc May 24, 2021
cbea5fb
Fix for List.Item subtitles being pushed down by title's flex
diegolmello May 25, 2021
f0e573a
Minor tweaks
gerzonc May 25, 2021
03eb3d9
Update RoomActionsView
gerzonc May 25, 2021
2006146
Merge branch 'new.delete-team' into new.add-remove-users-teams
gerzonc May 25, 2021
1fc4122
Use showConfirmationAlert and showErrorAlert
diegolmello May 25, 2021
92ef166
Merge branch 'new.delete-team' of github.com:RocketChat/Rocket.Chat.R…
diegolmello May 25, 2021
53b6cf4
Merge branch 'new.delete-team' into new.add-remove-users-teams
gerzonc May 25, 2021
d478c51
Merge branch 'develop' into new.add-remove-users-teams
gerzonc May 25, 2021
f021aee
Remove addTeamMember, update removeTeamMember
gerzonc May 25, 2021
f138e10
Update Alert
gerzonc May 25, 2021
98d5f0e
Minor tweaks
gerzonc May 25, 2021
6399269
Minor tweaks
gerzonc May 25, 2021
3844471
Minor tweak
gerzonc May 25, 2021
6a16add
Update showActionSheet on RoomMembersView
gerzonc May 25, 2021
ec0df16
Merge branch 'new.delete-team' into new.delete-teams
gerzonc May 25, 2021
750e21a
Remove team main from query and move code around
diegolmello May 25, 2021
a08a24d
Fetch roles
gerzonc May 26, 2021
55aa294
Update RoomMembersView and SelectListView
gerzonc May 26, 2021
427831a
Merge branch 'develop' into new.add-remove-users-teams
gerzonc May 26, 2021
01a7222
Merge branch 'new.add-remove-users-teams' into new.delete-teams
gerzonc May 26, 2021
b1bde5e
Update rocketchat.js
gerzonc May 26, 2021
c9266f6
Updated leaveTeam and handleRemoveFromTeam
gerzonc May 26, 2021
0469772
Fix validation
gerzonc May 26, 2021
f1815ce
Remove unnecessary function
gerzonc May 26, 2021
ca6a2f8
Merge branch 'new.add-remove-users-teams' into new.delete-teams
gerzonc May 26, 2021
1765107
Merge branch 'develop' into new.delete-teams
gerzonc May 26, 2021
a70a747
Update RoomActionsView
gerzonc May 26, 2021
9c33263
Update en.json
gerzonc May 26, 2021
72e6162
Merge branch 'develop' into new.delete-teams
gerzonc May 27, 2021
a77906c
updated deleteTeam function and permissions
gerzonc May 27, 2021
139a31b
Added showConfirmationAlert
gerzonc May 27, 2021
cc6b13d
Added string translations for teams
gerzonc May 27, 2021
ad12ea0
Fix permission
gerzonc May 27, 2021
786583a
Added moveChannelToTeam and convertToTeam functionality
gerzonc May 27, 2021
70e62fc
Merge branch 'develop' into new.convert-move-channel-teams
gerzonc May 27, 2021
88ab8ad
Fix SelectListView RadioButton
gerzonc May 27, 2021
587d20e
Fix moveToTeam
gerzonc May 27, 2021
e0e14ef
Added searchBar to SelectListVIew
gerzonc May 27, 2021
0d942a2
Merge branch 'develop' into new.convert-move-channel-teams
gerzonc May 27, 2021
c67b5e8
Merge branch 'develop' into new.convert-move-channel-teams
gerzonc May 28, 2021
a85d69d
Merge branch 'develop' into new.convert-move-channel-teams
gerzonc May 28, 2021
eaced3c
Merge branch 'develop' into new.convert-move-channel-teams
diegolmello May 28, 2021
540a2b2
Update RoomView , SelectListVIew and string translation for error
gerzonc May 31, 2021
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
5 changes: 4 additions & 1 deletion app/containers/RoomHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RoomHeaderContainer extends Component {

shouldComponentUpdate(nextProps) {
const {
type, title, subtitle, status, statusText, connecting, connected, onPress, usersTyping, width, height
type, title, subtitle, status, statusText, connecting, connected, onPress, usersTyping, width, height, teamMain
} = this.props;
if (nextProps.type !== type) {
return true;
Expand Down Expand Up @@ -67,6 +67,9 @@ class RoomHeaderContainer extends Component {
if (nextProps.onPress !== onPress) {
return true;
}
if (nextProps.teamMain !== teamMain) {
return true;
}
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"delete": "delete",
"Delete": "Delete",
"DELETE": "DELETE",
"move": "move",
"deleting_room": "deleting room",
"description": "description",
"Description": "Description",
Expand Down Expand Up @@ -731,6 +732,7 @@
"invalid-room": "Invalid room",
"You_are_leaving_the_team": "You are leaving the team '{{team}}'",
"Leave_Team": "Leave Team",
"Select_Team": "Select Team",
"Select_Team_Channels": "Select the Team's channels you would like to leave.",
"Cannot_leave": "Cannot leave",
"Cannot_remove": "Cannot remove",
Expand All @@ -746,8 +748,16 @@
"Remove_Member": "Remove Member",
"leaving_team": "leaving team",
"removing_team": "removing from team",
"moving_channel_to_team": "moving channel to team",
"deleting_team": "deleting team",
"member-does-not-exist": "Member does not exist",
"Convert": "Convert",
"Convert_to_Team": "Convert to Team",
"Convert_to_Team_Warning": "This can't be undone. Once you convert a channel to a team, you can not turn it back to a channel.",
"Move_to_Team": "Move to Team",
"Move_Channel_to_Team": "Move Channel to Team",
"Move_Channel_Paragraph": "Moving a channel inside a team means that this channel will be added in the team’s context, however, all channel’s members, which are not members of the respective team, will still have access to this channel, but will not be added as team’s members. \n\nAll channel’s management will still be made by the owners of this channel.\n\nTeam’s members and even team’s owners, if not a member of this channel, can not have access to the channel’s content. \n\nPlease notice that the Team’s owner will be able remove members from the Channel.",
"Move_to_Team_Warning": "After reading the previous intructions about this behavior, do you still want to move this channel to the selected team?",
"Load_More": "Load More",
"Load_Newer": "Load Newer",
"Load_Older": "Load Older"
Expand Down
1 change: 1 addition & 0 deletions app/lib/methods/getPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const PERMISSIONS = [
'archive-room',
'auto-translate',
'create-invite-links',
'create-team',
'delete-c',
'delete-message',
'delete-p',
Expand Down
14 changes: 14 additions & 0 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,20 @@ const RocketChat = {
// RC 3.13.0
return this.sdk.get('teams.listRoomsOfUser', { teamId, userId });
},
convertChannelToTeam({ rid, name, type }) {
const params = {
...(type === 'c'
? {
channelId: rid,
channelName: name
}
: {
roomId: rid,
roomName: name
})
};
return this.sdk.post(type === 'c' ? 'channels.convertToTeam' : 'groups.convertToTeam', params);
},
joinRoom(roomId, joinCode, type) {
// TODO: join code
// RC 0.48.0
Expand Down
190 changes: 185 additions & 5 deletions app/views/RoomActionsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
} from 'react-native';
import { connect } from 'react-redux';
import isEmpty from 'lodash/isEmpty';
import { compareServerVersion, methods } from '../../lib/utils';
import { Q } from '@nozbe/watermelondb';

import { compareServerVersion, methods } from '../../lib/utils';
import Touch from '../../utils/touch';
import { setLoading as setLoadingAction } from '../../actions/selectedUsers';
import { leaveRoom as leaveRoomAction, closeRoom as closeRoomAction } from '../../actions/room';
Expand Down Expand Up @@ -61,7 +62,9 @@ class RoomActionsView extends React.Component {
editRoomPermission: PropTypes.array,
toggleRoomE2EEncryptionPermission: PropTypes.array,
viewBroadcastMemberListPermission: PropTypes.array,
transferLivechatGuestPermission: PropTypes.array
transferLivechatGuestPermission: PropTypes.array,
createTeamPermission: PropTypes.array,
addTeamChannelPermission: PropTypes.array
}

constructor(props) {
Expand All @@ -83,7 +86,9 @@ class RoomActionsView extends React.Component {
canForwardGuest: false,
canReturnQueue: false,
canEdit: false,
canToggleEncryption: false
canToggleEncryption: false,
canCreateTeam: false,
canAddChannelToTeam: false
};
if (room && room.observe && room.rid) {
this.roomObservable = room.observe();
Expand Down Expand Up @@ -132,9 +137,11 @@ class RoomActionsView extends React.Component {
const canEdit = await this.canEdit();
const canToggleEncryption = await this.canToggleEncryption();
const canViewMembers = await this.canViewMembers();
const canCreateTeam = await this.canCreateTeam();
const canAddChannelToTeam = await this.canAddChannelToTeam();

this.setState({
canAutoTranslate, canAddUser, canInviteUser, canEdit, canToggleEncryption, canViewMembers
canAutoTranslate, canAddUser, canInviteUser, canEdit, canToggleEncryption, canViewMembers, canCreateTeam, canAddChannelToTeam
});

// livechat permissions
Expand Down Expand Up @@ -210,6 +217,26 @@ class RoomActionsView extends React.Component {
return canEdit;
}

canCreateTeam = async() => {
const { room } = this.state;
const { createTeamPermission } = this.props;
const { rid } = room;
const permissions = await RocketChat.hasPermission([createTeamPermission], rid);

const canCreateTeam = permissions[0];
return canCreateTeam;
}

canAddChannelToTeam = async() => {
const { room } = this.state;
const { addTeamChannelPermission } = this.props;
const { rid } = room;
const permissions = await RocketChat.hasPermission([addTeamChannelPermission], rid);

const canAddChannelToTeam = permissions[0];
return canAddChannelToTeam;
}

canToggleEncryption = async() => {
const { room } = this.state;
const { toggleRoomE2EEncryptionPermission } = this.props;
Expand Down Expand Up @@ -464,6 +491,111 @@ class RoomActionsView extends React.Component {
}
}

handleConvertToTeam = async() => {
try {
const { room } = this.state;
const { navigation } = this.props;
const result = await RocketChat.convertChannelToTeam({ rid: room.rid, name: room.name, type: room.t });

if (result.success) {
navigation.navigate('RoomView');
}
} catch (e) {
log(e);
}
}

convertToTeam = () => {
showConfirmationAlert({
title: I18n.t('Confirmation'),
message: I18n.t('Convert_to_Team_Warning'),
confirmationText: I18n.t('Convert'),
onPress: () => this.handleConvertToTeam()
});
}

handleMoveToTeam = async(selected) => {
try {
const { room } = this.state;
const { navigation } = this.props;
const result = await RocketChat.addRoomsToTeam({ teamId: selected.teamId, rooms: [room.rid] });
if (result.success) {
navigation.navigate('RoomView');
}
} catch (e) {
log(e);
showErrorAlert(I18n.t('There_was_an_error_while_action', { action: I18n.t('moving_channel_to_team') }));
}
}

searchTeam = async(onChangeText) => {
try {
const { addTeamChannelPermission, createTeamPermission } = this.props;
const QUERY_SIZE = 50;
const db = database.active;
const teams = await db.collections
.get('subscriptions')
.query(
Q.where('team_main', Q.notEq(null)),
Q.where('name', Q.like(`%${ onChangeText }%`)),
Q.experimentalTake(QUERY_SIZE),
Q.experimentalSortBy('room_updated_at', Q.desc)
);

const asyncFilter = async(teamArray) => {
const results = await Promise.all(teamArray.map(async(team) => {
const permissions = await RocketChat.hasPermission([addTeamChannelPermission, createTeamPermission], team.rid);
if (!permissions[0]) {
return false;
}
return true;
}));

return teamArray.filter((_v, index) => results[index]);
};
const teamsFiltered = await asyncFilter(teams);
return teamsFiltered;
} catch (e) {
log(e);
}
}

moveToTeam = async() => {
try {
const { navigation } = this.props;
const db = database.active;
const subCollection = db.get('subscriptions');
const teamRooms = await subCollection.query(
Q.where('team_main', Q.notEq(null))
);

if (teamRooms.length) {
navigation.navigate('SelectListView', {
title: 'Move_to_Team',
infoText: 'Move_Channel_Paragraph',
nextAction: () => {
navigation.push('SelectListView', {
title: 'Select_Team',
data: teamRooms,
isRadio: true,
isSearch: true,
onSearch: onChangeText => this.searchTeam(onChangeText),
nextAction: selected => showConfirmationAlert({
title: I18n.t('Confirmation'),
message: I18n.t('Move_to_Team_Warning'),
confirmationText: I18n.t('Yes_action_it', { action: I18n.t('move') }),
onPress: () => this.handleMoveToTeam(selected)
})

});
}
});
}
} catch (e) {
log(e);
}
}

renderRoomInfo = () => {
const { room, member } = this.state;
const {
Expand Down Expand Up @@ -635,6 +767,50 @@ class RoomActionsView extends React.Component {
}
}

teamChannelActions = (t, room) => {
const { canEdit, canCreateTeam, canAddChannelToTeam } = this.state;
const canConvertToTeam = canEdit && canCreateTeam && !room.teamMain;
const canMoveToTeam = canEdit && canAddChannelToTeam && !room.teamId;

return (
<>
{['c', 'p'].includes(t) && canConvertToTeam
? (
<>
<List.Item
title='Convert_to_Team'
onPress={() => this.onPressTouchable({
event: this.convertToTeam
})}
testID='room-actions-convert-to-team'
left={() => <List.Icon name='teams' />}
showActionIndicator
/>
<List.Separator />
</>
)
: null}

{['c', 'p'].includes(t) && canMoveToTeam
? (
<>
<List.Item
title='Move_Channel_to_Team'
onPress={() => this.onPressTouchable({
event: this.moveToTeam
})}
testID='room-actions-convert-to-team'
left={() => <List.Icon name='channel-move-to-team' />}
showActionIndicator
/>
<List.Separator />
</>
)
: null}
</>
);
}

render() {
const {
room, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate, canForwardGuest, canReturnQueue
Expand Down Expand Up @@ -836,6 +1012,8 @@ class RoomActionsView extends React.Component {
)
: null}

{ this.teamChannelActions(t, room) }

{['l'].includes(t) && !this.isOmnichannelPreview
? (
<>
Expand Down Expand Up @@ -922,7 +1100,9 @@ const mapStateToProps = state => ({
editRoomPermission: state.permissions['edit-room'],
toggleRoomE2EEncryptionPermission: state.permissions['toggle-room-e2e-encryption'],
viewBroadcastMemberListPermission: state.permissions['view-broadcast-member-list'],
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest']
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest'],
createTeamPermission: state.permissions['create-team'],
addTeamChannelPermission: state.permissions['add-team-channel']
});

const mapDispatchToProps = dispatch => ({
Expand Down
4 changes: 4 additions & 0 deletions app/views/RoomView/RightButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class RightButtonsContainer extends Component {
const {
isFollowingThread, tunread, tunreadUser, tunreadGroup
} = this.state;
const { teamId } = this.props;
if (nextProps.teamId !== teamId) {
return true;
}
if (nextState.isFollowingThread !== isFollowingThread) {
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions app/views/RoomView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const stateAttrsUpdate = [
'member',
'showingBlockingLoader'
];
const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'tunread', 'muted', 'ignored', 'jitsiTimeout', 'announcement', 'sysMes', 'topic', 'name', 'fname', 'roles', 'bannerClosed', 'visitor', 'joinCodeRequired'];
const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'tunread', 'muted', 'ignored', 'jitsiTimeout', 'announcement', 'sysMes', 'topic', 'name', 'fname', 'roles', 'bannerClosed', 'visitor', 'joinCodeRequired', 'teamMain', 'teamId'];

class RoomView extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -254,7 +254,10 @@ class RoomView extends React.Component {
this.setHeader();
}
}
if (((roomUpdate.fname !== prevState.roomUpdate.fname) || (roomUpdate.name !== prevState.roomUpdate.name)) && !this.tmid) {
if (roomUpdate.teamMain !== prevState.roomUpdate.teamMain) {
this.setHeader();
}
if (((roomUpdate.fname !== prevState.roomUpdate.fname) || (roomUpdate.name !== prevState.roomUpdate.name) || (roomUpdate.teamMain !== prevState.roomUpdate.teamMain)) && !this.tmid) {
this.setHeader();
}
if (insets.left !== prevProps.insets.left || insets.right !== prevProps.insets.right) {
Expand Down
Loading