Automated cherry pick of #4064 (#4073)

* MM-23341 Fix message failed banner when posting first message

* Set switchToChannel flag back to false

* Feedback review

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
Mattermost Build 2020-03-24 21:29:45 +01:00 committed by GitHub
parent b830b8ec93
commit 8bd4a49849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 22 deletions

View file

@ -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},
},

View file

@ -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']);

View file

@ -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};

View file

@ -78,3 +78,7 @@ export function throttle(fn, limit, ...args) {
}
};
}
export function isPendingPost(postId, userId) {
return postId.startsWith(userId);
}