From 63359328834995f253c0a08cbf62b66f36e6cfcd Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 11 Jun 2021 13:56:09 -0400 Subject: [PATCH] 1.44 fixes (#5444) * fix: get status as soon as appstate is in the foreground * re-render post list when theme changes * remove invalid userIds from get status request --- app/components/network_indicator/network.tsx | 4 +-- app/components/post_list/post_list.tsx | 2 +- app/mm-redux/actions/users.ts | 33 ++++++++++--------- app/screens/pinned_posts/pinned_posts.js | 1 + .../recent_mentions/recent_mentions.js | 1 + app/screens/saved_posts/saved_posts.js | 1 + 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/components/network_indicator/network.tsx b/app/components/network_indicator/network.tsx index 0dd7a928b..917a60eef 100644 --- a/app/components/network_indicator/network.tsx +++ b/app/components/network_indicator/network.tsx @@ -24,7 +24,7 @@ type Props = { initWebSocket: (additionalOptions: {forceConnection: boolean}) => void; markChannelViewedAndReadOnReconnect: (channelId: string) => void; setCurrentUserStatusOffline: () => void; - startPeriodicStatusUpdates: () => void; + startPeriodicStatusUpdates: (forceStatusUpdate: boolean) => void; status: string; stopPeriodicStatusUpdates: () => void; } @@ -142,7 +142,7 @@ const NetworkIndicator = ({ const handleWebSocket = (connect: boolean) => { if (connect) { initWebSocket({forceConnection: true}); - startPeriodicStatusUpdates(); + startPeriodicStatusUpdates(true); } else { closeWebSocket(true); stopPeriodicStatusUpdates(); diff --git a/app/components/post_list/post_list.tsx b/app/components/post_list/post_list.tsx index 212cc3d67..68d1ed254 100644 --- a/app/components/post_list/post_list.tsx +++ b/app/components/post_list/post_list.tsx @@ -217,7 +217,7 @@ const PostList = ({ {...postProps} /> ); - }, [postIds]); + }, [postIds, theme]); const scrollToIndex = useCallback((index: number, animated = true) => { flatListRef.current?.scrollToIndex({ diff --git a/app/mm-redux/actions/users.ts b/app/mm-redux/actions/users.ts index fb81f45b4..4d58749e2 100644 --- a/app/mm-redux/actions/users.ts +++ b/app/mm-redux/actions/users.ts @@ -802,29 +802,32 @@ export function searchProfiles(term: string, options: any = {}): ActionFunc { } let statusIntervalId: NodeJS.Timeout|null; -export function startPeriodicStatusUpdates(): ActionFunc { +export function startPeriodicStatusUpdates(forceStatusUpdate = false): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { if (statusIntervalId) { clearInterval(statusIntervalId); } - statusIntervalId = setInterval( - () => { - const {statuses} = getState().entities.users; + const getStatusForUsers = () => { + const {statuses} = getState().entities.users; - if (!statuses) { - return; - } + if (!statuses) { + return; + } - const userIds = Object.keys(statuses); - if (!userIds.length) { - return; - } + const userIds = Object.keys(statuses).filter((u) => u); + if (!userIds.length) { + return; + } - dispatch(getStatusesByIds(userIds)); - }, - General.STATUS_INTERVAL, - ); + dispatch(getStatusesByIds(userIds)); + }; + + statusIntervalId = setInterval(getStatusForUsers, General.STATUS_INTERVAL); + + if (forceStatusUpdate) { + getStatusForUsers(); + } return {data: true}; }; diff --git a/app/screens/pinned_posts/pinned_posts.js b/app/screens/pinned_posts/pinned_posts.js index eb6bd270e..8244335c6 100644 --- a/app/screens/pinned_posts/pinned_posts.js +++ b/app/screens/pinned_posts/pinned_posts.js @@ -171,6 +171,7 @@ export default class PinnedPosts extends PureComponent { ref={this.setListRef} contentContainerStyle={style.sectionList} data={postIds} + extraData={theme} keyExtractor={this.keyExtractor} keyboardShouldPersistTaps='always' keyboardDismissMode='interactive' diff --git a/app/screens/recent_mentions/recent_mentions.js b/app/screens/recent_mentions/recent_mentions.js index 3e6c73488..2291fcb81 100644 --- a/app/screens/recent_mentions/recent_mentions.js +++ b/app/screens/recent_mentions/recent_mentions.js @@ -171,6 +171,7 @@ export default class RecentMentions extends PureComponent { ref={this.setListRef} contentContainerStyle={style.sectionList} data={postIds} + extraData={theme} keyExtractor={this.keyExtractor} keyboardShouldPersistTaps='always' keyboardDismissMode='interactive' diff --git a/app/screens/saved_posts/saved_posts.js b/app/screens/saved_posts/saved_posts.js index 6af17e849..caf5a697d 100644 --- a/app/screens/saved_posts/saved_posts.js +++ b/app/screens/saved_posts/saved_posts.js @@ -173,6 +173,7 @@ export default class SavedPosts extends PureComponent { ref={this.setListRef} contentContainerStyle={style.sectionList} data={postIds} + extraData={theme} keyExtractor={this.keyExtractor} keyboardShouldPersistTaps='always' keyboardDismissMode='interactive'