[MM-45730] Fix Sentry crash: nil deference in model/post_list.go:152 (#20742)

* Add check to include ID in Order, only if it exists in Posts

* avoid calling GetPostsBeforePost if lastUnreadPostId is inaccessible
Этот коммит содержится в:
Vishal
2022-08-18 14:33:33 +05:30
коммит произвёл GitHub
родитель a28a967eba
Коммит 53985ef162

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

@@ -1205,12 +1205,17 @@ func (a *App) GetPostsForChannelAroundLastUnread(c request.CTX, channelID, userI
}
// 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}
postList.Order = []string{}
// Add lastUnreadPostId in order, only if it hasn't been filtered as per the cloud plan's limit
if _, ok := postList.Posts[lastUnreadPostId]; ok {
postList.Order = []string{lastUnreadPostId}
if postListBefore, err := a.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelID, PostId: lastUnreadPostId, Page: PageDefault, PerPage: limitBefore, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended, UserId: userID}); err != nil {
return nil, err
} else if postListBefore != nil {
postList.Extend(postListBefore)
// BeforePosts will only be accessible if the lastUnreadPostId is itself accessible
if postListBefore, err := a.GetPostsBeforePost(model.GetPostsOptions{ChannelId: channelID, PostId: lastUnreadPostId, Page: PageDefault, PerPage: limitBefore, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended, UserId: userID}); err != nil {
return nil, err
} else if postListBefore != nil {
postList.Extend(postListBefore)
}
}
if postListAfter, err := a.GetPostsAfterPost(model.GetPostsOptions{ChannelId: channelID, PostId: lastUnreadPostId, Page: PageDefault, PerPage: limitAfter - 1, SkipFetchThreads: skipFetchThreads, CollapsedThreads: collapsedThreads, CollapsedThreadsExtended: collapsedThreadsExtended, UserId: userID}); err != nil {