forked from Ivasoft/mattermost-mobile
* Init * Test fix * New sync implementation * misc * Includes migration and other servers sync * Misc * Migration fix * Migration is done version 7 * Update app/queries/servers/thread.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Update app/database/operator/server_data_operator/handlers/team_threads_sync.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * Feedback changes * Fixes when old thread gets a reply * Fix Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {Config, Preferences} from '@constants';
|
|
import {getPreferenceValue} from '@helpers/api/preference';
|
|
|
|
import type PreferenceModel from '@typings/database/models/servers/preference';
|
|
|
|
export function processIsCRTEnabled(preferences: PreferenceModel[]|PreferenceType[], configValue?: string, featureFlag?: string): boolean {
|
|
let preferenceDefault = Preferences.COLLAPSED_REPLY_THREADS_OFF;
|
|
if (configValue === Config.DEFAULT_ON) {
|
|
preferenceDefault = Preferences.COLLAPSED_REPLY_THREADS_ON;
|
|
}
|
|
const preference = getPreferenceValue(preferences, Preferences.CATEGORY_DISPLAY_SETTINGS, Preferences.COLLAPSED_REPLY_THREADS, preferenceDefault);
|
|
|
|
const isAllowed = (
|
|
featureFlag === Config.TRUE &&
|
|
configValue !== Config.DISABLED
|
|
);
|
|
|
|
return isAllowed && (
|
|
preference === Preferences.COLLAPSED_REPLY_THREADS_ON ||
|
|
configValue === Config.ALWAYS_ON
|
|
);
|
|
}
|
|
|
|
export const getThreadsListEdges = (threads: Thread[]) => {
|
|
// Sort a clone of 'threads' array by last_reply_at
|
|
const sortedThreads = [...threads].sort((a, b) => {
|
|
return a.last_reply_at - b.last_reply_at;
|
|
});
|
|
|
|
const earliestThread = sortedThreads[0];
|
|
const latestThread = sortedThreads[sortedThreads.length - 1];
|
|
|
|
return {earliestThread, latestThread};
|
|
};
|