Merge branch 'gekidou' into MM-35065-add-onboarding-screens
This commit is contained in:
commit
96001c3553
5 changed files with 44 additions and 57 deletions
|
|
@ -268,6 +268,36 @@ describe('Actions.Calls', () => {
|
|||
assert.equal((result.current[2] as CurrentCall | null), null);
|
||||
});
|
||||
|
||||
it('loadCalls fails from server', async () => {
|
||||
const expectedCallsState: CallsState = {
|
||||
serverUrl: 'server1',
|
||||
myUserId: 'userId1',
|
||||
calls: {},
|
||||
enabled: {},
|
||||
};
|
||||
|
||||
// setup
|
||||
const oldGetCalls = mockClient.getCalls;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
mockClient.getCalls = jest.fn(() => null);
|
||||
|
||||
const {result} = renderHook(() => {
|
||||
return [useCallsState('server1'), useChannelsWithCalls('server1'), useCurrentCall()];
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await CallsActions.loadCalls('server1', 'userId1');
|
||||
});
|
||||
expect(mockClient.getCalls).toBeCalled();
|
||||
assert.deepEqual((result.current[0] as CallsState), expectedCallsState);
|
||||
assert.deepEqual((result.current[1] as ChannelsWithCalls), {});
|
||||
assert.equal((result.current[2] as CurrentCall | null), null);
|
||||
|
||||
mockClient.getCalls = oldGetCalls;
|
||||
});
|
||||
|
||||
it('loadConfig', async () => {
|
||||
// setup
|
||||
const {result} = renderHook(() => useCallsConfig('server1'));
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export const loadCalls = async (serverUrl: string, userId: string) => {
|
|||
}
|
||||
let resp: ServerChannelState[] = [];
|
||||
try {
|
||||
resp = await client.getCalls();
|
||||
resp = await client.getCalls() || [];
|
||||
} catch (error) {
|
||||
await forceLogoutIfNecessary(serverUrl, error as ClientError);
|
||||
return {error};
|
||||
|
|
|
|||
|
|
@ -469,22 +469,16 @@ export function observeMyChannelMentionCount(database: Database, teamId?: string
|
|||
);
|
||||
}
|
||||
|
||||
export function queryMyChannelsByUnread(database: Database, isUnread: boolean, sortBy: 'last_viewed_at' | 'last_post_at', take: number, excludeIds?: string[]) {
|
||||
const clause: Q.Clause[] = [Q.where('is_unread', Q.eq(isUnread))];
|
||||
export function queryMyRecentChannels(database: Database, take: number) {
|
||||
const count: Q.Clause[] = [];
|
||||
|
||||
if (excludeIds?.length) {
|
||||
clause.push(Q.where('id', Q.notIn(excludeIds)));
|
||||
}
|
||||
|
||||
if (take > 0) {
|
||||
count.push(Q.take(take));
|
||||
}
|
||||
|
||||
return queryAllMyChannel(database).extend(
|
||||
Q.on(CHANNEL, Q.where('delete_at', Q.eq(0))),
|
||||
...clause,
|
||||
Q.sortBy(sortBy, Q.desc),
|
||||
Q.sortBy('last_viewed_at', Q.desc),
|
||||
...count,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,57 +1,32 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {Database} from '@nozbe/watermelondb';
|
||||
import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
|
||||
import withObservables from '@nozbe/with-observables';
|
||||
import {of as of$} from 'rxjs';
|
||||
import {combineLatestWith, map, switchMap} from 'rxjs/operators';
|
||||
import {switchMap} from 'rxjs/operators';
|
||||
|
||||
import {filterAndSortMyChannels, makeChannelsMap} from '@helpers/database';
|
||||
import {observeNotifyPropsByChannels, queryMyChannelsByUnread} from '@queries/servers/channel';
|
||||
import {queryMyRecentChannels} from '@queries/servers/channel';
|
||||
import {queryJoinedTeams} from '@queries/servers/team';
|
||||
import {retrieveChannels} from '@screens/find_channels/utils';
|
||||
|
||||
import UnfilteredList from './unfiltered_list';
|
||||
|
||||
import type {WithDatabaseArgs} from '@typings/database/database';
|
||||
import type ChannelModel from '@typings/database/models/servers/channel';
|
||||
|
||||
const MAX_UNREAD_CHANNELS = 10;
|
||||
const MAX_CHANNELS = 20;
|
||||
|
||||
const observeRecentChannels = (database: Database, unreads: ChannelModel[]) => {
|
||||
const count = MAX_CHANNELS - unreads.length;
|
||||
const unreadIds = unreads.map((u) => u.id);
|
||||
return queryMyChannelsByUnread(database, false, 'last_viewed_at', count, unreadIds).observe().pipe(
|
||||
switchMap((myChannels) => retrieveChannels(database, myChannels, true)),
|
||||
);
|
||||
};
|
||||
|
||||
const enhanced = withObservables([], ({database}: WithDatabaseArgs) => {
|
||||
const teamsCount = queryJoinedTeams(database).observeCount();
|
||||
|
||||
const myUnreadChannels = queryMyChannelsByUnread(database, true, 'last_post_at', 0).
|
||||
observeWithColumns(['last_post_at']);
|
||||
const notifyProps = myUnreadChannels.pipe(switchMap((cs) => observeNotifyPropsByChannels(database, cs)));
|
||||
const channels = myUnreadChannels.pipe(
|
||||
switchMap((myChannels) => retrieveChannels(database, myChannels)),
|
||||
);
|
||||
const channelsMap = channels.pipe(switchMap((cs) => of$(makeChannelsMap(cs))));
|
||||
const unreadChannels = myUnreadChannels.pipe(
|
||||
combineLatestWith(channelsMap, notifyProps),
|
||||
map(filterAndSortMyChannels),
|
||||
switchMap((cs) => of$(cs.slice(0, MAX_UNREAD_CHANNELS))),
|
||||
);
|
||||
|
||||
const recentChannels = unreadChannels.pipe(
|
||||
switchMap((unreads) => observeRecentChannels(database, unreads)),
|
||||
);
|
||||
const recentChannels = queryMyRecentChannels(database, MAX_CHANNELS).
|
||||
observeWithColumns(['last_viewed_at']).pipe(
|
||||
switchMap((myChannels) => retrieveChannels(database, myChannels, true)),
|
||||
);
|
||||
|
||||
return {
|
||||
recentChannels,
|
||||
showTeamName: teamsCount.pipe(switchMap((count) => of$(count > 1))),
|
||||
unreadChannels,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -20,15 +20,10 @@ type Props = {
|
|||
keyboardHeight: number;
|
||||
recentChannels: ChannelModel[];
|
||||
showTeamName: boolean;
|
||||
unreadChannels: ChannelModel[];
|
||||
testID?: string;
|
||||
}
|
||||
|
||||
const sectionNames = {
|
||||
unreads: {
|
||||
id: t('mobile.channel_list.unreads'),
|
||||
defaultMessage: 'Unreads',
|
||||
},
|
||||
recent: {
|
||||
id: t('mobile.channel_list.recent'),
|
||||
defaultMessage: 'Recent',
|
||||
|
|
@ -39,15 +34,8 @@ const style = StyleSheet.create({
|
|||
flex: {flex: 1},
|
||||
});
|
||||
|
||||
const buildSections = (unreadChannels: ChannelModel[], recentChannels: ChannelModel[]) => {
|
||||
const buildSections = (recentChannels: ChannelModel[]) => {
|
||||
const sections = [];
|
||||
if (unreadChannels.length) {
|
||||
sections.push({
|
||||
...sectionNames.unreads,
|
||||
data: unreadChannels,
|
||||
});
|
||||
}
|
||||
|
||||
if (recentChannels.length) {
|
||||
sections.push({
|
||||
...sectionNames.recent,
|
||||
|
|
@ -58,10 +46,10 @@ const buildSections = (unreadChannels: ChannelModel[], recentChannels: ChannelMo
|
|||
return sections;
|
||||
};
|
||||
|
||||
const UnfilteredList = ({close, keyboardHeight, recentChannels, showTeamName, unreadChannels, testID}: Props) => {
|
||||
const UnfilteredList = ({close, keyboardHeight, recentChannels, showTeamName, testID}: Props) => {
|
||||
const intl = useIntl();
|
||||
const serverUrl = useServerUrl();
|
||||
const [sections, setSections] = useState(buildSections(unreadChannels, recentChannels));
|
||||
const [sections, setSections] = useState(buildSections(recentChannels));
|
||||
const sectionListStyle = useMemo(() => ({paddingBottom: keyboardHeight}), [keyboardHeight]);
|
||||
|
||||
const onPress = useCallback(async (channelId: string) => {
|
||||
|
|
@ -86,8 +74,8 @@ const UnfilteredList = ({close, keyboardHeight, recentChannels, showTeamName, un
|
|||
}, [onPress, showTeamName]);
|
||||
|
||||
useEffect(() => {
|
||||
setSections(buildSections(unreadChannels, recentChannels));
|
||||
}, [unreadChannels, recentChannels]);
|
||||
setSections(buildSections(recentChannels));
|
||||
}, [recentChannels]);
|
||||
|
||||
return (
|
||||
<Animated.View
|
||||
|
|
|
|||
Loading…
Reference in a new issue