Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always load the thread & modify thread selector #4771

Merged
merged 2 commits into from Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 1 addition & 13 deletions app/actions/views/channel.js
Expand Up @@ -31,7 +31,7 @@ import {getChannelByName as selectChannelByName, getChannelsIdForTeam} from '@mm
import EventEmitter from '@mm-redux/utils/event_emitter';

import {lastChannelIdForTeam, loadSidebarDirectMessagesProfiles} from '@actions/helpers/channels';
import {getPosts, getPostsBefore, getPostsSince, getPostThread, loadUnreadChannelPosts} from '@actions/views/post';
import {getPosts, getPostsBefore, getPostsSince, loadUnreadChannelPosts} from '@actions/views/post';
import {INSERT_TO_COMMENT, INSERT_TO_DRAFT} from '@constants/post_draft';
import {getChannelReachable} from '@selectors/channel';
import telemetry from '@telemetry';
Expand Down Expand Up @@ -111,18 +111,6 @@ export function fetchPostActionWithRetry(action, maxTries = MAX_RETRIES) {
};
}

export function loadThreadIfNecessary(rootId) {
return (dispatch, getState) => {
const state = getState();
const {posts, postsInThread} = state.entities.posts;
const threadPosts = postsInThread[rootId];

if (!posts[rootId] || !threadPosts) {
dispatch(getPostThread(rootId));
}
};
}

