diff --git a/app/components/channel_list/categories/categories.tsx b/app/components/channel_list/categories/categories.tsx index f4ccb5e15..2225f29fb 100644 --- a/app/components/channel_list/categories/categories.tsx +++ b/app/components/channel_list/categories/categories.tsx @@ -27,15 +27,26 @@ const styles = StyleSheet.create({ }, }); -const extractKey = (item: CategoryModel) => item.id; +const extractKey = (item: CategoryModel) => (Array.isArray(item) ? 'UNREADS' : item.id); const Categories = ({categories, currentChannelId, currentUserId, currentTeamId, unreadChannels}: Props) => { const intl = useIntl(); const listRef = useRef(null); const unreadChannelIds = useMemo(() => new Set(unreadChannels.map((myC) => myC.id)), [unreadChannels]); + const categoriesToDisplay: Array = useMemo(() => { + if (unreadChannelIds.size) { + return [Array.from(unreadChannelIds), ...categories]; + } + + return categories; + }, [categories, unreadChannelIds]); + + const renderCategory = useCallback((data: {item: CategoryModel | string[]}) => { + if (Array.isArray(data.item)) { + return ; + } - const renderCategory = useCallback((data: {item: CategoryModel}) => { return ( <> @@ -48,7 +59,7 @@ const Categories = ({categories, currentChannelId, currentUserId, currentTeamId, /> ); - }, [categories, currentChannelId, intl.locale]); + }, [categories, currentChannelId, intl.locale, unreadChannels]); useEffect(() => { listRef.current?.scrollToOffset({animated: false, offset: 0}); @@ -62,23 +73,20 @@ const Categories = ({categories, currentChannelId, currentUserId, currentTeamId, } return ( - <> - {unreadChannels.length > 0 && } - - + ); }; diff --git a/app/components/channel_list/categories/index.ts b/app/components/channel_list/categories/index.ts index 3f3848e00..4a7a303b1 100644 --- a/app/components/channel_list/categories/index.ts +++ b/app/components/channel_list/categories/index.ts @@ -29,7 +29,7 @@ const enhanced = withObservables( const categories = queryCategoriesByTeamIds(database, [currentTeamId]).observeWithColumns(['sort_order']); const unreadsOnTop = queryPreferencesByCategoryAndName(database, Preferences.CATEGORY_SIDEBAR_SETTINGS, Preferences.CHANNEL_SIDEBAR_GROUP_UNREADS). - observe(). + observeWithColumns(['value']). pipe( switchMap((prefs: PreferenceModel[]) => of$(getPreferenceAsBool(prefs, Preferences.CATEGORY_SIDEBAR_SETTINGS, Preferences.CHANNEL_SIDEBAR_GROUP_UNREADS, false))), ); diff --git a/app/queries/servers/channel.ts b/app/queries/servers/channel.ts index 1e7a5845a..754220d20 100644 --- a/app/queries/servers/channel.ts +++ b/app/queries/servers/channel.ts @@ -377,9 +377,12 @@ export const queryMyChannelUnreads = (database: Database, currentTeamId: string) return database.get(MY_CHANNEL).query( Q.on( CHANNEL, - Q.or( - Q.where('team_id', Q.eq(currentTeamId)), - Q.where('team_id', Q.eq('')), + Q.and( + Q.or( + Q.where('team_id', Q.eq(currentTeamId)), + Q.where('team_id', Q.eq('')), + ), + Q.where('delete_at', Q.eq(0)), ), ), Q.where('is_unread', Q.eq(true)),