diff --git a/app/components/channel_list/categories/body/channel/channel_list_item.tsx b/app/components/channel_list/categories/body/channel/channel_list_item.tsx index f364bd3ec..6a3e92354 100644 --- a/app/components/channel_list/categories/body/channel/channel_list_item.tsx +++ b/app/components/channel_list/categories/body/channel/channel_list_item.tsx @@ -54,7 +54,7 @@ type Props = { isActive: boolean; isOwnDirectMessage: boolean; isMuted: boolean; - myChannel: MyChannelModel; + myChannel?: MyChannelModel; collapsed: boolean; } @@ -65,7 +65,7 @@ const ChannelListItem = ({channel, isActive, isOwnDirectMessage, isMuted, myChan const serverUrl = useServerUrl(); // Make it brighter if it's not muted, and highlighted or has unreads - const bright = !isMuted && (myChannel.isUnread || myChannel.mentionsCount > 0); + const bright = !isMuted && (myChannel?.isUnread || (myChannel?.mentionsCount ?? 0) > 0); const sharedValue = useSharedValue(collapsed && !bright); @@ -80,7 +80,11 @@ const ChannelListItem = ({channel, isActive, isOwnDirectMessage, isMuted, myChan }; }); - const switchChannels = () => switchToChannelById(serverUrl, myChannel.id); + const switchChannels = () => { + if (myChannel) { + switchToChannelById(serverUrl, myChannel.id); + } + }; const membersCount = useMemo(() => { if (channel.type === General.GM_CHANNEL) { return channel.displayName?.split(',').length; @@ -101,7 +105,7 @@ const ChannelListItem = ({channel, isActive, isOwnDirectMessage, isMuted, myChan displayName = formatMessage({id: 'channel_header.directchannel.you', defaultMessage: '{displayName} (you)'}, {displayName}); } - if (channel.deleteAt > 0 && !isActive) { + if ((channel.deleteAt > 0 && !isActive) || !myChannel) { return null; } diff --git a/app/components/channel_list/categories/body/channel/index.ts b/app/components/channel_list/categories/body/channel/index.ts index 9e0ca2717..3a4c6c667 100644 --- a/app/components/channel_list/categories/body/channel/index.ts +++ b/app/components/channel_list/categories/body/channel/index.ts @@ -4,7 +4,7 @@ import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider'; import withObservables from '@nozbe/with-observables'; import {combineLatest, of as of$} from 'rxjs'; -import {switchMap} from 'rxjs/operators'; +import {catchError, switchMap} from 'rxjs/operators'; import {General} from '@constants'; import {MM_TABLES, SYSTEM_IDENTIFIERS} from '@constants/database'; @@ -22,12 +22,14 @@ const {SERVER: {MY_CHANNEL, SYSTEM}} = MM_TABLES; const {CURRENT_USER_ID} = SYSTEM_IDENTIFIERS; const enhance = withObservables(['channelId'], ({channelId, database}: {channelId: string} & WithDatabaseArgs) => { - const myChannel = database.get(MY_CHANNEL).findAndObserve(channelId); + const myChannel = database.get(MY_CHANNEL).findAndObserve(channelId).pipe( + catchError(() => of$(undefined)), + ); const currentUserId = database.get(SYSTEM).findAndObserve(CURRENT_USER_ID).pipe( switchMap(({value}) => of$(value)), ); - const channel = myChannel.pipe(switchMap((my) => my.channel.observe())); + const channel = myChannel.pipe(switchMap((my) => (my ? my.channel.observe() : of$(undefined)))); const settings = channel.pipe(switchMap((c) => c.settings.observe())); const isOwnDirectMessage = combineLatest([currentUserId, channel]).pipe(