MM-30865 Invalid Participants handling on post delete in thread (#16353)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Eli Yukelzon
2020-12-01 16:50:39 +02:00
коммит произвёл GitHub
родитель 64499ca767
Коммит 1bd7dc41bd
2 изменённых файлов: 5 добавлений и 5 удалений

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

@@ -1937,7 +1937,6 @@ func (s *SqlPostStore) cleanupThreads(postId, rootId, userId string, permanent b
} }
if thread != nil { if thread != nil {
thread.ReplyCount -= 1 thread.ReplyCount -= 1
thread.Participants = thread.Participants.Remove(userId)
if _, err = s.Thread().Update(thread); err != nil { if _, err = s.Thread().Update(thread); err != nil {
return errors.Wrap(err, "failed to update thread") return errors.Wrap(err, "failed to update thread")
} }

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

@@ -4,12 +4,13 @@
package storetest package storetest
import ( import (
"testing"
"time"
"github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/store" "github.com/mattermost/mattermost-server/v5/store"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"testing"
"time"
) )
func TestThreadStore(t *testing.T, ss store.Store, s SqlSupplier) { func TestThreadStore(t *testing.T, ss store.Store, s SqlSupplier) {
@@ -120,7 +121,7 @@ func testThreadStorePopulation(t *testing.T, ss store.Store) {
require.Nil(t, err, "couldn't get thread") require.Nil(t, err, "couldn't get thread")
require.NotNil(t, thread) require.NotNil(t, thread)
require.Equal(t, int64(1), thread.ReplyCount) require.Equal(t, int64(1), thread.ReplyCount)
require.ElementsMatch(t, model.StringArray{newPosts[0].UserId}, thread.Participants) require.ElementsMatch(t, model.StringArray{newPosts[0].UserId, newPosts[1].UserId}, thread.Participants)
}) })
t.Run("Update reply should update the UpdateAt of the thread", func(t *testing.T) { t.Run("Update reply should update the UpdateAt of the thread", func(t *testing.T) {
@@ -197,7 +198,7 @@ func testThreadStorePopulation(t *testing.T, ss store.Store) {
thread2, err := ss.Thread().Get(rootPost.RootId) thread2, err := ss.Thread().Get(rootPost.RootId)
require.Nil(t, err) require.Nil(t, err)
require.EqualValues(t, thread2.ReplyCount, 1) require.EqualValues(t, thread2.ReplyCount, 1)
require.Len(t, thread2.Participants, 1) require.Len(t, thread2.Participants, 2)
}) })
t.Run("Deleting root post should delete the thread", func(t *testing.T) { t.Run("Deleting root post should delete the thread", func(t *testing.T) {