MM-38445: Set isFollowing to false only when explicitly unfollowed (#18740)
Summary Set post.IsFollowing to false only if the post is explicitly unfollowed. Otherwise leave it as nil. Ticket Link https://mattermost.atlassian.net/browse/MM-38445
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c91ab6267a
Коммит
097d32f409
@@ -528,7 +528,7 @@ func (s *SqlPostStore) getPostWithCollapsedThreads(id, userID string, extended b
|
|||||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
"ThreadMemberships.Following as IsFollowing",
|
||||||
)
|
)
|
||||||
var post postWithExtra
|
var post postWithExtra
|
||||||
|
|
||||||
@@ -879,7 +879,7 @@ func (s *SqlPostStore) getPostsCollapsedThreads(options model.GetPostsOptions) (
|
|||||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
"ThreadMemberships.Following as IsFollowing",
|
||||||
)
|
)
|
||||||
var posts []*postWithExtra
|
var posts []*postWithExtra
|
||||||
offset := options.PerPage * options.Page
|
offset := options.PerPage * options.Page
|
||||||
@@ -965,7 +965,7 @@ func (s *SqlPostStore) getPostsSinceCollapsedThreads(options model.GetPostsSince
|
|||||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
"ThreadMemberships.Following as IsFollowing",
|
||||||
)
|
)
|
||||||
var posts []*postWithExtra
|
var posts []*postWithExtra
|
||||||
|
|
||||||
@@ -1181,7 +1181,7 @@ func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions
|
|||||||
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
"COALESCE(Threads.ReplyCount, 0) as ThreadReplyCount",
|
||||||
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
"COALESCE(Threads.LastReplyAt, 0) as LastReplyAt",
|
||||||
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
"COALESCE(Threads.Participants, '[]') as ThreadParticipants",
|
||||||
"COALESCE(ThreadMemberships.Following, false) as IsFollowing",
|
"ThreadMemberships.Following as IsFollowing",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
query := s.getQueryBuilder().Select(columns...)
|
query := s.getQueryBuilder().Select(columns...)
|
||||||
|
|||||||
@@ -502,26 +502,64 @@ func testPostStoreGet(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testPostStoreGetForThread(t *testing.T, ss store.Store) {
|
func testPostStoreGetForThread(t *testing.T, ss store.Store) {
|
||||||
o1 := &model.Post{ChannelId: model.NewId(), UserId: model.NewId(), Message: NewTestId()}
|
t.Run("Post thread is followed", func(t *testing.T) {
|
||||||
o1, err := ss.Post().Save(o1)
|
o1 := &model.Post{ChannelId: model.NewId(), UserId: model.NewId(), Message: NewTestId()}
|
||||||
require.NoError(t, err)
|
o1, err := ss.Post().Save(o1)
|
||||||
_, err = ss.Post().Save(&model.Post{ChannelId: o1.ChannelId, UserId: model.NewId(), Message: NewTestId(), RootId: o1.Id})
|
require.NoError(t, err)
|
||||||
require.NoError(t, err)
|
_, err = ss.Post().Save(&model.Post{ChannelId: o1.ChannelId, UserId: model.NewId(), Message: NewTestId(), RootId: o1.Id})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
threadMembership := &model.ThreadMembership{
|
threadMembership := &model.ThreadMembership{
|
||||||
PostId: o1.Id,
|
PostId: o1.Id,
|
||||||
UserId: o1.UserId,
|
UserId: o1.UserId,
|
||||||
Following: true,
|
Following: true,
|
||||||
LastViewed: 0,
|
LastViewed: 0,
|
||||||
LastUpdated: 0,
|
LastUpdated: 0,
|
||||||
UnreadMentions: 0,
|
UnreadMentions: 0,
|
||||||
}
|
}
|
||||||
_, err = ss.Thread().SaveMembership(threadMembership)
|
_, err = ss.Thread().SaveMembership(threadMembership)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
r1, err := ss.Post().Get(context.Background(), o1.Id, false, true, false, o1.UserId)
|
r1, err := ss.Post().Get(context.Background(), o1.Id, false, true, false, o1.UserId)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, r1.Posts[o1.Id].CreateAt, o1.CreateAt, "invalid returned post")
|
require.Equal(t, r1.Posts[o1.Id].CreateAt, o1.CreateAt, "invalid returned post")
|
||||||
require.True(t, *r1.Posts[o1.Id].IsFollowing)
|
require.True(t, *r1.Posts[o1.Id].IsFollowing)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Post thread is explicitly not followed", func(t *testing.T) {
|
||||||
|
o1 := &model.Post{ChannelId: model.NewId(), UserId: model.NewId(), Message: NewTestId()}
|
||||||
|
o1, err := ss.Post().Save(o1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = ss.Post().Save(&model.Post{ChannelId: o1.ChannelId, UserId: model.NewId(), Message: NewTestId(), RootId: o1.Id})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
threadMembership := &model.ThreadMembership{
|
||||||
|
PostId: o1.Id,
|
||||||
|
UserId: o1.UserId,
|
||||||
|
Following: false,
|
||||||
|
LastViewed: 0,
|
||||||
|
LastUpdated: 0,
|
||||||
|
UnreadMentions: 0,
|
||||||
|
}
|
||||||
|
_, err = ss.Thread().SaveMembership(threadMembership)
|
||||||
|
require.NoError(t, err)
|
||||||
|
r1, err := ss.Post().Get(context.Background(), o1.Id, false, true, false, o1.UserId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, r1.Posts[o1.Id].CreateAt, o1.CreateAt, "invalid returned post")
|
||||||
|
require.False(t, *r1.Posts[o1.Id].IsFollowing)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Post threadmembership does not exist", func(t *testing.T) {
|
||||||
|
o1 := &model.Post{ChannelId: model.NewId(), UserId: model.NewId(), Message: NewTestId()}
|
||||||
|
o1, err := ss.Post().Save(o1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
_, err = ss.Post().Save(&model.Post{ChannelId: o1.ChannelId, UserId: model.NewId(), Message: NewTestId(), RootId: o1.Id})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
r1, err := ss.Post().Get(context.Background(), o1.Id, false, true, false, o1.UserId)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, r1.Posts[o1.Id].CreateAt, o1.CreateAt, "invalid returned post")
|
||||||
|
require.Nil(t, r1.Posts[o1.Id].IsFollowing)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPostStoreGetSingle(t *testing.T, ss store.Store) {
|
func testPostStoreGetSingle(t *testing.T, ss store.Store) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user