From 43c43e50d4dd7aaacc5469b0f0775f419020fd02 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 3 May 2022 14:43:55 -0400 Subject: [PATCH] Do not set new line message indicator on own posts (#6206) --- app/components/post_list/index.ts | 29 +++++++++++++++++++ .../post_list/{index.tsx => post_list.tsx} | 4 ++- .../channel_post_list/channel_post_list.tsx | 10 ++----- .../channel/channel_post_list/index.ts | 8 ----- .../home/recent_mentions/recent_mentions.tsx | 2 +- app/screens/permalink/permalink.tsx | 6 +--- app/screens/saved_posts/saved_posts.tsx | 2 +- app/screens/thread/thread_post_list/index.ts | 8 ----- .../thread_post_list/thread_post_list.tsx | 10 ++----- app/utils/post_list/index.ts | 8 +++-- 10 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 app/components/post_list/index.ts rename app/components/post_list/{index.tsx => post_list.tsx} (98%) diff --git a/app/components/post_list/index.ts b/app/components/post_list/index.ts new file mode 100644 index 0000000000..601a478adb --- /dev/null +++ b/app/components/post_list/index.ts @@ -0,0 +1,29 @@ +// 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 React from 'react'; +import {of as of$} from 'rxjs'; +import {switchMap} from 'rxjs/operators'; + +import {observeConfigBooleanValue} from '@queries/servers/system'; +import {observeCurrentUser} from '@queries/servers/user'; +import {getTimezone} from '@utils/user'; + +import PostList from './post_list'; + +import type {WithDatabaseArgs} from '@typings/database/database'; + +const enhanced = withObservables([], ({database}: WithDatabaseArgs) => { + const currentUser = observeCurrentUser(database); + + return { + isTimezoneEnabled: observeConfigBooleanValue(database, 'ExperimentalTimezone'), + currentTimezone: currentUser.pipe((switchMap((user) => of$(getTimezone(user?.timezone || null))))), + currentUserId: currentUser.pipe((switchMap((user) => of$(user?.id)))), + currentUsername: currentUser.pipe((switchMap((user) => of$(user?.username)))), + }; +}); + +export default React.memo(withDatabase(enhanced(PostList))); diff --git a/app/components/post_list/index.tsx b/app/components/post_list/post_list.tsx similarity index 98% rename from app/components/post_list/index.tsx rename to app/components/post_list/post_list.tsx index 8920caeab8..672af5cfdf 100644 --- a/app/components/post_list/index.tsx +++ b/app/components/post_list/post_list.tsx @@ -28,6 +28,7 @@ type Props = { channelId: string; contentContainerStyle?: StyleProp; currentTimezone: string | null; + currentUserId: string; currentUsername: string; highlightedId?: PostModel['id']; highlightPinnedOrSaved?: boolean; @@ -79,6 +80,7 @@ const PostList = ({ channelId, contentContainerStyle, currentTimezone, + currentUserId, currentUsername, footer, highlightedId, @@ -106,7 +108,7 @@ const PostList = ({ const theme = useTheme(); const serverUrl = useServerUrl(); const orderedPosts = useMemo(() => { - return preparePostList(posts, lastViewedAt, showNewMessageLine, currentUsername, shouldShowJoinLeaveMessages, isTimezoneEnabled, currentTimezone, location === Screens.THREAD); + return preparePostList(posts, lastViewedAt, showNewMessageLine, currentUserId, currentUsername, shouldShowJoinLeaveMessages, isTimezoneEnabled, currentTimezone, location === Screens.THREAD); }, [posts, lastViewedAt, showNewMessageLine, currentTimezone, currentUsername, shouldShowJoinLeaveMessages, isTimezoneEnabled, location]); const initialIndex = useMemo(() => { diff --git a/app/screens/channel/channel_post_list/channel_post_list.tsx b/app/screens/channel/channel_post_list/channel_post_list.tsx index 151b638156..58912261f9 100644 --- a/app/screens/channel/channel_post_list/channel_post_list.tsx +++ b/app/screens/channel/channel_post_list/channel_post_list.tsx @@ -20,10 +20,7 @@ import type PostModel from '@typings/database/models/servers/post'; type Props = { channelId: string; contentContainerStyle?: StyleProp; - currentTimezone: string | null; - currentUsername: string; isCRTEnabled: boolean; - isTimezoneEnabled: boolean; lastViewedAt: number; nativeID: string; posts: PostModel[]; @@ -36,8 +33,8 @@ const styles = StyleSheet.create({ }); const ChannelPostList = ({ - channelId, contentContainerStyle, currentTimezone, currentUsername, - isCRTEnabled, isTimezoneEnabled, lastViewedAt, nativeID, posts, shouldShowJoinLeaveMessages, + channelId, contentContainerStyle, isCRTEnabled, + lastViewedAt, nativeID, posts, shouldShowJoinLeaveMessages, }: Props) => { const isTablet = useIsTablet(); const serverUrl = useServerUrl(); @@ -60,10 +57,7 @@ const ChannelPostList = ({ { - const currentUser = observeCurrentUser(database); - const isCRTEnabledObserver = observeIsCRTEnabled(database); const postsInChannelObserver = queryPostsInChannel(database, channelId).observeWithColumns(['earliest', 'latest']); return { - currentTimezone: currentUser.pipe((switchMap((user) => of$(getTimezone(user?.timezone || null))))), - currentUsername: currentUser.pipe((switchMap((user) => of$(user?.username)))), isCRTEnabled: isCRTEnabledObserver, - isTimezoneEnabled: observeConfigBooleanValue(database, 'ExperimentalTimezone'), lastViewedAt: observeMyChannel(database, channelId).pipe( switchMap((myChannel) => of$(myChannel?.viewedAt)), ), diff --git a/app/screens/home/recent_mentions/recent_mentions.tsx b/app/screens/home/recent_mentions/recent_mentions.tsx index 12a7bb8d5f..bc63915037 100644 --- a/app/screens/home/recent_mentions/recent_mentions.tsx +++ b/app/screens/home/recent_mentions/recent_mentions.tsx @@ -75,7 +75,7 @@ const RecentMentionsScreen = ({mentions, currentTimezone, isTimezoneEnabled}: Pr const paddingTop = useMemo(() => ({paddingTop: scrollPaddingTop}), [scrollPaddingTop]); - const posts = useMemo(() => selectOrderedPosts(mentions, 0, false, '', false, isTimezoneEnabled, currentTimezone, false).reverse(), [mentions]); + const posts = useMemo(() => selectOrderedPosts(mentions, 0, false, '', '', false, isTimezoneEnabled, currentTimezone, false).reverse(), [mentions]); const handleRefresh = useCallback(async () => { setRefreshing(true); diff --git a/app/screens/permalink/permalink.tsx b/app/screens/permalink/permalink.tsx index 225f1c6414..8dbc76c6e0 100644 --- a/app/screens/permalink/permalink.tsx +++ b/app/screens/permalink/permalink.tsx @@ -23,7 +23,6 @@ import {preventDoubleTap} from '@utils/tap'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; type Props = { - currentUsername: UserProfile['username']; postId: PostModel['id']; channel?: ChannelModel; } @@ -115,7 +114,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({ }, })); -function Permalink({channel, postId, currentUsername}: Props) { +function Permalink({channel, postId}: Props) { const [posts, setPosts] = useState([]); const [loading, setLoading] = useState(true); const theme = useTheme(); @@ -201,10 +200,7 @@ function Permalink({channel, postId, currentUsername}: Props) { posts={posts} location={Screens.PERMALINK} lastViewedAt={0} - isTimezoneEnabled={false} shouldShowJoinLeaveMessages={false} - currentTimezone={null} - currentUsername={currentUsername} channelId={channel!.id} testID='permalink.post_list' nativeID={Screens.PERMALINK} diff --git a/app/screens/saved_posts/saved_posts.tsx b/app/screens/saved_posts/saved_posts.tsx index ae4f9701ab..4d652f056d 100644 --- a/app/screens/saved_posts/saved_posts.tsx +++ b/app/screens/saved_posts/saved_posts.tsx @@ -67,7 +67,7 @@ function SavedMessages({ const theme = useTheme(); const serverUrl = useServerUrl(); - const data = useMemo(() => selectOrderedPosts(posts, 0, false, '', false, isTimezoneEnabled, currentTimezone, false).reverse(), [posts]); + const data = useMemo(() => selectOrderedPosts(posts, 0, false, '', '', false, isTimezoneEnabled, currentTimezone, false).reverse(), [posts]); useEffect(() => { fetchSavedPosts(serverUrl).finally(() => { diff --git a/app/screens/thread/thread_post_list/index.ts b/app/screens/thread/thread_post_list/index.ts index 8e9956d258..bdba98a2c7 100644 --- a/app/screens/thread/thread_post_list/index.ts +++ b/app/screens/thread/thread_post_list/index.ts @@ -9,10 +9,7 @@ import {switchMap} from 'rxjs/operators'; import {observeMyChannel} from '@queries/servers/channel'; import {queryPostsChunk, queryPostsInThread} from '@queries/servers/post'; -import {observeConfigBooleanValue} from '@queries/servers/system'; import {observeIsCRTEnabled} from '@queries/servers/thread'; -import {observeCurrentUser} from '@queries/servers/user'; -import {getTimezone} from '@utils/user'; import ThreadPostList from './thread_post_list'; @@ -25,13 +22,8 @@ type Props = WithDatabaseArgs & { }; const enhanced = withObservables(['forceQueryAfterAppState', 'rootPost'], ({database, rootPost}: Props) => { - const currentUser = observeCurrentUser(database); - return { - currentTimezone: currentUser.pipe((switchMap((user) => of$(getTimezone(user?.timezone || null))))), - currentUsername: currentUser.pipe((switchMap((user) => of$(user?.username || '')))), isCRTEnabled: observeIsCRTEnabled(database), - isTimezoneEnabled: observeConfigBooleanValue(database, 'ExperimentalTimezone'), lastViewedAt: observeMyChannel(database, rootPost.channelId).pipe( switchMap((myChannel) => of$(myChannel?.viewedAt)), ), diff --git a/app/screens/thread/thread_post_list/thread_post_list.tsx b/app/screens/thread/thread_post_list/thread_post_list.tsx index df8fb4a940..986bb1a232 100644 --- a/app/screens/thread/thread_post_list/thread_post_list.tsx +++ b/app/screens/thread/thread_post_list/thread_post_list.tsx @@ -14,10 +14,7 @@ import {useIsTablet} from '@hooks/device'; import type PostModel from '@typings/database/models/servers/post'; type Props = { - currentTimezone: string | null; - currentUsername: string; isCRTEnabled: boolean; - isTimezoneEnabled: boolean; lastViewedAt: number; nativeID: string; posts: PostModel[]; @@ -34,8 +31,8 @@ const styles = StyleSheet.create({ }); const ThreadPostList = ({ - currentTimezone, currentUsername, - isCRTEnabled, isTimezoneEnabled, lastViewedAt, nativeID, posts, rootPost, teamId, + isCRTEnabled, lastViewedAt, + nativeID, posts, rootPost, teamId, }: Props) => { const isTablet = useIsTablet(); const serverUrl = useServerUrl(); @@ -57,9 +54,6 @@ const ThreadPostList = ({ lastViewedAt && + (post.userId !== currentUserId || isFromWebhook(post)) && !addedNewMessagesIndicator && indicateNewMessages ) { @@ -359,9 +361,9 @@ export function isThreadOverview(item: string) { } export function preparePostList( - posts: PostModel[], lastViewedAt: number, indicateNewMessages: boolean, currentUsername: string, showJoinLeave: boolean, + posts: PostModel[], lastViewedAt: number, indicateNewMessages: boolean, currentUserId: string, currentUsername: string, showJoinLeave: boolean, timezoneEnabled: boolean, currentTimezone: string | null, isThreadScreen = false) { - const orderedPosts = selectOrderedPosts(posts, lastViewedAt, indicateNewMessages, currentUsername, showJoinLeave, timezoneEnabled, currentTimezone, isThreadScreen); + const orderedPosts = selectOrderedPosts(posts, lastViewedAt, indicateNewMessages, currentUserId, currentUsername, showJoinLeave, timezoneEnabled, currentTimezone, isThreadScreen); return combineUserActivityPosts(orderedPosts); }