* Permalink initial commit * Fixes: 10 items per page * MM-40203: permalink modal viewer for mentions Is triggered by pressing on an item in mentions, and shows posts around that item, including the item in a modal. * Adds previously deleted file * address feedback * Move showPermalink as a remote action * address more feedback * fetchPostsAround to only return PostModel * Attempt to autoscroll to highlighted item * Permalink to not highlight saved and pinned posts * Add bottom margin using insets to permalink screen * Use lottie loading indicator * Switch to channel * Missing translation string Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {fetchMyChannelsForTeam} from '@actions/remote/channel';
|
|
import DatabaseManager from '@database/manager';
|
|
import {queryCommonSystemValues} from '@queries/servers/system';
|
|
import {queryTeamById, queryTeamByName} from '@queries/servers/team';
|
|
import {permalinkBadTeam} from '@utils/draft';
|
|
import {displayPermalink} from '@utils/permalink';
|
|
import {PERMALINK_GENERIC_TEAM_NAME_REDIRECT} from '@utils/url';
|
|
|
|
import type TeamModel from '@typings/database/models/servers/team';
|
|
import type {IntlShape} from 'react-intl';
|
|
|
|
export const showPermalink = async (serverUrl: string, teamName: string, postId: string, intl: IntlShape, openAsPermalink = true) => {
|
|
const database = DatabaseManager.serverDatabases[serverUrl]?.database;
|
|
if (!database) {
|
|
return {error: `${serverUrl} database not found`};
|
|
}
|
|
|
|
try {
|
|
let name = teamName;
|
|
let team: TeamModel | undefined;
|
|
const system = await queryCommonSystemValues(database);
|
|
if (!name || name === PERMALINK_GENERIC_TEAM_NAME_REDIRECT) {
|
|
team = await queryTeamById(database, system.currentTeamId);
|
|
if (team) {
|
|
name = team.name;
|
|
}
|
|
}
|
|
|
|
if (!team) {
|
|
team = await queryTeamByName(database, name);
|
|
if (!team) {
|
|
permalinkBadTeam(intl);
|
|
return {error: 'Bad Permalink team'};
|
|
}
|
|
}
|
|
|
|
if (team.id !== system.currentTeamId) {
|
|
const result = await fetchMyChannelsForTeam(serverUrl, team.id, true, 0, false, true);
|
|
if (result.error) {
|
|
return {error: result.error};
|
|
}
|
|
}
|
|
|
|
await displayPermalink(team.name, postId, openAsPermalink);
|
|
|
|
return {error: undefined};
|
|
} catch (error) {
|
|
return {error};
|
|
}
|
|
};
|