Handes visibility preference setting for dm/gm
This commit is contained in:
parent
4cedbdfdd2
commit
368f6aa08d
8 changed files with 78 additions and 15 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,6 +8,9 @@ import {combineLatest, of as of$} from 'rxjs';
|
|||
import {switchMap} from 'rxjs/operators';
|
||||
|
||||
import {MM_TABLES} from '@app/constants/database';
|
||||
import {queryChannelsByNames} from '@app/queries/servers/channel';
|
||||
import {queryPreferencesByCategory} from '@app/queries/servers/preference';
|
||||
import {getDirectChannelName} from '@app/utils/channel';
|
||||
import {General, Preferences} from '@constants';
|
||||
import {WithDatabaseArgs} from '@typings/database/database';
|
||||
|
||||
|
|
@ -22,7 +25,7 @@ type ChannelData = Pick<ChannelModel, 'id' | 'displayName'> & {
|
|||
isMuted: boolean;
|
||||
};
|
||||
|
||||
const {SERVER: {MY_CHANNEL_SETTINGS, PREFERENCE}} = MM_TABLES;
|
||||
const {SERVER: {MY_CHANNEL_SETTINGS}} = MM_TABLES;
|
||||
|
||||
const sortAlpha = (locale: string, a: ChannelData, b: ChannelData) => {
|
||||
if (a.isMuted && !b.isMuted) {
|
||||
|
|
@ -82,19 +85,37 @@ 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));
|
||||
|
||||
const enhance = withObservables(['category'], ({category, locale, database, currentUserId}: {category: CategoryModel; locale: string; currentUserId: string} & WithDatabaseArgs) => {
|
||||
const observedCategory = category.observe();
|
||||
const sortedIds = observedCategory.pipe(
|
||||
switchMap((c) => getSortedIds(database, c, locale)),
|
||||
);
|
||||
|
||||
const dmMap = (p: PreferenceModel) => getDirectChannelName(p.name, currentUserId);
|
||||
|
||||
const hiddenDmIds = queryPreferencesByCategory(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 = queryPreferencesByCategory(database, Preferences.CATEGORY_GROUP_CHANNEL_SHOW, undefined, 'false').
|
||||
observe().pipe(switchMap(mapPrefName));
|
||||
|
||||
let limit = of$(0);
|
||||
if (category.type === 'direct_messages') {
|
||||
limit = database.get<PreferenceModel>(PREFERENCE).
|
||||
query(
|
||||
Q.where('category', Preferences.CATEGORY_SIDEBAR_SETTINGS),
|
||||
Q.where('name', 'limit_visible_dms_gms'),
|
||||
).observe().pipe(
|
||||
limit = queryPreferencesByCategory(database, Preferences.CATEGORY_SIDEBAR_SETTINGS, Preferences.CHANNEL_SIDEBAR_LIMIT_DMS).
|
||||
observe().pipe(
|
||||
switchMap(
|
||||
(val) => {
|
||||
if (val[0]) {
|
||||
|
|
@ -107,8 +128,13 @@ const enhance = withObservables(['category'], ({category, locale, database}: {ca
|
|||
);
|
||||
}
|
||||
|
||||
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}
|
||||
/>
|
||||
</>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import type CategoryModel from '@typings/database/models/servers/category';
|
|||
import type SystemModel from '@typings/database/models/servers/system';
|
||||
|
||||
const {SERVER: {CATEGORY, SYSTEM}} = MM_TABLES;
|
||||
const {CURRENT_CHANNEL_ID} = SYSTEM_IDENTIFIERS;
|
||||
const {CURRENT_CHANNEL_ID, CURRENT_USER_ID} = SYSTEM_IDENTIFIERS;
|
||||
|
||||
type WithDatabaseProps = {currentTeamId: string } & WithDatabaseArgs
|
||||
|
||||
|
|
@ -26,6 +26,9 @@ const enhanced = withObservables(
|
|||
const currentChannelId = database.get<SystemModel>(SYSTEM).findAndObserve(CURRENT_CHANNEL_ID).pipe(
|
||||
switchMap(({value}) => of$(value)),
|
||||
);
|
||||
const currentUserId = database.get<SystemModel>(SYSTEM).findAndObserve(CURRENT_USER_ID).pipe(
|
||||
switchMap(({value}) => of$(value)),
|
||||
);
|
||||
const categories = database.get<CategoryModel>(CATEGORY).query(
|
||||
Q.where('team_id', currentTeamId),
|
||||
).observeWithColumns(['sort_order']);
|
||||
|
|
@ -33,6 +36,7 @@ const enhanced = withObservables(
|
|||
return {
|
||||
currentChannelId,
|
||||
categories,
|
||||
currentUserId,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ const Preferences: Record<string, any> = {
|
|||
CATEGORY_FAVORITE_CHANNEL: 'favorite_channel',
|
||||
CATEGORY_AUTO_RESET_MANUAL_STATUS: 'auto_reset_manual_status',
|
||||
CATEGORY_NOTIFICATIONS: 'notifications',
|
||||
|
||||
COMMENTS: 'comments',
|
||||
COMMENTS_ANY: 'any',
|
||||
COMMENTS_ROOT: 'root',
|
||||
|
|
@ -35,7 +36,7 @@ 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',
|
||||
AUTOCLOSE_DMS_ENABLED: 'after_seven_days',
|
||||
CATEGORY_ADVANCED_SETTINGS: 'advanced_settings',
|
||||
ADVANCED_FILTER_JOIN_LEAVE: 'join_leave',
|
||||
|
|
|
|||
|
|
@ -247,3 +247,7 @@ export const addChannelMembership = async (operator: ServerDataOperator, userId:
|
|||
export const queryAllMyChannelMembershipIds = async (database: Database, userId: string) => {
|
||||
return database.get(CHANNEL_MEMBERSHIP).query(Q.where('user_id', Q.eq(userId))).fetchIds();
|
||||
};
|
||||
|
||||
export const queryChannelsByNames = (database: Database, names: string[]) => {
|
||||
return database.get<ChannelModel>(CHANNEL).query(Q.where('name', Q.oneOf(names)));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import {queryCurrentTeamId} 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({
|
||||
|
|
@ -65,3 +67,17 @@ export const deletePreferences = async (database: ServerDatabase, preferences: P
|
|||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const queryPreferencesByCategory = (database: Database, category: string, name?: string, value?: string) => {
|
||||
const clauses = [Q.where('category', category)];
|
||||
|
||||
if (typeof name === 'string') {
|
||||
clauses.push(Q.where('name', name));
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
clauses.push(Q.where('value', value));
|
||||
}
|
||||
|
||||
return database.get<PreferenceModel>(PREFERENCE).query(...clauses);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue