* MM-39710: saved posts screen and DB - Adds ids of saved posts to the systems table, as we do with recent mentions. - Adds a new remote action to fetch saved posts (getFlaggedPosts). - Adds a new screen to display those in a mobile. - Displays saved posts in the tablet view next to profile card. * Uses Preferences instead of System table Renames to saved posts wherever possible * Adds text to localization file * Fixes fetching/saving saved posts * Refactor mini post to components folder * Fixes hooks dependencies according to review * Removes unnecessary 'withObservables' * Small refactor * Satisfies linter * Adds empty state And fixes empty state icon to be theme sensitive. Both recent_mentions and saved_posts. * Fixes empty screen's alignment * Add missing preference * add missing translation strings * remove unused database type definition * Fetch newly saved post * Fix return type for client.getSavedPosts * Remove usage of lodash compose * Rename get remote actions to fetch * Include close button for savedPost modal * fix tablet view for SavePosts and use lottie loading indicator * Render post with content for save posts and recent mentions * post list viewable items type definition * Add layout width to post content for saved post screen * Use PostWithChannel and viewableItems for saved posts and recent mentions * Layout margin of 20 * openGraphImage margin * Fix openGraphImage display Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {fetchPostById} from '@actions/remote/post';
|
|
import {Preferences} from '@constants';
|
|
import DatabaseManager from '@database/manager';
|
|
import {queryPostById} from '@queries/servers/post';
|
|
import {deletePreferences} from '@queries/servers/preference';
|
|
|
|
export async function handlePreferenceChangedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
|
|
const operator = DatabaseManager.serverDatabases[serverUrl].operator;
|
|
if (!operator) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const preference = JSON.parse(msg.data.preference) as PreferenceType;
|
|
handleSavePostAdded(serverUrl, [preference]);
|
|
if (operator) {
|
|
operator.handlePreferences({
|
|
prepareRecordsOnly: false,
|
|
preferences: [preference],
|
|
});
|
|
}
|
|
} catch (error) {
|
|
// Do nothing
|
|
}
|
|
}
|
|
|
|
export async function handlePreferencesChangedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
|
|
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
|
if (!operator) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const preferences = JSON.parse(msg.data.preferences) as PreferenceType[];
|
|
handleSavePostAdded(serverUrl, preferences);
|
|
if (operator) {
|
|
operator.handlePreferences({
|
|
prepareRecordsOnly: false,
|
|
preferences,
|
|
});
|
|
}
|
|
} catch (error) {
|
|
// Do nothing
|
|
}
|
|
}
|
|
|
|
export async function handlePreferencesDeletedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
|
|
const database = DatabaseManager.serverDatabases[serverUrl];
|
|
if (!database) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const preferences = JSON.parse(msg.data.preferences) as PreferenceType[];
|
|
deletePreferences(database, preferences);
|
|
} catch {
|
|
// Do nothing
|
|
}
|
|
}
|
|
|
|
// If preferences include new save posts we fetch them
|
|
async function handleSavePostAdded(serverUrl: string, preferences: PreferenceType[]) {
|
|
const database = DatabaseManager.serverDatabases[serverUrl]?.database;
|
|
if (!database) {
|
|
return;
|
|
}
|
|
|
|
const savedPosts = preferences.filter((p) => p.category === Preferences.CATEGORY_SAVED_POST);
|
|
for await (const saved of savedPosts) {
|
|
const post = await queryPostById(database, saved.name);
|
|
if (!post) {
|
|
await fetchPostById(serverUrl, saved.name, false);
|
|
}
|
|
}
|
|
}
|