forked from Ivasoft/mattermost-mobile
Fix links to channels closing the channel (#6446)
This commit is contained in:
committed by
GitHub
parent
330dc0b9ad
commit
82c514013c
@@ -19,7 +19,7 @@ import {getCommonSystemValues, getConfig, getCurrentTeamId, getCurrentUserId, ge
|
||||
import {prepareMyTeams, getNthLastChannelFromTeam, getMyTeamById, getTeamById, getTeamByName, queryMyTeams} from '@queries/servers/team';
|
||||
import {getCurrentUser} from '@queries/servers/user';
|
||||
import EphemeralStore from '@store/ephemeral_store';
|
||||
import {generateChannelNameFromDisplayName, getDirectChannelName, isDMorGM} from '@utils/channel';
|
||||
import {generateChannelNameFromDisplayName, getDirectChannelName, isArchived, isDMorGM} from '@utils/channel';
|
||||
import {isTablet} from '@utils/helpers';
|
||||
import {logError, logInfo} from '@utils/log';
|
||||
import {showMuteChannelSnackbar} from '@utils/snack_bar';
|
||||
@@ -684,20 +684,22 @@ export async function switchToChannelByName(serverUrl: string, channelName: stri
|
||||
return {error: 'Could not fetch team member'};
|
||||
}
|
||||
|
||||
let isArchived = false;
|
||||
const chReq = await fetchChannelByName(serverUrl, team.id, channelName, true);
|
||||
if (chReq.error) {
|
||||
errorHandler(intl);
|
||||
return {error: chReq.error};
|
||||
let channel: Channel | ChannelModel | undefined = await getChannelByName(database, team.id, channelName);
|
||||
if (!channel) {
|
||||
const chReq = await fetchChannelByName(serverUrl, team.id, channelName, true);
|
||||
if (chReq.error) {
|
||||
errorHandler(intl);
|
||||
return {error: chReq.error};
|
||||
}
|
||||
channel = chReq.channel;
|
||||
}
|
||||
const channel = chReq.channel;
|
||||
|
||||
if (!channel) {
|
||||
errorHandler(intl);
|
||||
return {error: 'Could not fetch channel'};
|
||||
}
|
||||
|
||||
isArchived = channel.delete_at > 0;
|
||||
if (isArchived && system.config.ExperimentalViewArchivedChannels !== 'true') {
|
||||
if (isArchived(channel) && system.config.ExperimentalViewArchivedChannels !== 'true') {
|
||||
errorHandler(intl);
|
||||
return {error: 'Channel is archived'};
|
||||
}
|
||||
@@ -705,13 +707,14 @@ export async function switchToChannelByName(serverUrl: string, channelName: stri
|
||||
myChannel = await getMyChannel(database, channel.id);
|
||||
|
||||
if (!myChannel) {
|
||||
const req = await fetchMyChannel(serverUrl, channel.team_id || team.id, channel.id, true);
|
||||
const channelTeamId = 'team_id' in channel ? channel.team_id : channel.teamId;
|
||||
const req = await fetchMyChannel(serverUrl, channelTeamId || team.id, channel.id, true);
|
||||
myChannel = req.memberships?.[0];
|
||||
}
|
||||
|
||||
if (!myChannel) {
|
||||
if (channel.type === General.PRIVATE_CHANNEL) {
|
||||
const displayName = channel.display_name;
|
||||
const displayName = 'display_name' in channel ? channel.display_name : channel.displayName;
|
||||
const {join} = await privateChannelJoinPrompt(displayName, intl);
|
||||
if (!join) {
|
||||
if (joinedNewTeam) {
|
||||
@@ -755,7 +758,8 @@ export async function switchToChannelByName(serverUrl: string, channelName: stri
|
||||
);
|
||||
}
|
||||
|
||||
if (!(myChannel instanceof Model)) {
|
||||
// We are checking both, so this may become an issue
|
||||
if (!(myChannel instanceof Model) && !(channel instanceof Model)) {
|
||||
modelPromises.push(...await prepareMyChannelsForTeam(operator, team.id, [channel], [myChannel]));
|
||||
}
|
||||
|
||||
@@ -814,7 +818,7 @@ export async function createDirectChannel(serverUrl: string, userId: string, dis
|
||||
}
|
||||
|
||||
const channelName = getDirectChannelName(currentUser.id, userId);
|
||||
const channel = await getChannelByName(database, channelName);
|
||||
const channel = await getChannelByName(database, '', channelName);
|
||||
if (channel) {
|
||||
return {data: channel.toApi()};
|
||||
}
|
||||
@@ -906,7 +910,7 @@ export async function makeDirectChannel(serverUrl: string, userId: string, displ
|
||||
try {
|
||||
const currentUserId = await getCurrentUserId(operator.database);
|
||||
const channelName = getDirectChannelName(userId, currentUserId);
|
||||
let channel: Channel|ChannelModel|undefined = await getChannelByName(operator.database, channelName);
|
||||
let channel: Channel|ChannelModel|undefined = await getChannelByName(operator.database, '', channelName);
|
||||
let result: {data?: Channel|ChannelModel; error?: any};
|
||||
if (channel) {
|
||||
result = {data: channel};
|
||||
|
||||
@@ -1320,7 +1320,7 @@ export class AppCommandParser {
|
||||
}
|
||||
case AppFieldTypes.CHANNEL: {
|
||||
const getFieldChannel = async (channelName: string) => {
|
||||
let channel: ChannelModel | Channel | undefined = await getChannelByName(this.database, channelName);
|
||||
let channel: ChannelModel | Channel | undefined = await getChannelByName(this.database, this.teamID, channelName);
|
||||
if (!channel) {
|
||||
const res = await fetchChannelByName(this.serverUrl, this.teamID, channelName);
|
||||
if ('error' in res) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import SlideUpPanelItem, {ITEM_HEIGHT} from '@components/slide_up_panel_item';
|
||||
import DeepLinkTypes from '@constants/deep_linking';
|
||||
import {useServerUrl} from '@context/server';
|
||||
import {useTheme} from '@context/theme';
|
||||
import {bottomSheet, dismissAllModals, dismissBottomSheet, popToRoot} from '@screens/navigation';
|
||||
import {bottomSheet, dismissBottomSheet} from '@screens/navigation';
|
||||
import {errorBadChannel} from '@utils/draft';
|
||||
import {bottomSheetSnapPoint} from '@utils/helpers';
|
||||
import {preventDoubleTap} from '@utils/tap';
|
||||
@@ -69,11 +69,7 @@ const MarkdownLink = ({children, experimentalNormalizeMarkdownLinks, href, siteU
|
||||
|
||||
if (match && match.data?.teamName) {
|
||||
if (match.type === DeepLinkTypes.CHANNEL) {
|
||||
const result = await switchToChannelByName(serverUrl, (match?.data as DeepLinkChannel).channelName, match.data?.teamName, errorBadChannel, intl);
|
||||
if (!result.error) {
|
||||
await dismissAllModals();
|
||||
await popToRoot();
|
||||
}
|
||||
await switchToChannelByName(serverUrl, (match?.data as DeepLinkChannel).channelName, match.data?.teamName, errorBadChannel, intl);
|
||||
} else if (match.type === DeepLinkTypes.PERMALINK) {
|
||||
showPermalink(serverUrl, match.data.teamName, (match.data as DeepLinkPermalink).postId, intl);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import type MyChannelModel from '@typings/database/models/servers/my_channel';
|
||||
import type MyChannelSettingsModel from '@typings/database/models/servers/my_channel_settings';
|
||||
import type UserModel from '@typings/database/models/servers/user';
|
||||
|
||||
const {SERVER: {CHANNEL, MY_CHANNEL, CHANNEL_MEMBERSHIP, MY_CHANNEL_SETTINGS, CHANNEL_INFO, USER}} = MM_TABLES;
|
||||
const {SERVER: {CHANNEL, MY_CHANNEL, CHANNEL_MEMBERSHIP, MY_CHANNEL_SETTINGS, CHANNEL_INFO, USER, TEAM}} = MM_TABLES;
|
||||
|
||||
export function prepareMissingChannelsForAllTeams(operator: ServerDataOperator, channels: Channel[], channelMembers: ChannelMembership[], isCRTEnabled?: boolean): Array<Promise<Model[]>> {
|
||||
const channelInfos: ChannelInfo[] = [];
|
||||
@@ -211,8 +211,8 @@ export const observeChannel = (database: Database, channelId: string) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getChannelByName = async (database: Database, channelName: string) => {
|
||||
const channels = await database.get<ChannelModel>(CHANNEL).query(Q.where('name', channelName)).fetch();
|
||||
export const getChannelByName = async (database: Database, teamId: string, channelName: string) => {
|
||||
const channels = await database.get<ChannelModel>(CHANNEL).query(Q.on(TEAM, 'id', teamId), Q.where('name', channelName)).fetch();
|
||||
|
||||
// Check done to force types
|
||||
if (channels.length) {
|
||||
|
||||
@@ -28,6 +28,11 @@ export function isDMorGM(channel: Channel | ChannelModel): boolean {
|
||||
return directTypes.includes(channel.type);
|
||||
}
|
||||
|
||||
export function isArchived(channel: Channel | ChannelModel): boolean {
|
||||
const deleteAt = 'delete_at' in channel ? channel.delete_at : channel.deleteAt;
|
||||
return deleteAt > 0;
|
||||
}
|
||||
|
||||
export function selectDefaultChannelForTeam<T extends Channel|ChannelModel>(channels: T[], memberships: ChannelMembership[], teamId: string, roles?: Role[], locale = DEFAULT_LOCALE) {
|
||||
let channel: T|undefined;
|
||||
let canIJoinPublicChannelsInTeam = false;
|
||||
|
||||
4
index.ts
4
index.ts
@@ -102,10 +102,6 @@ function screenDidDisappearListener({componentId}: ComponentDidDisappearEvent) {
|
||||
DeviceEventEmitter.emit(Events.PAUSE_KEYBOARD_TRACKING_VIEW, false);
|
||||
}
|
||||
|
||||
if (NavigationStore.getNavigationTopComponentId() === componentId) {
|
||||
NavigationStore.removeNavigationComponentId(componentId);
|
||||
}
|
||||
|
||||
if (NavigationStore.getNavigationTopComponentId() === Screens.HOME) {
|
||||
DeviceEventEmitter.emit(Events.TAB_BAR_VISIBLE, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user