diff --git a/app/actions/navigation/index.js b/app/actions/navigation/index.js index 8fc2402c2..f41372a82 100644 --- a/app/actions/navigation/index.js +++ b/app/actions/navigation/index.js @@ -10,6 +10,8 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import store from 'app/store'; import EphemeralStore from 'app/store/ephemeral_store'; +const CHANNEL_SCREEN = 'Channel'; + function getThemeFromState() { const state = store.getState(); @@ -24,8 +26,8 @@ export function resetToChannel(passProps = {}) { const stack = { children: [{ component: { - id: 'Channel', - name: 'Channel', + id: CHANNEL_SCREEN, + name: CHANNEL_SCREEN, passProps, options: { layout: { @@ -397,10 +399,8 @@ export function closeMainSideMenu() { return; } - const componentId = EphemeralStore.getNavigationTopComponentId(); - Keyboard.dismiss(); - Navigation.mergeOptions(componentId, { + Navigation.mergeOptions(CHANNEL_SCREEN, { sideMenu: { left: {visible: false}, }, @@ -412,9 +412,7 @@ export function enableMainSideMenu(enabled, visible = true) { return; } - const componentId = EphemeralStore.getNavigationTopComponentId(); - - Navigation.mergeOptions(componentId, { + Navigation.mergeOptions(CHANNEL_SCREEN, { sideMenu: { left: {enabled, visible}, }, @@ -426,10 +424,8 @@ export function openSettingsSideMenu() { return; } - const componentId = EphemeralStore.getNavigationTopComponentId(); - Keyboard.dismiss(); - Navigation.mergeOptions(componentId, { + Navigation.mergeOptions(CHANNEL_SCREEN, { sideMenu: { right: {visible: true}, }, @@ -441,10 +437,8 @@ export function closeSettingsSideMenu() { return; } - const componentId = EphemeralStore.getNavigationTopComponentId(); - Keyboard.dismiss(); - Navigation.mergeOptions(componentId, { + Navigation.mergeOptions(CHANNEL_SCREEN, { sideMenu: { right: {visible: false}, }, diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index b04a1d68f..ba1a9980d 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -48,6 +48,7 @@ import {INSERT_TO_COMMENT, INSERT_TO_DRAFT} from 'app/constants/post_textbox'; import {getChannelReachable} from 'app/selectors/channel'; import telemetry from 'app/telemetry'; import {isDirectChannelVisible, isGroupChannelVisible, isDirectMessageVisible, isGroupMessageVisible, isDirectChannelAutoClosed} from 'app/utils/channels'; +import {isPendingPost} from 'app/utils/general'; import {buildPreference} from 'app/utils/preferences'; import {getPosts, getPostsBefore, getPostsSince, getPostThread} from './post'; @@ -647,6 +648,7 @@ export function increasePostVisibility(channelId, postId) { return async (dispatch, getState) => { const state = getState(); const {loadingPosts} = state.views.channel; + const currentUserId = getCurrentUserId(state); if (loadingPosts[channelId]) { return true; @@ -657,6 +659,11 @@ export function increasePostVisibility(channelId, postId) { return true; } + if (isPendingPost(postId, currentUserId)) { + // This is the first created post in the channel + return true; + } + telemetry.reset(); telemetry.start(['posts:loading']); diff --git a/app/actions/views/post.js b/app/actions/views/post.js index d6a14f57a..75193d12a 100644 --- a/app/actions/views/post.js +++ b/app/actions/views/post.js @@ -75,25 +75,29 @@ export function selectAttachmentMenuAction(postId, actionId, text, value) { } export function getPosts(channelId, page = 0, perPage = Posts.POST_CHUNK_SIZE) { - return async (dispatch) => { + return async (dispatch, getState) => { try { + const state = getState(); + const {postsInChannel} = state.entities.posts; + const postForChannel = postsInChannel[channelId]; const data = await Client4.getPosts(channelId, page, perPage); const posts = Object.values(data.posts); + const actions = []; + + if (posts?.length || !postForChannel) { + actions.push(receivedPostsInChannel(data, channelId, page === 0, data.prev_post_id === '')); + } if (posts?.length) { - const actions = [ - receivedPosts(data), - receivedPostsInChannel(data, channelId, page === 0, data.prev_post_id === ''), - ]; - + actions.push(receivedPosts(data)); const additional = await dispatch(getPostsAdditionalDataBatch(posts)); if (additional.length) { actions.push(...additional); } - - dispatch(batchActions(actions)); } + dispatch(batchActions(actions)); + return {data}; } catch (error) { return {error}; diff --git a/app/utils/general.js b/app/utils/general.js index 6365e9380..66779665a 100644 --- a/app/utils/general.js +++ b/app/utils/general.js @@ -78,3 +78,7 @@ export function throttle(fn, limit, ...args) { } }; } + +export function isPendingPost(postId, userId) { + return postId.startsWith(userId); +} \ No newline at end of file