From 53985ef16268e7ef7b23ab730eb930ee5086f3fb Mon Sep 17 00:00:00 2001 From: Vishal Date: Thu, 18 Aug 2022 14:33:33 +0530 Subject: [PATCH] [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 --- app/post.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/post.go b/app/post.go index dd5e2c31ba..e7b1fc214d 100644 --- a/app/post.go +++ b/app/post.go @@ -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 {