forked from Ivasoft/mattermost-mobile
[Gekidou] [MM-43973] Thread footer for recent mentions (#6225)
* Displaying thread footer * Participants can be empty * Update thread.ts
This commit is contained in:
committed by
GitHub
parent
83c2cfff97
commit
1760b75dbf
@@ -5,6 +5,7 @@ import {SYSTEM_IDENTIFIERS} from '@constants/database';
|
||||
import DatabaseManager from '@database/manager';
|
||||
import NetworkManager from '@managers/network_manager';
|
||||
import {prepareMissingChannelsForAllTeams} from '@queries/servers/channel';
|
||||
import {getIsCRTEnabled, prepareThreadsFromReceivedPosts} from '@queries/servers/thread';
|
||||
import {getCurrentUser} from '@queries/servers/user';
|
||||
import {processPostsFetched} from '@utils/post';
|
||||
|
||||
@@ -66,6 +67,11 @@ export async function fetchRecentMentions(serverUrl: string): Promise<PostSearch
|
||||
}));
|
||||
|
||||
if (postsArray.length) {
|
||||
const isCRTEnabled = await getIsCRTEnabled(operator.database);
|
||||
if (isCRTEnabled) {
|
||||
promises.push(prepareThreadsFromReceivedPosts(operator, postsArray));
|
||||
}
|
||||
|
||||
const {authors} = await fetchPostAuthors(serverUrl, postsArray, true);
|
||||
const {channels, channelMemberships} = await fetchMissingChannelsFromPosts(serverUrl, postsArray, true);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import {ActionType, Events, Screens} from '@constants';
|
||||
import DatabaseManager from '@database/manager';
|
||||
import {getChannelById, getMyChannel} from '@queries/servers/channel';
|
||||
import {getPostById} from '@queries/servers/post';
|
||||
import {getCurrentChannelId, getCurrentUserId} from '@queries/servers/system';
|
||||
import {getCurrentChannelId, getCurrentTeamId, getCurrentUserId} from '@queries/servers/system';
|
||||
import {getIsCRTEnabled} from '@queries/servers/thread';
|
||||
import EphemeralStore from '@store/ephemeral_store';
|
||||
import {isTablet} from '@utils/helpers';
|
||||
@@ -239,7 +239,11 @@ export async function handlePostDeleted(serverUrl: string, msg: WebSocketMessage
|
||||
|
||||
const channel = await getChannelById(database, post.channel_id);
|
||||
if (channel) {
|
||||
fetchThread(serverUrl, channel.teamId, post.root_id);
|
||||
let {teamId} = channel;
|
||||
if (!teamId) {
|
||||
teamId = await getCurrentTeamId(database); // In case of DM/GM
|
||||
}
|
||||
fetchThread(serverUrl, teamId, post.root_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
app/components/post_with_channel_info/index.ts
Normal file
23
app/components/post_with_channel_info/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
|
||||
import withObservables from '@nozbe/with-observables';
|
||||
import compose from 'lodash/fp/compose';
|
||||
|
||||
import {observeIsCRTEnabled} from '@queries/servers/thread';
|
||||
|
||||
import PostWithChannelInfo from './post_with_channel_info';
|
||||
|
||||
import type {WithDatabaseArgs} from '@typings/database/database';
|
||||
|
||||
const enhance = withObservables([], ({database}: WithDatabaseArgs) => {
|
||||
return {
|
||||
isCRTEnabled: observeIsCRTEnabled(database),
|
||||
};
|
||||
});
|
||||
|
||||
export default compose(
|
||||
withDatabase,
|
||||
enhance,
|
||||
)(PostWithChannelInfo);
|
||||
@@ -11,6 +11,7 @@ import ChannelInfo from './channel_info';
|
||||
import type PostModel from '@typings/database/models/servers/post';
|
||||
|
||||
type Props = {
|
||||
isCRTEnabled: boolean;
|
||||
post: PostModel;
|
||||
location: string;
|
||||
}
|
||||
@@ -26,12 +27,13 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
});
|
||||
|
||||
function PostWithChannelInfo({post, location}: Props) {
|
||||
function PostWithChannelInfo({isCRTEnabled, post, location}: Props) {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<ChannelInfo post={post}/>
|
||||
<View style={styles.content}>
|
||||
<Post
|
||||
isCRTEnabled={isCRTEnabled}
|
||||
post={post}
|
||||
location={location}
|
||||
highlightPinnedOrSaved={false}
|
||||
@@ -53,13 +53,16 @@ const ThreadHandler = (superclass: any) => class extends superclass {
|
||||
|
||||
// Let's process the thread data
|
||||
for (const thread of uniqueThreads) {
|
||||
threadsParticipants.push({
|
||||
thread_id: thread.id,
|
||||
participants: (thread.participants || []).map((participant) => ({
|
||||
id: participant.id,
|
||||
// Avoid participants field set as "null" from overriding the existing ones
|
||||
if (Array.isArray(thread.participants)) {
|
||||
threadsParticipants.push({
|
||||
thread_id: thread.id,
|
||||
})),
|
||||
});
|
||||
participants: thread.participants.map((participant) => ({
|
||||
id: participant.id,
|
||||
thread_id: thread.id,
|
||||
})),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Get thread models to be created and updated
|
||||
@@ -106,14 +109,7 @@ const ThreadHandler = (superclass: any) => class extends superclass {
|
||||
handleThreadParticipants = async ({threadsParticipants, prepareRecordsOnly, skipSync = false}: HandleThreadParticipantsArgs): Promise<ThreadParticipantModel[]> => {
|
||||
const batchRecords: ThreadParticipantModel[] = [];
|
||||
|
||||
if (!threadsParticipants?.length) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
'An empty or undefined "threadParticipants" array has been passed to the handleThreadParticipants method',
|
||||
);
|
||||
return [];
|
||||
}
|
||||
|
||||
// NOTE: Participants list can also be an empty array
|
||||
for await (const threadParticipant of threadsParticipants) {
|
||||
const {thread_id, participants} = threadParticipant;
|
||||
const rawValues = getUniqueRawsBy({raws: participants, key: 'id'}) as ThreadParticipant[];
|
||||
|
||||
@@ -129,8 +129,7 @@ const PostOptions = ({
|
||||
);
|
||||
};
|
||||
|
||||
// This fixes opening "post options modal" on top of "thread modal"
|
||||
const additionalSnapPoints = sourceScreen === Screens.THREAD ? 3 : 2;
|
||||
const additionalSnapPoints = 2;
|
||||
|
||||
return (
|
||||
<BottomSheet
|
||||
|
||||
2
types/database/database.d.ts
vendored
2
types/database/database.d.ts
vendored
@@ -98,7 +98,7 @@ export type HandleThreadsArgs = {
|
||||
export type HandleThreadParticipantsArgs = {
|
||||
prepareRecordsOnly: boolean;
|
||||
skipSync?: boolean;
|
||||
threadsParticipants?: ParticipantsPerThread[];
|
||||
threadsParticipants: ParticipantsPerThread[];
|
||||
};
|
||||
|
||||
export type HandleThreadInTeamArgs = {
|
||||
|
||||
Reference in New Issue
Block a user