forked from Ivasoft/mattermost-mobile
Do not set new line message indicator on own posts (#6206)
This commit is contained in:
29
app/components/post_list/index.ts
Normal file
29
app/components/post_list/index.ts
Normal file
@@ -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)));
|
||||
@@ -28,6 +28,7 @@ type Props = {
|
||||
channelId: string;
|
||||
contentContainerStyle?: StyleProp<ViewStyle>;
|
||||
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(() => {
|
||||
@@ -20,10 +20,7 @@ import type PostModel from '@typings/database/models/servers/post';
|
||||
type Props = {
|
||||
channelId: string;
|
||||
contentContainerStyle?: StyleProp<ViewStyle>;
|
||||
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 = ({
|
||||
<PostList
|
||||
channelId={channelId}
|
||||
contentContainerStyle={contentContainerStyle}
|
||||
currentTimezone={currentTimezone}
|
||||
currentUsername={currentUsername}
|
||||
isCRTEnabled={isCRTEnabled}
|
||||
isTimezoneEnabled={isTimezoneEnabled}
|
||||
footer={intro}
|
||||
lastViewedAt={lastViewedAt}
|
||||
location={Screens.CHANNEL}
|
||||
|
||||
@@ -14,26 +14,18 @@ import {getPreferenceAsBool} from '@helpers/api/preference';
|
||||
import {observeMyChannel} from '@queries/servers/channel';
|
||||
import {queryPostsBetween, queryPostsInChannel} from '@queries/servers/post';
|
||||
import {queryPreferencesByCategoryAndName} from '@queries/servers/preference';
|
||||
import {observeConfigBooleanValue} from '@queries/servers/system';
|
||||
import {observeIsCRTEnabled} from '@queries/servers/thread';
|
||||
import {observeCurrentUser} from '@queries/servers/user';
|
||||
import {getTimezone} from '@utils/user';
|
||||
|
||||
import ChannelPostList from './channel_post_list';
|
||||
|
||||
import type {WithDatabaseArgs} from '@typings/database/database';
|
||||
|
||||
const enhanced = withObservables(['channelId', 'forceQueryAfterAppState'], ({database, channelId}: {channelId: string; forceQueryAfterAppState: AppStateStatus} & WithDatabaseArgs) => {
|
||||
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)),
|
||||
),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<PostModel[]>([]);
|
||||
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}
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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)),
|
||||
),
|
||||
|
||||
@@ -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 = ({
|
||||
<PostList
|
||||
channelId={rootPost.channelId}
|
||||
contentContainerStyle={styles.container}
|
||||
currentTimezone={currentTimezone}
|
||||
currentUsername={currentUsername}
|
||||
isTimezoneEnabled={isTimezoneEnabled}
|
||||
lastViewedAt={lastViewedAt}
|
||||
location={Screens.THREAD}
|
||||
nativeID={nativeID}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import {Post} from '@constants';
|
||||
import {isFromWebhook} from '@utils/post';
|
||||
|
||||
import type PostModel from '@typings/database/models/servers/post';
|
||||
|
||||
@@ -170,7 +171,7 @@ function isJoinLeavePostForUsername(post: PostModel, currentUsername: string): b
|
||||
|
||||
// are we going to do something with selectedPostId as in v1?
|
||||
export function selectOrderedPosts(
|
||||
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) {
|
||||
if (posts.length === 0) {
|
||||
return [];
|
||||
@@ -218,6 +219,7 @@ export function selectOrderedPosts(
|
||||
if (
|
||||
lastViewedAt &&
|
||||
post.createAt > 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user