MM-17339: fix missing post thread (#11729)

* leverage testify for TestGetPostsForChannelAroundLastUnread

* introduce assertPostList helper

* unit test MM-17339

* fix MM-17339
Этот коммит содержится в:
Jesse Hallam
2019-07-30 06:27:18 -03:00
коммит произвёл Saturnino Abril
родитель e2ef5d7149
Коммит f44473e062
2 изменённых файлов: 168 добавлений и 53 удалений

Просмотреть файл

@@ -771,27 +771,33 @@ func (a *App) GetPostsForChannelAroundLastUnread(channelId, userId string, limit
return model.NewPostList(), nil
}
lastUnreadPost, err := a.GetPostAfterTime(channelId, member.LastViewedAt)
lastUnreadPostId, err := a.GetPostIdAfterTime(channelId, member.LastViewedAt)
if err != nil {
return nil, err
} else if lastUnreadPost == nil {
} else if lastUnreadPostId == "" {
return model.NewPostList(), nil
}
var postList *model.PostList
if postList, err = a.GetPostsBeforePost(channelId, lastUnreadPost.Id, PAGE_DEFAULT, limitBefore); err != nil {
postList, err := a.GetPostThread(lastUnreadPostId)
if err != nil {
return nil, err
}
// Reset order to only include the last unread post: if the thread appears in the centre
// channel organically, those replies will be added below.
postList.Order = []string{lastUnreadPostId}
if postListAfter, err := a.GetPostsAfterPost(channelId, lastUnreadPost.Id, PAGE_DEFAULT, limitAfter-1); err != nil {
if postListBefore, err := a.GetPostsBeforePost(channelId, lastUnreadPostId, PAGE_DEFAULT, limitBefore); err != nil {
return nil, err
} else if postListBefore != nil {
postList.Extend(postListBefore)
}
if postListAfter, err := a.GetPostsAfterPost(channelId, lastUnreadPostId, PAGE_DEFAULT, limitAfter-1); err != nil {
return nil, err
} else if postListAfter != nil {
postList.Extend(postListAfter)
}
postList.AddPost(lastUnreadPost)
postList.AddOrder(lastUnreadPost.Id)
postList.SortByCreateAt()
return postList, nil
}