Merge branch 'gekidou' into gekidou-fixes
This commit is contained in:
commit
ccb29bbce6
8 changed files with 65 additions and 14 deletions
|
|
@ -36,6 +36,7 @@ describe('components/channel_list/categories/body', () => {
|
|||
category={category}
|
||||
locale={DEFAULT_LOCALE}
|
||||
currentChannelId={''}
|
||||
currentUserId={''}
|
||||
/>,
|
||||
{database},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,19 +11,27 @@ import type CategoryModel from '@typings/database/models/servers/category';
|
|||
type Props = {
|
||||
currentChannelId: string;
|
||||
sortedIds: string[];
|
||||
hiddenChannelIds: string[];
|
||||
category: CategoryModel;
|
||||
limit: number;
|
||||
};
|
||||
|
||||
const extractKey = (item: string) => item;
|
||||
|
||||
const CategoryBody = ({currentChannelId, sortedIds, category, limit}: Props) => {
|
||||
const CategoryBody = ({currentChannelId, sortedIds, category, hiddenChannelIds, limit}: Props) => {
|
||||
const ids = useMemo(() => {
|
||||
if (category.type === 'direct_messages' && limit > 0) {
|
||||
return sortedIds.slice(0, limit - 1);
|
||||
let filteredIds = sortedIds;
|
||||
|
||||
// Remove all closed gm/dms
|
||||
if (hiddenChannelIds.length) {
|
||||
filteredIds = sortedIds.filter((id) => !hiddenChannelIds.includes(id));
|
||||
}
|
||||
return sortedIds;
|
||||
}, [category.type, limit]);
|
||||
|
||||
if (category.type === 'direct_messages' && limit > 0) {
|
||||
return filteredIds.slice(0, limit - 1);
|
||||
}
|
||||
return filteredIds;
|
||||
}, [category.type, limit, hiddenChannelIds]);
|
||||
|
||||
const ChannelItem = useCallback(({item}: {item: string}) => {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -8,15 +8,17 @@ import {combineLatest, of as of$} from 'rxjs';
|
|||
import {switchMap} from 'rxjs/operators';
|
||||
|
||||
import {General, Preferences} from '@constants';
|
||||
import {queryMyChannelSettingsByIds} from '@queries/servers/channel';
|
||||
import {queryChannelsByNames, queryMyChannelSettingsByIds} from '@queries/servers/channel';
|
||||
import {queryPreferencesByCategoryAndName} from '@queries/servers/preference';
|
||||
import {WithDatabaseArgs} from '@typings/database/database';
|
||||
import {getDirectChannelName} from '@utils/channel';
|
||||
|
||||
import CategoryBody from './category_body';
|
||||
|
||||
import type CategoryModel from '@typings/database/models/servers/category';
|
||||
import type ChannelModel from '@typings/database/models/servers/channel';
|
||||
import type MyChannelSettingsModel from '@typings/database/models/servers/my_channel_settings';
|
||||
import type PreferenceModel from '@typings/database/models/servers/preference';
|
||||
|
||||
type ChannelData = Pick<ChannelModel, 'id' | 'displayName'> & {
|
||||
isMuted: boolean;
|
||||
|
|
@ -77,23 +79,51 @@ const getSortedIds = (database: Database, category: CategoryModel, locale: strin
|
|||
}
|
||||
};
|
||||
|
||||
const enhance = withObservables(['category'], ({category, locale, database}: {category: CategoryModel; locale: string} & WithDatabaseArgs) => {
|
||||
const mapPrefName = (prefs: PreferenceModel[]) => of$(prefs.map((p) => p.name));
|
||||
|
||||
const mapChannelIds = (channels: ChannelModel[]) => of$(channels.map((c) => c.id));
|
||||
|
||||
type EnhanceProps = {category: CategoryModel; locale: string; currentUserId: string} & WithDatabaseArgs
|
||||
|
||||
const enhance = withObservables(['category'], ({category, locale, database, currentUserId}: EnhanceProps) => {
|
||||
const observedCategory = category.observe();
|
||||
const sortedIds = observedCategory.pipe(
|
||||
switchMap((c) => getSortedIds(database, c, locale)),
|
||||
);
|
||||
|
||||
let limit = of$(20);
|
||||
const dmMap = (p: PreferenceModel) => getDirectChannelName(p.name, currentUserId);
|
||||
|
||||
const hiddenDmIds = queryPreferencesByCategoryAndName(database, Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, undefined, 'false').
|
||||
observe().pipe(
|
||||
switchMap((prefs: PreferenceModel[]) => {
|
||||
const names = prefs.map(dmMap);
|
||||
const channels = queryChannelsByNames(database, names).observe();
|
||||
|
||||
return channels.pipe(
|
||||
switchMap(mapChannelIds),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
const hiddenGmIds = queryPreferencesByCategoryAndName(database, Preferences.CATEGORY_GROUP_CHANNEL_SHOW, undefined, 'false').
|
||||
observe().pipe(switchMap(mapPrefName));
|
||||
|
||||
let limit = of$(Preferences.CHANNEL_SIDEBAR_LIMIT_DMS_DEFAULT);
|
||||
if (category.type === 'direct_messages') {
|
||||
limit = queryPreferencesByCategoryAndName(database, Preferences.CATEGORY_SIDEBAR_SETTINGS, 'limit_visible_dms_gms').observe().pipe(
|
||||
limit = queryPreferencesByCategoryAndName(database, Preferences.CATEGORY_SIDEBAR_SETTINGS, Preferences.CHANNEL_SIDEBAR_LIMIT_DMS).observe().pipe(
|
||||
switchMap((val) => {
|
||||
return val[0] ? of$(parseInt(val[0].value, 10)) : of$(0);
|
||||
return val[0] ? of$(parseInt(val[0].value, 10)) : of$(Preferences.CHANNEL_SIDEBAR_LIMIT_DMS_DEFAULT);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const hiddenChannelIds = combineLatest([hiddenDmIds, hiddenGmIds]).pipe(switchMap(
|
||||
([a, b]) => of$(a.concat(b)),
|
||||
));
|
||||
|
||||
return {
|
||||
limit,
|
||||
hiddenChannelIds,
|
||||
sortedIds,
|
||||
category: observedCategory,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import type {CategoryModel} from '@database/models/server';
|
|||
type Props = {
|
||||
categories: CategoryModel[];
|
||||
currentChannelId: string;
|
||||
currentUserId: string;
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
|
|
@ -24,8 +25,9 @@ const styles = StyleSheet.create({
|
|||
|
||||
const extractKey = (item: CategoryModel) => item.id;
|
||||
|
||||
const Categories = ({categories, currentChannelId}: Props) => {
|
||||
const Categories = ({categories, currentChannelId, currentUserId}: Props) => {
|
||||
const intl = useIntl();
|
||||
|
||||
const renderCategory = useCallback((data: {item: CategoryModel}) => {
|
||||
return (
|
||||
<>
|
||||
|
|
@ -33,6 +35,7 @@ const Categories = ({categories, currentChannelId}: Props) => {
|
|||
<CategoryBody
|
||||
category={data.item}
|
||||
currentChannelId={currentChannelId}
|
||||
currentUserId={currentUserId}
|
||||
locale={intl.locale}
|
||||
/>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
|
|||
import withObservables from '@nozbe/with-observables';
|
||||
|
||||
import {queryCategoriesByTeamIds} from '@queries/servers/categories';
|
||||
import {observeCurrentChannelId} from '@queries/servers/system';
|
||||
import {observeCurrentChannelId, observeCurrentUserId} from '@queries/servers/system';
|
||||
|
||||
import Categories from './categories';
|
||||
|
||||
|
|
@ -17,11 +17,13 @@ const enhanced = withObservables(
|
|||
['currentTeamId'],
|
||||
({currentTeamId, database}: WithDatabaseProps) => {
|
||||
const currentChannelId = observeCurrentChannelId(database);
|
||||
const currentUserId = observeCurrentUserId(database);
|
||||
const categories = queryCategoriesByTeamIds(database, [currentTeamId]).observeWithColumns(['sort_order']);
|
||||
|
||||
return {
|
||||
currentChannelId,
|
||||
categories,
|
||||
currentUserId,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ const Preferences: Record<string, any> = {
|
|||
USE_MILITARY_TIME: 'use_military_time',
|
||||
CATEGORY_SIDEBAR_SETTINGS: 'sidebar_settings',
|
||||
CHANNEL_SIDEBAR_ORGANIZATION: 'channel_sidebar_organization',
|
||||
CHANNEL_SIDEBAR_AUTOCLOSE_DMS: 'close_unused_direct_messages',
|
||||
CHANNEL_SIDEBAR_LIMIT_DMS: 'limit_visible_dms_gms',
|
||||
CHANNEL_SIDEBAR_LIMIT_DMS_DEFAULT: 20,
|
||||
AUTOCLOSE_DMS_ENABLED: 'after_seven_days',
|
||||
CATEGORY_ADVANCED_SETTINGS: 'advanced_settings',
|
||||
ADVANCED_FILTER_JOIN_LEAVE: 'join_leave',
|
||||
|
|
|
|||
|
|
@ -303,3 +303,7 @@ export const queryMyChannelSettingsByIds = (database: Database, ids: string[]) =
|
|||
Q.where('id', Q.oneOf(ids)),
|
||||
);
|
||||
};
|
||||
|
||||
export const queryChannelsByNames = (database: Database, names: string[]) => {
|
||||
return database.get<ChannelModel>(CHANNEL).query(Q.where('name', Q.oneOf(names)));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import {getCurrentTeamId} from './system';
|
|||
import type ServerDataOperator from '@database/operator/server_data_operator';
|
||||
import type PreferenceModel from '@typings/database/models/servers/preference';
|
||||
|
||||
const {SERVER: {PREFERENCE}} = MM_TABLES;
|
||||
|
||||
export const prepareMyPreferences = (operator: ServerDataOperator, preferences: PreferenceType[], sync = false) => {
|
||||
try {
|
||||
return operator.handlePreferences({
|
||||
|
|
@ -32,7 +34,7 @@ export const queryPreferencesByCategoryAndName = (database: Database, category:
|
|||
if (value != null) {
|
||||
clauses.push(Q.where('value', value));
|
||||
}
|
||||
return database.get<PreferenceModel>(MM_TABLES.SERVER.PREFERENCE).query(...clauses);
|
||||
return database.get<PreferenceModel>(PREFERENCE).query(...clauses);
|
||||
};
|
||||
|
||||
export const getThemeForCurrentTeam = async (database: Database) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue