forked from Ivasoft/mattermost-mobile
Fix issue with missing post headers on threads (#7378)
* Fix issue with missing post headers on threads * Fix lint
This commit is contained in:
committed by
GitHub
parent
0030381a93
commit
20dfb4f406
@@ -65,7 +65,7 @@ type ScrollIndexFailed = {
|
||||
};
|
||||
|
||||
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
||||
const keyExtractor = (item: PostListItem | PostListOtherItem) => (item.type === 'post' ? item.value.id : item.value);
|
||||
const keyExtractor = (item: PostListItem | PostListOtherItem) => (item.type === 'post' ? item.value.currentPost.id : item.value);
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
flex: {
|
||||
@@ -272,7 +272,8 @@ const PostList = ({
|
||||
return (<CombinedUserActivity {...postProps}/>);
|
||||
}
|
||||
default: {
|
||||
const post = item.value;
|
||||
const post = item.value.currentPost;
|
||||
const {isSaved, nextPost, previousPost} = item.value;
|
||||
const skipSaveddHeader = (location === Screens.THREAD && post.id === rootId);
|
||||
const postProps = {
|
||||
appsEnabled,
|
||||
@@ -281,12 +282,12 @@ const PostList = ({
|
||||
isPostAcknowledgementEnabled,
|
||||
highlight: highlightedId === post.id,
|
||||
highlightPinnedOrSaved,
|
||||
isSaved: post.isSaved,
|
||||
isSaved,
|
||||
key: post.id,
|
||||
location,
|
||||
nextPost: post.nextPost,
|
||||
nextPost,
|
||||
post,
|
||||
previousPost: post.previousPost,
|
||||
previousPost,
|
||||
rootId,
|
||||
shouldRenderReplyButton,
|
||||
skipSaveddHeader,
|
||||
@@ -313,7 +314,7 @@ const PostList = ({
|
||||
if (highlightedId && orderedPosts && !scrolledToHighlighted.current) {
|
||||
scrolledToHighlighted.current = true;
|
||||
// eslint-disable-next-line max-nested-callbacks
|
||||
const index = orderedPosts.findIndex((p) => p.type === 'post' && p.value.id === highlightedId);
|
||||
const index = orderedPosts.findIndex((p) => p.type === 'post' && p.value.currentPost.id === highlightedId);
|
||||
if (index >= 0 && listRef.current) {
|
||||
listRef.current?.scrollToIndex({
|
||||
animated: true,
|
||||
|
||||
@@ -151,9 +151,9 @@ const RecentMentionsScreen = ({appsEnabled, customEmojiNames, mentions, currentT
|
||||
<PostWithChannelInfo
|
||||
appsEnabled={appsEnabled}
|
||||
customEmojiNames={customEmojiNames}
|
||||
key={item.value.id}
|
||||
key={item.value.currentPost.id}
|
||||
location={Screens.MENTIONS}
|
||||
post={item.value}
|
||||
post={item.value.currentPost}
|
||||
testID='recent_mentions.post_list'
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -152,9 +152,9 @@ function SavedMessages({appsEnabled, posts, currentTimezone, customEmojiNames, i
|
||||
<PostWithChannelInfo
|
||||
appsEnabled={appsEnabled}
|
||||
customEmojiNames={customEmojiNames}
|
||||
key={item.value.id}
|
||||
key={item.value.currentPost.id}
|
||||
location={Screens.SAVED_MESSAGES}
|
||||
post={item.value}
|
||||
post={item.value.currentPost}
|
||||
testID='saved_messages.post_list'
|
||||
skipSavedPostsHighlight={true}
|
||||
/>
|
||||
|
||||
@@ -51,9 +51,9 @@ const PostResults = ({
|
||||
<PostWithChannelInfo
|
||||
appsEnabled={appsEnabled}
|
||||
customEmojiNames={customEmojiNames}
|
||||
key={item.value.id}
|
||||
key={item.value.currentPost.id}
|
||||
location={Screens.SEARCH}
|
||||
post={item.value}
|
||||
post={item.value.currentPost}
|
||||
testID='search_results.post_list'
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -132,9 +132,9 @@ function SavedMessages({
|
||||
highlightPinnedOrSaved={false}
|
||||
isCRTEnabled={isCRTEnabled}
|
||||
location={Screens.PINNED_MESSAGES}
|
||||
key={item.value.id}
|
||||
key={item.value.currentPost.id}
|
||||
nextPost={undefined}
|
||||
post={item.value}
|
||||
post={item.value.currentPost}
|
||||
previousPost={undefined}
|
||||
showAddReaction={false}
|
||||
shouldRenderReplyButton={false}
|
||||
|
||||
@@ -66,17 +66,17 @@ function combineUserActivityPosts(orderedPosts: PostList) {
|
||||
combinedCount = 0;
|
||||
|
||||
continue;
|
||||
} else if (item.type === 'post' && item.value.deleteAt) {
|
||||
} else if (item.type === 'post' && item.value.currentPost.deleteAt) {
|
||||
out.push(item);
|
||||
|
||||
lastPostIsUserActivity = false;
|
||||
combinedCount = 0;
|
||||
} else {
|
||||
const postIsUserActivity = item.type === 'post' && Post.USER_ACTIVITY_POST_TYPES.includes(item.value.type);
|
||||
const postIsUserActivity = item.type === 'post' && Post.USER_ACTIVITY_POST_TYPES.includes(item.value.currentPost.type);
|
||||
if (postIsUserActivity && lastPostIsUserActivity && combinedCount < MAX_COMBINED_SYSTEM_POSTS) {
|
||||
out[out.length - 1].value += '_' + item.value.id;
|
||||
out[out.length - 1].value += '_' + item.value.currentPost.id;
|
||||
} else if (postIsUserActivity) {
|
||||
out.push({type: 'user-activity', value: `${COMBINED_USER_ACTIVITY}${item.value.id}`});
|
||||
out.push({type: 'user-activity', value: `${COMBINED_USER_ACTIVITY}${item.value.currentPost.id}`});
|
||||
combinedCount = 1;
|
||||
changed = true;
|
||||
} else {
|
||||
@@ -193,8 +193,8 @@ export function selectOrderedPosts(
|
||||
|
||||
// Iterating through the posts from oldest to newest
|
||||
for (let i = posts.length - 1; i >= 0; i--) {
|
||||
const post: PostWithPrevAndNext = posts[i];
|
||||
post.isSaved = savedPostIds.has(post.id);
|
||||
const post: PostWithPrevAndNext = {currentPost: posts[i]};
|
||||
post.isSaved = savedPostIds.has(post.currentPost.id);
|
||||
if (includePrevNext) {
|
||||
post.nextPost = posts[i - 1];
|
||||
if (!isThreadScreen || out[out.length - 1]?.type !== 'thread-overview') {
|
||||
@@ -204,25 +204,25 @@ export function selectOrderedPosts(
|
||||
|
||||
if (
|
||||
!post ||
|
||||
(post.type === Post.POST_TYPES.EPHEMERAL_ADD_TO_CHANNEL && !isThreadScreen)
|
||||
(post.currentPost.type === Post.POST_TYPES.EPHEMERAL_ADD_TO_CHANNEL && !isThreadScreen)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Filter out join/leave messages if necessary
|
||||
if (shouldFilterJoinLeavePost(post, showJoinLeave, currentUsername)) {
|
||||
if (shouldFilterJoinLeavePost(post.currentPost, showJoinLeave, currentUsername)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Push on a date header if the last post was on a different day than the current one
|
||||
const postDate = new Date(post.createAt);
|
||||
const postDate = new Date(post.currentPost.createAt);
|
||||
if (timezoneEnabled) {
|
||||
const currentOffset = toMilliseconds({minutes: postDate.getTimezoneOffset()});
|
||||
if (currentTimezone) {
|
||||
const zone = moment.tz.zone(currentTimezone);
|
||||
if (zone) {
|
||||
const timezoneOffset = toMilliseconds({minutes: zone.utcOffset(post.createAt)});
|
||||
postDate.setTime(post.createAt + (currentOffset - timezoneOffset));
|
||||
const timezoneOffset = toMilliseconds({minutes: zone.utcOffset(post.currentPost.createAt)});
|
||||
postDate.setTime(post.currentPost.createAt + (currentOffset - timezoneOffset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,8 +235,8 @@ export function selectOrderedPosts(
|
||||
|
||||
if (
|
||||
lastViewedAt &&
|
||||
post.createAt > lastViewedAt &&
|
||||
(post.userId !== currentUserId || isFromWebhook(post)) &&
|
||||
post.currentPost.createAt > lastViewedAt &&
|
||||
(post.currentPost.userId !== currentUserId || isFromWebhook(post.currentPost)) &&
|
||||
!addedNewMessagesIndicator &&
|
||||
indicateNewMessages
|
||||
) {
|
||||
|
||||
@@ -14,7 +14,7 @@ export type ViewableItemsChangedListenerEvent = (viewableItms: ViewToken[]) => v
|
||||
export type ScrollEndIndexListener = (fn: (endIndex: number) => void) => () => void;
|
||||
export type ViewableItemsListener = (fn: (viewableItems: ViewToken[]) => void) => () => void;
|
||||
|
||||
export type PostWithPrevAndNext = PostModel & {nextPost?: PostModel; previousPost?: PostModel; isSaved?: boolean};
|
||||
export type PostWithPrevAndNext = {currentPost: PostModel; nextPost?: PostModel; previousPost?: PostModel; isSaved?: boolean};
|
||||
|
||||
export type PostListItem = {
|
||||
type: 'post';
|
||||
|
||||
Reference in New Issue
Block a user