Chore: evaluate `RoomInfoEditView` (#4095)

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gerzon Z 2022-05-10 17:26:06 -04:00 committed by GitHub
parent c9fd7973f0
commit e233058e22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 25 deletions

View File

@ -59,6 +59,20 @@ export interface IRoom {
waitingResponse?: boolean; waitingResponse?: boolean;
} }
export interface IRoomSettings {
roomName?: string;
roomAvatar?: string;
roomDescription?: string;
roomTopic?: string;
roomAnnouncement?: string;
roomType?: SubscriptionType;
readOnly?: boolean;
reactWhenReadOnly?: boolean;
systemMessages?: string[];
joinCode?: string;
encrypted?: boolean;
}
export enum OmnichannelSourceType { export enum OmnichannelSourceType {
WIDGET = 'widget', WIDGET = 'widget',
EMAIL = 'email', EMAIL = 'email',

View File

@ -1,11 +1,12 @@
import React from 'react';
import { Q } from '@nozbe/watermelondb'; import { Q } from '@nozbe/watermelondb';
import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit'; import { BLOCK_CONTEXT } from '@rocket.chat/ui-kit';
import { dequal } from 'dequal'; import { dequal } from 'dequal';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import React from 'react';
import { Alert, Keyboard, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native'; import { Alert, Keyboard, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native';
import ImagePicker, { Image } from 'react-native-image-crop-picker'; import ImagePicker, { Image } from 'react-native-image-crop-picker';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Subscription } from 'rxjs';
import { deleteRoom } from '../../actions/room'; import { deleteRoom } from '../../actions/room';
import { themes } from '../../lib/constants'; import { themes } from '../../lib/constants';
@ -16,7 +17,15 @@ import StatusBar from '../../containers/StatusBar';
import RCTextInput from '../../containers/TextInput'; import RCTextInput from '../../containers/TextInput';
import { LISTENER } from '../../containers/Toast'; import { LISTENER } from '../../containers/Toast';
import { MultiSelect } from '../../containers/UIKit/MultiSelect'; import { MultiSelect } from '../../containers/UIKit/MultiSelect';
import { IApplicationState, IBaseScreen, ISubscription, SubscriptionType, TSubscriptionModel, IAvatar } from '../../definitions'; import {
IApplicationState,
IBaseScreen,
IRoomSettings,
ISubscription,
SubscriptionType,
TSubscriptionModel,
IAvatar
} from '../../definitions';
import { ERoomType } from '../../definitions/ERoomType'; import { ERoomType } from '../../definitions/ERoomType';
import I18n from '../../i18n'; import I18n from '../../i18n';
import database from '../../lib/database'; import database from '../../lib/database';
@ -25,7 +34,7 @@ import KeyboardView from '../../containers/KeyboardView';
import { TSupportedPermissions } from '../../reducers/permissions'; import { TSupportedPermissions } from '../../reducers/permissions';
import { ModalStackParamList } from '../../stacks/MasterDetailStack/types'; import { ModalStackParamList } from '../../stacks/MasterDetailStack/types';
import { ChatsStackParamList } from '../../stacks/types'; import { ChatsStackParamList } from '../../stacks/types';
import { TSupportedThemes, withTheme } from '../../theme'; import { withTheme } from '../../theme';
import EventEmitter from '../../utils/events'; import EventEmitter from '../../utils/events';
import { showConfirmationAlert, showErrorAlert } from '../../utils/info'; import { showConfirmationAlert, showErrorAlert } from '../../utils/info';
import log, { events, logEvent } from '../../utils/log'; import log, { events, logEvent } from '../../utils/log';
@ -62,7 +71,6 @@ interface IRoomInfoEditViewState {
interface IRoomInfoEditViewProps extends IBaseScreen<ChatsStackParamList | ModalStackParamList, 'RoomInfoEditView'> { interface IRoomInfoEditViewProps extends IBaseScreen<ChatsStackParamList | ModalStackParamList, 'RoomInfoEditView'> {
serverVersion?: string; serverVersion?: string;
encryptionEnabled: boolean; encryptionEnabled: boolean;
theme: TSupportedThemes;
setReadOnlyPermission: string[]; setReadOnlyPermission: string[];
setReactWhenReadOnlyPermission: string[]; setReactWhenReadOnlyPermission: string[];
archiveRoomPermission: string[]; archiveRoomPermission: string[];
@ -70,18 +78,17 @@ interface IRoomInfoEditViewProps extends IBaseScreen<ChatsStackParamList | Modal
deleteCPermission: string[]; deleteCPermission: string[];
deletePPermission: string[]; deletePPermission: string[];
deleteTeamPermission: string[]; deleteTeamPermission: string[];
isMasterDetail: boolean;
} }
class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfoEditViewState> { class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfoEditViewState> {
randomValue = random(15); randomValue = random(15);
private querySubscription: any; // Observable dont have unsubscribe prop private querySubscription: Subscription | undefined;
private room!: TSubscriptionModel; private room: TSubscriptionModel;
private name!: TextInput | null; private name: TextInput | null | undefined;
private description!: TextInput | null; private description: TextInput | null | undefined;
private topic!: TextInput | null; private topic: TextInput | null | undefined;
private announcement!: TextInput | null; private announcement: TextInput | null | undefined;
private joinCode!: TextInput | null; private joinCode: TextInput | null | undefined;
static navigationOptions = () => ({ static navigationOptions = () => ({
title: I18n.t('Room_Info_Edit') title: I18n.t('Room_Info_Edit')
@ -89,6 +96,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
constructor(props: IRoomInfoEditViewProps) { constructor(props: IRoomInfoEditViewProps) {
super(props); super(props);
this.room = {} as TSubscriptionModel;
this.state = { this.state = {
room: {} as ISubscription, room: {} as ISubscription,
avatar: {} as IAvatar, avatar: {} as IAvatar,
@ -117,7 +125,6 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
} }
} }
// eslint-disable-next-line react/sort-comp
loadRoom = async () => { loadRoom = async () => {
const { const {
route, route,
@ -269,7 +276,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
// Clear error objects // Clear error objects
await this.clearErrors(); await this.clearErrors();
const params = {} as any; const params = {} as IRoomSettings;
// Name // Name
if (room.name !== name) { if (room.name !== name) {
@ -277,7 +284,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
} }
// Avatar // Avatar
if (!isEmpty(avatar)) { if (!isEmpty(avatar)) {
params.roomAvatar = avatar.data; params.roomAvatar = avatar.data as string;
} }
// Description // Description
if (room.description !== description) { if (room.description !== description) {
@ -293,7 +300,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
} }
// Room Type // Room Type
if ((room.t === SubscriptionType.GROUP) !== t) { if ((room.t === SubscriptionType.GROUP) !== t) {
params.roomType = t ? 'p' : 'c'; params.roomType = t ? ('p' as SubscriptionType) : ('c' as SubscriptionType);
} }
// Read Only // Read Only
if (room.ro !== ro) { if (room.ro !== ro) {
@ -305,7 +312,7 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
} }
if (!dequal(room.sysMes, systemMessages)) { if (!dequal(room.sysMes, systemMessages)) {
params.systemMessages = systemMessages; params.systemMessages = systemMessages as string[];
} }
// Join Code // Join Code
@ -346,21 +353,16 @@ class RoomInfoEditView extends React.Component<IRoomInfoEditViewProps, IRoomInfo
try { try {
const db = database.active; const db = database.active;
const subCollection = db.get('subscriptions'); const subCollection = db.get('subscriptions');
const teamChannels = await subCollection.query( const teamChannels = await subCollection
Q.where('team_id', room.teamId as string), .query(Q.where('team_id', room.teamId as string), Q.where('team_main', Q.notEq(true)))
Q.where('team_main', Q.notEq(true)) .fetch();
);
const teamChannelOwner = []; const teamChannelOwner = [];
// @ts-ignore - wm schema type error dont including array
for (let i = 0; i < teamChannels.length; i += 1) { for (let i = 0; i < teamChannels.length; i += 1) {
// @ts-ignore - wm schema type error dont including array
const permissionType = teamChannels[i].t === 'c' ? deleteCPermission : deletePPermission; const permissionType = teamChannels[i].t === 'c' ? deleteCPermission : deletePPermission;
// @ts-ignore - wm schema type error dont including array
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
const permissions = await hasPermission([permissionType], teamChannels[i].rid); const permissions = await hasPermission([permissionType], teamChannels[i].rid);
if (permissions[0]) { if (permissions[0]) {
// @ts-ignore - wm schema type error dont including array
teamChannelOwner.push(teamChannels[i]); teamChannelOwner.push(teamChannels[i]);
} }
} }