Skip to content

Commit

Permalink
MM-15700 Manual load more trigger in virt list does not load more mes…
Browse files Browse the repository at this point in the history
…sages (mattermost#2824)

* MM-15700 Manual load more trigger in virt list does not load more messages

  * Exclude MANUAL_TRIGGER_LOAD_MESSAGES from getLastPostId

* Change condition to be a new func
  • Loading branch information
sudheerDev committed May 22, 2019
1 parent 0dab1a5 commit 3fd84d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
17 changes: 11 additions & 6 deletions utils/post_utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,23 @@ export function isErrorInvalidSlashCommand(error) {
return false;
}

function isIdNotPost(postId) {
return (
PostListUtils.isStartOfNewMessages(postId) ||
PostListUtils.isDateLine(postId) ||
postId === PostListRowListIds.CHANNEL_INTRO_MESSAGE ||
postId === PostListRowListIds.MORE_MESSAGES_LOADER ||
postId === PostListRowListIds.MANUAL_TRIGGER_LOAD_MESSAGES
);
}

// getLastPostId returns the most recent post ID in the given list of post IDs. This function is copied from
// mattermost-redux, except it also includes additional special IDs that are only used in the web app.
export function getLastPostId(postIds) {
for (let i = postIds.length - 1; i >= 0; i--) {
const item = postIds[i];

if (
PostListUtils.isStartOfNewMessages(item) ||
PostListUtils.isDateLine(item) ||
item === PostListRowListIds.CHANNEL_INTRO_MESSAGE ||
item === PostListRowListIds.MORE_MESSAGES_LOADER
) {
if (isIdNotPost(item)) {
// This is not a post at all
continue;
}
Expand Down
28 changes: 28 additions & 0 deletions utils/post_utils.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import assert from 'assert';

import * as PostUtils from 'utils/post_utils.jsx';
import {PostListRowListIds} from 'utils/constants.jsx';

describe('PostUtils.containsAtChannel', () => {
test('should return correct @all (same for @channel)', () => {
Expand Down Expand Up @@ -524,3 +525,30 @@ describe('PostUtils.postMessageOnKeyPress', () => {
});
}
});

describe('PostUtils.getLastPostId', () => {
test('Should not return MANUAL_TRIGGER_LOAD_MESSAGES', () => {
const postId = PostUtils.getLastPostId(['postId1', 'postId2', PostListRowListIds.MANUAL_TRIGGER_LOAD_MESSAGES]);
assert.equal(postId, 'postId2');
});

test('Should not return MORE_MESSAGES_LOADER', () => {
const postId = PostUtils.getLastPostId(['postId1', 'postId2', PostListRowListIds.MORE_MESSAGES_LOADER]);
assert.equal(postId, 'postId2');
});

test('Should not return CHANNEL_INTRO_MESSAGE', () => {
const postId = PostUtils.getLastPostId(['postId1', 'postId2', PostListRowListIds.CHANNEL_INTRO_MESSAGE]);
assert.equal(postId, 'postId2');
});

test('Should not return dateline', () => {
const postId = PostUtils.getLastPostId(['postId1', 'postId2', 'date-1558290600000']);
assert.equal(postId, 'postId2');
});

test('Should not return START_OF_NEW_MESSAGES', () => {
const postId = PostUtils.getLastPostId(['postId1', 'postId2', PostListRowListIds.START_OF_NEW_MESSAGES]);
assert.equal(postId, 'postId2');
});
});

0 comments on commit 3fd84d1

Please sign in to comment.