export function selectInitialChannel(teamId) {
return (dispatch, getState) => {
const state = getState();
Expand Down
17 changes: 7 additions & 10 deletions app/mm-redux/selectors/entities/posts.ts
Expand Up @@ -69,23 +69,20 @@ export const getPostsInCurrentChannel: (a: GlobalState) => Array<PostWithFormatD
export function makeGetPostIdsForThread(): (b: GlobalState, a: $ID<Post>) => Array<$ID<Post>> {
return createIdsSelector(
getAllPosts,
(state: GlobalState, rootId: string) => state.entities.posts.postsInThread[rootId] || [],
(state: GlobalState, rootId) => state.entities.posts.posts[rootId],
(posts, postsForThread, rootPost) => {
(state: GlobalState, rootId: string) => state.entities.posts.posts[rootId],
(posts, rootPost) => {
const thread: Post[] = [];

if (rootPost) {
thread.push(rootPost);
}

postsForThread.forEach((id) => {
const post = posts[id];
if (post) {
thread.push(post);
const postsArray = Object.values(posts).filter((p) => p.root_id === rootPost.id);
if (postsArray.length) {
thread.push(...postsArray);
}
});

thread.sort(comparePosts);
thread.sort(comparePosts);
}

return thread.map((post) => post.id);
},
Expand Down
4 changes: 2 additions & 2 deletions app/screens/channel/channel_post_list/channel_post_list.js
Expand Up @@ -30,7 +30,7 @@ export default class ChannelPostList extends PureComponent {
static propTypes = {
actions: PropTypes.shape({
loadPostsIfNecessaryWithRetry: PropTypes.func.isRequired,
loadThreadIfNecessary: PropTypes.func.isRequired,
getPostThread: PropTypes.func.isRequired,
increasePostVisibility: PropTypes.func.isRequired,
selectPost: PropTypes.func.isRequired,
recordLoadTime: PropTypes.func.isRequired,
Expand Down Expand Up @@ -106,7 +106,7 @@ export default class ChannelPostList extends PureComponent {
const rootId = (post.root_id || post.id);

Keyboard.dismiss();
actions.loadThreadIfNecessary(rootId);
actions.getPostThread(rootId);
actions.selectPost(rootId);

const screen = 'Thread';
Expand Down
Expand Up @@ -12,7 +12,7 @@ describe('ChannelPostList', () => {
const baseProps = {
actions: {
loadPostsIfNecessaryWithRetry: jest.fn(),
loadThreadIfNecessary: jest.fn(),
getPostThread: jest.fn(),
increasePostVisibility: jest.fn(),
selectPost: jest.fn(),
recordLoadTime: jest.fn(),
Expand Down
21 changes: 10 additions & 11 deletions app/screens/channel/channel_post_list/index.js
Expand Up @@ -4,21 +4,20 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {selectPost} from '@mm-redux/actions/posts';
import {getPostIdsInCurrentChannel} from '@mm-redux/selectors/entities/posts';
import {getCurrentChannelId} from '@mm-redux/selectors/entities/channels';
import {getCurrentUserId} from '@mm-redux/selectors/entities/users';
import {getTheme} from '@mm-redux/selectors/entities/preferences';

import {
loadPostsIfNecessaryWithRetry,
loadThreadIfNecessary,
increasePostVisibility,
refreshChannelWithRetry,
} from 'app/actions/views/channel';
} from '@actions/views/channel';
import {getPostThread} from '@actions/views/post';
import {recordLoadTime} from 'app/actions/views/root';
import {Types} from 'app/constants';
import {isLandscape} from 'app/selectors/device';
import {Types} from '@constants';
import {selectPost} from '@mm-redux/actions/posts';
import {getPostIdsInCurrentChannel} from '@mm-redux/selectors/entities/posts';
import {getCurrentChannelId} from '@mm-redux/selectors/entities/channels';
import {getCurrentUserId} from '@mm-redux/selectors/entities/users';
import {getTheme} from '@mm-redux/selectors/entities/preferences';
import {isLandscape} from '@selectors/device';

import ChannelPostList from './channel_post_list';

Expand All @@ -44,7 +43,7 @@ function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
loadPostsIfNecessaryWithRetry,
loadThreadIfNecessary,
getPostThread,
increasePostVisibility,
selectPost,
recordLoadTime,
Expand Down
4 changes: 2 additions & 2 deletions app/screens/flagged_posts/flagged_posts.js
Expand Up @@ -36,7 +36,7 @@ export default class FlaggedPosts extends PureComponent {
actions: PropTypes.shape({
clearSearch: PropTypes.func.isRequired,
loadChannelsByTeamName: PropTypes.func.isRequired,
loadThreadIfNecessary: PropTypes.func.isRequired,
getPostThread: PropTypes.func.isRequired,
getFlaggedPosts: PropTypes.func.isRequired,
selectFocusedPostId: PropTypes.func.isRequired,
selectPost: PropTypes.func.isRequired,
Expand Down Expand Up @@ -103,7 +103,7 @@ export default class FlaggedPosts extends PureComponent {
};

Keyboard.dismiss();
actions.loadThreadIfNecessary(rootId);
actions.getPostThread(rootId);
actions.selectPost(rootId);
goToScreen(screen, title, passProps);
};
Expand Down
2 changes: 1 addition & 1 deletion app/screens/flagged_posts/flagged_posts.test.js
Expand Up @@ -15,7 +15,7 @@ describe('FlaggedPosts', () => {
actions: {
clearSearch: jest.fn(),
loadChannelsByTeamName: jest.fn(),
loadThreadIfNecessary: jest.fn(),
getPostThread: jest.fn(),
getFlaggedPosts: jest.fn(),
selectFocusedPostId: jest.fn(),
selectPost: jest.fn(),
Expand Down
8 changes: 4 additions & 4 deletions app/screens/flagged_posts/index.js
Expand Up @@ -4,12 +4,12 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {loadChannelsByTeamName} from '@actions/views/channel';
import {getPostThread} from '@actions/views/post';
import {selectFocusedPostId, selectPost} from '@mm-redux/actions/posts';
import {clearSearch, getFlaggedPosts} from '@mm-redux/actions/search';
import {getTheme} from '@mm-redux/selectors/entities/preferences';

import {loadChannelsByTeamName, loadThreadIfNecessary} from 'app/actions/views/channel';
import {makePreparePostIdsForSearchPosts} from 'app/selectors/post_list';
import {makePreparePostIdsForSearchPosts} from '@selectors/post_list';

import FlaggedPosts from './flagged_posts';

Expand All @@ -30,7 +30,7 @@ function mapDispatchToProps(dispatch) {
actions: bindActionCreators({
clearSearch,
loadChannelsByTeamName,
loadThreadIfNecessary,
getPostThread,
getFlaggedPosts,
selectFocusedPostId,
selectPost,
Expand Down
4 changes: 2 additions & 2 deletions app/screens/long_post/__snapshots__/long_post.test.js.snap
Expand Up @@ -35,7 +35,7 @@ LongPost {
"navigationEventListener": undefined,
"props": Object {
"actions": Object {
"loadThreadIfNecessary": [MockFunction],
"getPostThread": [MockFunction],
"selectPost": [MockFunction],
},
"intl": Object {
Expand Down Expand Up @@ -147,7 +147,7 @@ LongPost {
"_element": <LongPost
actions={
Object {
"loadThreadIfNecessary": [MockFunction],
"getPostThread": [MockFunction],
"selectPost": [MockFunction],
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/screens/long_post/index.js
Expand Up @@ -4,13 +4,13 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {getPostThread} from '@actions/views/channel';
import {selectPost} from '@mm-redux/actions/posts';
import {makeGetChannel} from '@mm-redux/selectors/entities/channels';
import {getPost} from '@mm-redux/selectors/entities/posts';
import {getTheme} from '@mm-redux/selectors/entities/preferences';
import {isLandscape} from '@selectors/device';

import {loadThreadIfNecessary} from 'app/actions/views/channel';
import {isLandscape} from 'app/selectors/device';
import LongPost from './long_post';

function makeMapStateToProps() {
Expand All @@ -32,7 +32,7 @@ function makeMapStateToProps() {
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
loadThreadIfNecessary,
getPostThread,
selectPost,
}, dispatch),
};
Expand Down
5 changes: 2 additions & 3 deletions app/screens/long_post/long_post.js
Expand Up @@ -41,11 +41,10 @@ Animatable.initializeRegistryWithDefinitions({
export default class LongPost extends PureComponent {
static propTypes = {
actions: PropTypes.shape({
loadThreadIfNecessary: PropTypes.func.isRequired,
getPostThread: PropTypes.func.isRequired,
selectPost: PropTypes.func.isRequired,
}).isRequired,
channelName: PropTypes.string,
isPermalink: PropTypes.bool,
inThreadView: PropTypes.bool,
managedConfig: PropTypes.object,
onHashtagPress: PropTypes.func,
Expand Down Expand Up @@ -84,7 +83,7 @@ export default class LongPost extends PureComponent {
rootId,
};

actions.loadThreadIfNecessary(rootId);
actions.getPostThread(rootId);
actions.selectPost(rootId);

goToScreen(screen, title, passProps);
Expand Down
2 changes: 1 addition & 1 deletion app/screens/long_post/long_post.test.js
Expand Up @@ -16,7 +16,7 @@ jest.mock('react-native-file-viewer', () => ({
describe('LongPost', () => {
const baseProps = {
actions: {
loadThreadIfNecessary: jest.fn(),
getPostThread: jest.fn(),
selectPost: jest.fn(),
},
postId: 'post-id',
Expand Down
13 changes: 4 additions & 9 deletions app/screens/permalink/index.js
Expand Up @@ -4,21 +4,17 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {handleSelectChannel} from '@actions/views/channel';
import {getPostsAround, getPostThread} from '@actions/views/post';
import {handleTeamChange} from '@actions/views/select_team';
import {getChannel as getChannelAction, joinChannel} from '@mm-redux/actions/channels';
import {selectPost} from '@mm-redux/actions/posts';
import {makeGetChannel, getMyChannelMemberships} from '@mm-redux/selectors/entities/channels';
import {makeGetPostIdsAroundPost, getPost} from '@mm-redux/selectors/entities/posts';
import {getTheme} from '@mm-redux/selectors/entities/preferences';
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
import {getCurrentUserId} from '@mm-redux/selectors/entities/users';

import {
handleSelectChannel,
loadThreadIfNecessary,
} from 'app/actions/views/channel';
import {getPostsAround, getPostThread} from 'app/actions/views/post';
import {handleTeamChange} from 'app/actions/views/select_team';
import {isLandscape} from 'app/selectors/device';
import {isLandscape} from '@selectors/device';

import Permalink from './permalink';

Expand Down Expand Up @@ -66,7 +62,6 @@ function mapDispatchToProps(dispatch) {
handleSelectChannel,
handleTeamChange,
joinChannel,
loadThreadIfNecessary,
selectPost,
}, dispatch),
};
Expand Down
3 changes: 1 addition & 2 deletions app/screens/permalink/permalink.js
Expand Up @@ -60,7 +60,6 @@ export default class Permalink extends PureComponent {
handleSelectChannel: PropTypes.func.isRequired,
handleTeamChange: PropTypes.func.isRequired,
joinChannel: PropTypes.func.isRequired,
loadThreadIfNecessary: PropTypes.func.isRequired,
selectPost: PropTypes.func.isRequired,
}).isRequired,
channelId: PropTypes.string,
Expand Down Expand Up @@ -147,7 +146,7 @@ export default class Permalink extends PureComponent {
rootId,
};

actions.loadThreadIfNecessary(rootId);
actions.getPostThread(rootId);
actions.selectPost(rootId);

goToScreen(screen, title, passProps);
Expand Down
1 change: 0 additions & 1 deletion app/screens/permalink/permalink.test.js
Expand Up @@ -18,7 +18,6 @@ describe('Permalink', () => {
handleSelectChannel: jest.fn(),
handleTeamChange: jest.fn(),
joinChannel: jest.fn(),
loadThreadIfNecessary: jest.fn(),
selectPost: jest.fn(),
};

Expand Down
8 changes: 4 additions & 4 deletions app/screens/pinned_posts/index.js
Expand Up @@ -4,12 +4,12 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {loadChannelsByTeamName} from '@actions/views/channel';
import {getPostThread} from '@actions/views/post';
import {selectFocusedPostId, selectPost} from '@mm-redux/actions/posts';
import {clearSearch, getPinnedPosts} from '@mm-redux/actions/search';
import {getTheme} from '@mm-redux/selectors/entities/preferences';

import {loadChannelsByTeamName, loadThreadIfNecessary} from 'app/actions/views/channel';
import {makePreparePostIdsForSearchPosts} from 'app/selectors/post_list';
import {makePreparePostIdsForSearchPosts} from '@selectors/post_list';

import PinnedPosts from './pinned_posts';

Expand All @@ -32,7 +32,7 @@ function mapDispatchToProps(dispatch) {
actions: bindActionCreators({
clearSearch,
loadChannelsByTeamName,
loadThreadIfNecessary,
getPostThread,
getPinnedPosts,
selectFocusedPostId,
selectPost,
Expand Down
4 changes: 2 additions & 2 deletions app/screens/pinned_posts/pinned_posts.js
Expand Up @@ -36,7 +36,7 @@ export default class PinnedPosts extends PureComponent {
actions: PropTypes.shape({
clearSearch: PropTypes.func.isRequired,
loadChannelsByTeamName: PropTypes.func.isRequired,
loadThreadIfNecessary: PropTypes.func.isRequired,
getPostThread: PropTypes.func.isRequired,
getPinnedPosts: PropTypes.func.isRequired,
selectFocusedPostId: PropTypes.func.isRequired,
selectPost: PropTypes.func.isRequired,
Expand Down Expand Up @@ -104,7 +104,7 @@ export default class PinnedPosts extends PureComponent {
rootId,
};
Keyboard.dismiss();
actions.loadThreadIfNecessary(rootId);
actions.getPostThread(rootId);
actions.selectPost(rootId);
goToScreen(screen, title, passProps);
};
Expand Down
2 changes: 1 addition & 1 deletion app/screens/pinned_posts/pinned_posts.test.js
Expand Up @@ -14,7 +14,7 @@ describe('PinnedPosts', () => {
actions: {
clearSearch: jest.fn(),
loadChannelsByTeamName: jest.fn(),
loadThreadIfNecessary: jest.fn(),
getPostThread: jest.fn(),
getPinnedPosts: jest.fn(),
selectFocusedPostId: jest.fn(),
selectPost: jest.fn(),
Expand Down
8 changes: 4 additions & 4 deletions app/screens/recent_mentions/index.js
Expand Up @@ -4,12 +4,12 @@
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import {loadChannelsByTeamName} from '@actions/views/channel';
import {getPostThread} from '@actions/views/post';
import {selectFocusedPostId, selectPost} from '@mm-redux/actions/posts';
import {clearSearch, getRecentMentions} from '@mm-redux/actions/search';
import {getTheme} from '@mm-redux/selectors/entities/preferences';

import {loadChannelsByTeamName, loadThreadIfNecessary} from 'app/actions/views/channel';
import {makePreparePostIdsForSearchPosts} from 'app/selectors/post_list';
import {makePreparePostIdsForSearchPosts} from '@selectors/post_list';

import RecentMentions from './recent_mentions';

Expand All @@ -30,7 +30,7 @@ function mapDispatchToProps(dispatch) {
actions: bindActionCreators({
clearSearch,
loadChannelsByTeamName,
loadThreadIfNecessary,
getPostThread,
getRecentMentions,
selectFocusedPostId,
selectPost,
Expand Down