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;
}
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 {
WIDGET = 'widget',
EMAIL = 'email',

View File

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