Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Sort pending and failed posts to start of posts in channel (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilander authored and hmhealey committed Aug 28, 2020
1 parent ed8d66c commit f5d618b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/mattermost-redux/src/reducers/entities/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import {PostTypes, SearchTypes, UserTypes} from 'action_types';
import {Posts} from 'constants';
import {isPostPendingOrFailed} from 'utils/post_utils';

function handleReceivedPost(posts = {}, postsInChannel = {}, action) {
const post = action.data;
Expand Down Expand Up @@ -74,8 +75,17 @@ function handleReceivedPosts(posts = {}, postsInChannel = {}, action) {
}
}

// Sort to ensure that the most recent posts are first
// Sort to ensure that the most recent posts are first, with pending
// and failed posts first
postsForChannel.sort((a, b) => {
const aIsPendingOrFailed = isPostPendingOrFailed(nextPosts[a]);
const bIsPendingOrFailed = isPostPendingOrFailed(nextPosts[b]);
if (aIsPendingOrFailed && !bIsPendingOrFailed) {
return -1;
} else if (!aIsPendingOrFailed && bIsPendingOrFailed) {
return 1;
}

if (nextPosts[a].create_at > nextPosts[b].create_at) {
return -1;
} else if (nextPosts[a].create_at < nextPosts[b].create_at) {
Expand Down

0 comments on commit f5d618b

Please sign in to comment.