Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions app/actions/remote/channel_bookmark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ describe('channel bookmarks', () => {
await DatabaseManager.init([serverUrl]);
operator = DatabaseManager.serverDatabases[serverUrl]!.operator;
await operator.handleConfigs({
configs: [
{id: 'FeatureFlagChannelBookmarks', value: 'true'},
],
configs: [{id: 'Version', value: '10.1.0'}],
configsToDelete: [],
prepareRecordsOnly: false,
});
Expand Down Expand Up @@ -87,18 +85,17 @@ describe('channel bookmarks', () => {
expect(bookmarkSpy).not.toHaveBeenCalled();
});

it('fetchChannelBookmarks - feature flag disabled', async () => {
it('fetchChannelBookmarks - old server version', async () => {
await operator.handleConfigs({
configs: [
{id: 'FeatureFlagChannelBookmarks', value: 'false'},
],
configs: [{id: 'Version', value: '10.0.0'}],
configsToDelete: [],
prepareRecordsOnly: false,
});
const result = await fetchChannelBookmarks(serverUrl, channelId);
expect(result).toBeDefined();
expect(result.bookmarks).toBeDefined();
expect(result.bookmarks?.length).toBe(0);
expect(mockClient.getChannelBookmarksForChannel).not.toHaveBeenCalled();
});

it('createChannelBookmark - handle not found database', async () => {
Expand Down
6 changes: 4 additions & 2 deletions app/actions/remote/channel_bookmark.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {CHANNEL_BOOKMARKS_VERSION} from '@constants/versions';
import DatabaseManager from '@database/manager';
import NetworkManager from '@managers/network_manager';
import websocketManager from '@managers/websocket_manager';
import {getBookmarksSince, getChannelBookmarkById} from '@queries/servers/channel_bookmark';
import {getConfigValue, getLicense} from '@queries/servers/system';
import {getFullErrorMessage} from '@utils/errors';
import {isMinimumServerVersion} from '@utils/helpers';
import {logError} from '@utils/log';

import {forceLogoutIfNecessary} from './session';
Expand All @@ -16,10 +18,10 @@ export async function fetchChannelBookmarks(serverUrl: string, channelId: string
const client = NetworkManager.getClient(serverUrl);
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);

const bookmarksEnabled = (await getConfigValue(database, 'FeatureFlagChannelBookmarks')) === 'true';
const serverVersion = await getConfigValue(database, 'Version');
const isLicensed = (await getLicense(database))?.IsLicensed === 'true';

if (!bookmarksEnabled || !isLicensed) {
if (!isMinimumServerVersion(serverVersion, ...CHANNEL_BOOKMARKS_VERSION) || !isLicensed) {
return {bookmarks: []};
}

Expand Down
1 change: 1 addition & 0 deletions app/constants/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See LICENSE.txt for license information.

export const GM_AS_DM_VERSION = [9, 1, 0];
export const CHANNEL_BOOKMARKS_VERSION = [10, 1, 0];

export const OS_VERSION = {
ANDROID: 'android',
Expand Down
8 changes: 7 additions & 1 deletion app/queries/servers/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {of as of$} from 'rxjs';
import {switchMap} from 'rxjs/operators';

import {GM_AS_DM_VERSION} from '@constants/versions';
import {CHANNEL_BOOKMARKS_VERSION, GM_AS_DM_VERSION} from '@constants/versions';
import {isMinimumServerVersion} from '@utils/helpers';

import {observeConfigValue} from './system';
Expand All @@ -16,3 +16,9 @@ export const observeHasGMasDMFeature = (database: Database) => {
switchMap((v) => of$(isMinimumServerVersion(v, ...GM_AS_DM_VERSION))),
);
};

export const observeIsChannelBookmarksEnabled = (database: Database) => {
return observeConfigValue(database, 'Version').pipe(
switchMap((v) => of$(isMinimumServerVersion(v, ...CHANNEL_BOOKMARKS_VERSION))),
);
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
3 changes: 2 additions & 1 deletion app/screens/channel/header/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {queryPlaybookRunsPerChannel} from '@playbooks/database/queries/run';
import {observeIsPlaybooksEnabled} from '@playbooks/database/queries/version';
import {observeChannel, observeChannelInfo, observeIsChannelAutotranslated} from '@queries/servers/channel';
import {observeCanAddBookmarks, queryBookmarks} from '@queries/servers/channel_bookmark';
import {observeIsChannelBookmarksEnabled} from '@queries/servers/features';
import {observeConfigBooleanValue, observeCurrentTeamId, observeCurrentUserId} from '@queries/servers/system';
import {observeIsUserLanguageSupportedByAutotranslation, observeUser} from '@queries/servers/user';
import {
Expand Down Expand Up @@ -94,7 +95,7 @@ const enhanced = withObservables(['channelId'], ({channelId, database}: OwnProps
distinctUntilChanged(),
);

const isBookmarksEnabled = observeConfigBooleanValue(database, 'FeatureFlagChannelBookmarks');
const isBookmarksEnabled = observeIsChannelBookmarksEnabled(database);
const canAddBookmarks = observeCanAddBookmarks(database, channelId);

const activeRuns = isPlaybooksEnabled.pipe(
Expand Down
5 changes: 2 additions & 3 deletions app/screens/channel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {Preferences} from '@constants';
import {withServerUrl} from '@context/server';
import {observeCurrentChannel} from '@queries/servers/channel';
import {queryBookmarks} from '@queries/servers/channel_bookmark';
import {observeHasGMasDMFeature} from '@queries/servers/features';
import {observeHasGMasDMFeature, observeIsChannelBookmarksEnabled} from '@queries/servers/features';
import {queryPreferencesByCategoryAndName} from '@queries/servers/preference';
import {observeScheduledPostCountForChannel} from '@queries/servers/scheduled_post';
import {
observeConfigBooleanValue,
observeCurrentChannelId,
observeCurrentUserId,
} from '@queries/servers/system';
Expand All @@ -35,7 +34,7 @@ const enhanced = withObservables([], ({database, serverUrl}: EnhanceProps) => {
const channelType = observeCurrentChannel(database).pipe(switchMap((c) => of$(c?.type)));
const currentUserId = observeCurrentUserId(database);
const hasGMasDMFeature = observeHasGMasDMFeature(database);
const isBookmarksEnabled = observeConfigBooleanValue(database, 'FeatureFlagChannelBookmarks');
const isBookmarksEnabled = observeIsChannelBookmarksEnabled(database);
const hasBookmarks = (count: number) => of$(count > 0);
const includeBookmarkBar = channelId.pipe(
combineLatestWith(isBookmarksEnabled),
Expand Down
4 changes: 2 additions & 2 deletions app/screens/channel_info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {withServerUrl} from '@context/server';
import {observeIsPlaybooksEnabled} from '@playbooks/database/queries/version';
import {observeChannelAutotranslation, observeCurrentChannel} from '@queries/servers/channel';
import {observeCanAddBookmarks} from '@queries/servers/channel_bookmark';
import {observeIsChannelBookmarksEnabled} from '@queries/servers/features';
import {observeCanManageChannelAutotranslations, observeCanManageChannelMembers, observeCanManageChannelSettings, observePermissionForChannel, observePermissionForTeam} from '@queries/servers/role';
import {
observeConfigBooleanValue,
observeConfigValue,
observeCurrentChannelId,
observeCurrentTeamId,
Expand Down Expand Up @@ -241,7 +241,7 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => {
distinctUntilChanged(),
);

const isBookmarksEnabled = observeConfigBooleanValue(database, 'FeatureFlagChannelBookmarks');
const isBookmarksEnabled = observeIsChannelBookmarksEnabled(database);

const canAddBookmarks = channelId.pipe(
switchMap((cId) => {
Expand Down
Loading