Change Post.IsFollowing to a pointer and set to nil for responses to updates to Posts (#17774)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
857c5e562f
Коммит
326eb2242a
@@ -649,6 +649,11 @@ func (a *App) UpdatePost(c *request.Context, post *model.Post, safeUpdate bool)
|
|||||||
|
|
||||||
rpost = a.PreparePostForClient(rpost, false, true)
|
rpost = a.PreparePostForClient(rpost, false, true)
|
||||||
|
|
||||||
|
// Ensure IsFollowing is nil since this updated post will be broadcast to all users
|
||||||
|
// and we don't want to have to populate it for every single user and broadcast to each
|
||||||
|
// individually.
|
||||||
|
rpost.IsFollowing = nil
|
||||||
|
|
||||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", rpost.ChannelId, "", nil)
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POST_EDITED, "", rpost.ChannelId, "", nil)
|
||||||
message.Add("post", rpost.ToJson())
|
message.Add("post", rpost.ToJson())
|
||||||
a.Publish(message)
|
a.Publish(message)
|
||||||
|
|||||||
@@ -2080,7 +2080,7 @@ func TestCollapsedThreadFetch(t *testing.T) {
|
|||||||
require.EqualValues(t, []string{user1.Id}, []string{l.Posts[postRoot.Id].Participants[0].Id})
|
require.EqualValues(t, []string{user1.Id}, []string{l.Posts[postRoot.Id].Participants[0].Id})
|
||||||
require.Empty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
require.Empty(t, l.Posts[postRoot.Id].Participants[0].Email)
|
||||||
require.NotZero(t, l.Posts[postRoot.Id].LastReplyAt)
|
require.NotZero(t, l.Posts[postRoot.Id].LastReplyAt)
|
||||||
require.True(t, l.Posts[postRoot.Id].IsFollowing)
|
require.True(t, *l.Posts[postRoot.Id].IsFollowing)
|
||||||
|
|
||||||
// try extended fetch
|
// try extended fetch
|
||||||
l, err = th.App.GetPostsForChannelAroundLastUnread(channel.Id, user1.Id, 10, 10, true, true, true)
|
l, err = th.App.GetPostsForChannelAroundLastUnread(channel.Id, user1.Id, 10, 10, true, true, true)
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ type Post struct {
|
|||||||
ReplyCount int64 `json:"reply_count" db:"-"`
|
ReplyCount int64 `json:"reply_count" db:"-"`
|
||||||
LastReplyAt int64 `json:"last_reply_at" db:"-"`
|
LastReplyAt int64 `json:"last_reply_at" db:"-"`
|
||||||
Participants []*User `json:"participants" db:"-"`
|
Participants []*User `json:"participants" db:"-"`
|
||||||
IsFollowing bool `json:"is_following" db:"-"` // for root posts in collapsed thread mode indicates if the current user is following this thread
|
IsFollowing *bool `json:"is_following,omitempty" db:"-"` // for root posts in collapsed thread mode indicates if the current user is following this thread
|
||||||
Metadata *PostMetadata `json:"metadata,omitempty" db:"-"`
|
Metadata *PostMetadata `json:"metadata,omitempty" db:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,9 @@ func (o *Post) ShallowCopy(dst *Post) error {
|
|||||||
dst.Participants = o.Participants
|
dst.Participants = o.Participants
|
||||||
dst.LastReplyAt = o.LastReplyAt
|
dst.LastReplyAt = o.LastReplyAt
|
||||||
dst.Metadata = o.Metadata
|
dst.Metadata = o.Metadata
|
||||||
dst.IsFollowing = o.IsFollowing
|
if o.IsFollowing != nil {
|
||||||
|
dst.IsFollowing = NewBool(*o.IsFollowing)
|
||||||
|
}
|
||||||
dst.RemoteId = o.RemoteId
|
dst.RemoteId = o.RemoteId
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type SqlPostStore struct {
|
|||||||
|
|
||||||
type postWithExtra struct {
|
type postWithExtra struct {
|
||||||
ThreadReplyCount int64
|
ThreadReplyCount int64
|
||||||
IsFollowing bool
|
IsFollowing *bool
|
||||||
ThreadParticipants model.StringArray
|
ThreadParticipants model.StringArray
|
||||||
model.Post
|
model.Post
|
||||||
}
|
}
|
||||||
@@ -739,7 +739,9 @@ func (s *SqlPostStore) prepareThreadedResponse(posts []*postWithExtra, extended,
|
|||||||
}
|
}
|
||||||
processPost := func(p *postWithExtra) error {
|
processPost := func(p *postWithExtra) error {
|
||||||
p.Post.ReplyCount = p.ThreadReplyCount
|
p.Post.ReplyCount = p.ThreadReplyCount
|
||||||
p.Post.IsFollowing = p.IsFollowing
|
if p.IsFollowing != nil {
|
||||||
|
p.Post.IsFollowing = model.NewBool(*p.IsFollowing)
|
||||||
|
}
|
||||||
for _, th := range p.ThreadParticipants {
|
for _, th := range p.ThreadParticipants {
|
||||||
var participant *model.User
|
var participant *model.User
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ func testPostStoreGetForThread(t *testing.T, ss store.Store) {
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPostStoreGetSingle(t *testing.T, ss store.Store) {
|
func testPostStoreGetSingle(t *testing.T, ss store.Store) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user