mattermost-mobile/app/queries/servers/preference.ts
Elias Nahum 7e6248dfb3
[Gekidou] - Channel Intro (#5846)
* Channel Intro

* Move avatar margins to post component per feedback review

* Channel intro redesign

* Fix preferences unit test

* Change group intro sizes

* Add Bot tag to DM Intro if they have it

* fix channel isTablet layout on split screen

* update snapshot
2021-12-21 17:44:00 +02:00

48 lines
1.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {Database, Q} from '@nozbe/watermelondb';
import {Preferences} from '@constants';
import {MM_TABLES} from '@constants/database';
import {queryCurrentTeamId} from './system';
import type ServerDataOperator from '@database/operator/server_data_operator';
import type PreferenceModel from '@typings/database/models/servers/preference';
export const prepareMyPreferences = (operator: ServerDataOperator, preferences: PreferenceType[], sync = false) => {
try {
return operator.handlePreferences({
prepareRecordsOnly: true,
preferences,
sync,
});
} catch {
return undefined;
}
};
export const queryPreferencesByCategoryAndName = (database: Database, category: string, name: string) => {
return database.
get<PreferenceModel>(MM_TABLES.SERVER.PREFERENCE).
query(
Q.where('category', category),
Q.where('name', name),
).
fetch();
};
export const queryThemeForCurrentTeam = async (database: Database) => {
const currentTeamId = await queryCurrentTeamId(database);
const teamTheme = await queryPreferencesByCategoryAndName(database, Preferences.CATEGORY_THEME, currentTeamId);
if (teamTheme.length) {
try {
return JSON.parse(teamTheme[0].value) as Theme;
} catch {
return undefined;
}
}
return undefined;
};