fix: crashing the app - Cannot read property 'find' of null at fetchRole method (#5447)

* fix: crashing the app - Cannot read property 'find' of null at fetchRole method

* minor tweak

* minor tweak
This commit is contained in:
Reinaldo Neto 2024-01-09 15:14:55 -03:00 committed by GitHub
parent 35cb39a2f2
commit 9109b87269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import { Q } from '@nozbe/watermelondb';
import { LISTENER } from '../../containers/Toast';
import { IUser, SubscriptionType, TSubscriptionModel, TUserModel } from '../../definitions';
import { IGetRoomRoles, IUser, SubscriptionType, TSubscriptionModel, TUserModel } from '../../definitions';
import I18n from '../../i18n';
import { getRoomTitle, showConfirmationAlert, showErrorAlert } from '../../lib/methods/helpers';
import EventEmitter from '../../lib/methods/helpers/events';
@ -18,9 +18,9 @@ const handleGoRoom = (item: TGoRoomItem, isMasterDetail: boolean): void => {
goRoom({ item, isMasterDetail, popToRoot: true });
};
export const fetchRole = (role: string, selectedUser: TUserModel, roomRoles: any): boolean => {
const userRoleResult = roomRoles.find((r: any) => r.u._id === selectedUser._id);
return userRoleResult?.roles.includes(role);
export const fetchRole = (role: string, selectedUser: TUserModel, roomRoles?: IGetRoomRoles[]): boolean => {
const userRoleResult = roomRoles?.find((r: any) => r.u._id === selectedUser._id);
return !!userRoleResult?.roles.includes(role);
};
export const fetchRoomMembersRoles = async (roomType: TRoomType, rid: string, updateState: any): Promise<void> => {

View File

@ -13,7 +13,7 @@ import SafeAreaView from '../../containers/SafeAreaView';
import SearchBox from '../../containers/SearchBox';
import StatusBar from '../../containers/StatusBar';
import UserItem from '../../containers/UserItem';
import { TSubscriptionModel, TUserModel } from '../../definitions';
import { IGetRoomRoles, TSubscriptionModel, TUserModel } from '../../definitions';
import I18n from '../../i18n';
import { useAppSelector, usePermissions } from '../../lib/hooks';
import { compareServerVersion, getRoomTitle, isGroupChat } from '../../lib/methods/helpers';
@ -50,7 +50,7 @@ interface IRoomMembersViewState {
members: TUserModel[];
room: TSubscriptionModel;
end: boolean;
roomRoles: any;
roomRoles?: IGetRoomRoles[];
filter: string;
page: number;
}
@ -93,7 +93,7 @@ const RoomMembersView = (): React.ReactElement => {
members: [],
room: params.room || ({} as TSubscriptionModel),
end: false,
roomRoles: null,
roomRoles: undefined,
filter: '',
page: 0
}