forked from Ivasoft/mattermost-mobile
Fix potential crash by accessing the team directly from another model (#6813)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import DatabaseManager from '@database/manager';
|
||||
import {prepareDeleteTeam, getMyTeamById, queryTeamSearchHistoryByTeamId, removeTeamFromTeamHistory, getTeamSearchHistoryById} from '@queries/servers/team';
|
||||
import {prepareDeleteTeam, getMyTeamById, queryTeamSearchHistoryByTeamId, removeTeamFromTeamHistory, getTeamSearchHistoryById, getTeamById} from '@queries/servers/team';
|
||||
import {logError} from '@utils/log';
|
||||
|
||||
import type Model from '@nozbe/watermelondb/Model';
|
||||
@@ -12,7 +12,7 @@ export async function removeUserFromTeam(serverUrl: string, teamId: string) {
|
||||
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
||||
const myTeam = await getMyTeamById(database, teamId);
|
||||
if (myTeam) {
|
||||
const team = await myTeam.team.fetch();
|
||||
const team = await getTeamById(database, myTeam.id);
|
||||
if (!team) {
|
||||
throw new Error('Team not found');
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
import withObservables from '@nozbe/with-observables';
|
||||
import {switchMap, of as of$} from 'rxjs';
|
||||
|
||||
import {observeTeam} from '@queries/servers/team';
|
||||
|
||||
import ChannelInfo from './channel_info';
|
||||
|
||||
import type PostModel from '@typings/database/models/servers/post';
|
||||
@@ -16,7 +18,7 @@ const enhance = withObservables(['post'], ({post}: {post: PostModel}) => {
|
||||
switchMap((chan) => (chan ? of$(chan.displayName) : '')),
|
||||
),
|
||||
teamName: channel.pipe(
|
||||
switchMap((chan) => (chan && chan.teamId ? chan.team.observe() : of$(null))),
|
||||
switchMap((chan) => (chan && chan.teamId ? observeTeam(post.database, chan.teamId) : of$(null))),
|
||||
switchMap((team) => of$(team?.displayName || null)),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import {combineLatestWith, map, switchMap, distinctUntilChanged} from 'rxjs/oper
|
||||
|
||||
import {observeAllMyChannelNotifyProps, queryMyChannelsByTeam} from '@queries/servers/channel';
|
||||
import {observeCurrentTeamId} from '@queries/servers/system';
|
||||
import {observeMentionCount} from '@queries/servers/team';
|
||||
import {observeMentionCount, observeTeam} from '@queries/servers/team';
|
||||
|
||||
import TeamItem from './team_item';
|
||||
|
||||
@@ -38,7 +38,7 @@ const enhance = withObservables(['myTeam'], ({myTeam, database}: WithTeamsArgs)
|
||||
|
||||
return {
|
||||
selected,
|
||||
team: myTeam.team.observe(),
|
||||
team: observeTeam(database, myTeam.id),
|
||||
mentionCount: observeMentionCount(database, myTeam.id, false),
|
||||
hasUnreads,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user