[MM-10768] Migrate "Channel.SaveDirectChannel" to Sync by default (#10846)
Этот коммит содержится в:
коммит произвёл
Hanzei
родитель
2d3e417833
Коммит
fab2e349b3
@@ -340,16 +340,14 @@ func (a *App) createDirectChannel(userId string, otherUserId string) (*model.Cha
|
|||||||
return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId, http.StatusBadRequest)
|
return nil, model.NewAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := <-a.Srv.Store.Channel().CreateDirectChannel(userId, otherUserId)
|
channel, err := a.Srv.Store.Channel().CreateDirectChannel(userId, otherUserId)
|
||||||
if result.Err != nil {
|
if err != nil {
|
||||||
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
|
if err.Id == store.CHANNEL_EXISTS_ERROR {
|
||||||
return result.Data.(*model.Channel), result.Err
|
return channel, err
|
||||||
}
|
}
|
||||||
return nil, result.Err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := result.Data.(*model.Channel)
|
|
||||||
|
|
||||||
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); result.Err != nil {
|
if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(userId, channel.Id, model.GetMillis()); result.Err != nil {
|
||||||
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ func (a *App) BulkImport(fileReader io.Reader, dryRun bool, workers int) (*model
|
|||||||
}
|
}
|
||||||
|
|
||||||
if lineNumber == 1 {
|
if lineNumber == 1 {
|
||||||
importDataFileVersion, apperr := processImportDataFileVersionLine(line)
|
importDataFileVersion, appErr := processImportDataFileVersionLine(line)
|
||||||
if apperr != nil {
|
if appErr != nil {
|
||||||
return apperr, lineNumber
|
return appErr, lineNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
if importDataFileVersion != 1 {
|
if importDataFileVersion != 1 {
|
||||||
|
|||||||
@@ -1136,8 +1136,8 @@ func (a *App) ImportDirectChannel(data *DirectChannelImportData, dryRun bool) *m
|
|||||||
|
|
||||||
if data.Header != nil {
|
if data.Header != nil {
|
||||||
channel.Header = *data.Header
|
channel.Header = *data.Header
|
||||||
if _, apperr := a.Srv.Store.Channel().Update(channel); apperr != nil {
|
if _, appErr := a.Srv.Store.Channel().Update(channel); appErr != nil {
|
||||||
return model.NewAppError("BulkImport", "app.import.import_direct_channel.update_header_failed.error", nil, apperr.Error(), http.StatusBadRequest)
|
return model.NewAppError("BulkImport", "app.import.import_direct_channel.update_header_failed.error", nil, appErr.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -487,7 +487,7 @@ func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) CreateDirectChannel(userId string, otherUserId string) store.StoreChannel {
|
func (s SqlChannelStore) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||||
channel := new(model.Channel)
|
channel := new(model.Channel)
|
||||||
|
|
||||||
channel.DisplayName = ""
|
channel.DisplayName = ""
|
||||||
@@ -510,35 +510,35 @@ func (s SqlChannelStore) CreateDirectChannel(userId string, otherUserId string)
|
|||||||
return s.SaveDirectChannel(channel, cm1, cm2)
|
return s.SaveDirectChannel(channel, cm1, cm2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) store.StoreChannel {
|
func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
|
||||||
if directchannel.DeleteAt != 0 {
|
if directchannel.DeleteAt != 0 {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("SqlChannelStore.Save", "store.sql_channel.save.archived_channel.app_error", nil, "", http.StatusBadRequest)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if directchannel.Type != model.CHANNEL_DIRECT {
|
if directchannel.Type != model.CHANNEL_DIRECT {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.not_direct.app_error", nil, "", http.StatusBadRequest)
|
return nil, model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.not_direct.app_error", nil, "", http.StatusBadRequest)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction, err := s.GetMaster().Begin()
|
transaction, err := s.GetMaster().Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer finalizeTransaction(transaction)
|
defer finalizeTransaction(transaction)
|
||||||
|
|
||||||
directchannel.TeamId = ""
|
directchannel.TeamId = ""
|
||||||
|
// After updating saveChannelT() should be:
|
||||||
|
// newChannel, appErr := s.saveChannelT(transaction, directchannel, 0)
|
||||||
channelResult := s.saveChannelT(transaction, directchannel, 0)
|
channelResult := s.saveChannelT(transaction, directchannel, 0)
|
||||||
|
var newChannel *model.Channel
|
||||||
|
if channelResult.Data != nil {
|
||||||
|
newChannel = channelResult.Data.(*model.Channel)
|
||||||
|
}
|
||||||
|
appErr := channelResult.Err
|
||||||
|
|
||||||
if channelResult.Err != nil {
|
if appErr != nil {
|
||||||
result.Err = channelResult.Err
|
return newChannel, appErr
|
||||||
result.Data = channelResult.Data
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newChannel := channelResult.Data.(*model.Channel)
|
|
||||||
// Members need new channel ID
|
// Members need new channel ID
|
||||||
member1.ChannelId = newChannel.Id
|
member1.ChannelId = newChannel.Id
|
||||||
member2.ChannelId = newChannel.Id
|
member2.ChannelId = newChannel.Id
|
||||||
@@ -557,17 +557,15 @@ func (s SqlChannelStore) SaveDirectChannel(directchannel *model.Channel, member1
|
|||||||
if member2Result.Err != nil {
|
if member2Result.Err != nil {
|
||||||
details += "Member2Err: " + member2Result.Err.Message
|
details += "Member2Err: " + member2Result.Err.Message
|
||||||
}
|
}
|
||||||
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.add_members.app_error", nil, details, http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.add_members.app_error", nil, details, http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := transaction.Commit(); err != nil {
|
if err := transaction.Commit(); err != nil {
|
||||||
result.Err = model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.commit.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("SqlChannelStore.SaveDirectChannel", "store.sql_channel.save_direct_channel.commit.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*result = channelResult
|
return newChannel, nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *model.Channel, maxChannelsPerTeam int64) store.StoreResult {
|
func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *model.Channel, maxChannelsPerTeam int64) store.StoreResult {
|
||||||
@@ -621,9 +619,9 @@ func (s SqlChannelStore) Update(channel *model.Channel) (*model.Channel, *model.
|
|||||||
}
|
}
|
||||||
defer finalizeTransaction(transaction)
|
defer finalizeTransaction(transaction)
|
||||||
|
|
||||||
updatedChannel, apperr := s.updateChannelT(transaction, channel)
|
updatedChannel, appErr := s.updateChannelT(transaction, channel)
|
||||||
if apperr != nil {
|
if appErr != nil {
|
||||||
return nil, apperr
|
return nil, appErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additionally propagate the write to the PublicChannels table.
|
// Additionally propagate the write to the PublicChannels table.
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ type TeamStore interface {
|
|||||||
|
|
||||||
type ChannelStore interface {
|
type ChannelStore interface {
|
||||||
Save(channel *model.Channel, maxChannelsPerTeam int64) StoreChannel
|
Save(channel *model.Channel, maxChannelsPerTeam int64) StoreChannel
|
||||||
CreateDirectChannel(userId string, otherUserId string) StoreChannel
|
CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError)
|
||||||
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) StoreChannel
|
SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, *model.AppError)
|
||||||
Update(channel *model.Channel) (*model.Channel, *model.AppError)
|
Update(channel *model.Channel) (*model.Channel, *model.AppError)
|
||||||
Get(id string, allowFromCache bool) (*model.Channel, *model.AppError)
|
Get(id string, allowFromCache bool) (*model.Channel, *model.AppError)
|
||||||
InvalidateChannel(id string)
|
InvalidateChannel(id string)
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSuppli
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
if err := (<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err != nil {
|
if _, err := ss.Channel().SaveDirectChannel(&o1, &m1, &m2); err != nil {
|
||||||
t.Fatal("couldn't save direct channel", err)
|
t.Fatal("couldn't save direct channel", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSuppli
|
|||||||
t.Fatal("should have saved 2 members")
|
t.Fatal("should have saved 2 members")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := (<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
|
if _, err := ss.Channel().SaveDirectChannel(&o1, &m1, &m2); err == nil {
|
||||||
t.Fatal("shouldn't be able to update from save")
|
t.Fatal("shouldn't be able to update from save")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,11 +170,12 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSuppli
|
|||||||
Type: o1.Type,
|
Type: o1.Type,
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-ss.Channel().SaveDirectChannel(&o1a, &m1, &m2); result.Err == nil {
|
returnedChannel, err := ss.Channel().SaveDirectChannel(&o1a, &m1, &m2)
|
||||||
|
if err == nil {
|
||||||
t.Fatal("should've failed to save a duplicate direct channel")
|
t.Fatal("should've failed to save a duplicate direct channel")
|
||||||
} else if result.Err.Id != store.CHANNEL_EXISTS_ERROR {
|
} else if err.Id != store.CHANNEL_EXISTS_ERROR {
|
||||||
t.Fatal("should've returned CHANNEL_EXISTS_ERROR")
|
t.Fatal("should've returned CHANNEL_EXISTS_ERROR")
|
||||||
} else if returned := result.Data.(*model.Channel); returned.Id != o1.Id {
|
} else if returnedChannel.Id != o1.Id {
|
||||||
t.Fatal("should've returned original channel when saving a duplicate direct channel")
|
t.Fatal("should've returned original channel when saving a duplicate direct channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +183,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSuppli
|
|||||||
o1.Id = ""
|
o1.Id = ""
|
||||||
o1.Name = "zz" + model.NewId() + "b"
|
o1.Name = "zz" + model.NewId() + "b"
|
||||||
o1.Type = model.CHANNEL_OPEN
|
o1.Type = model.CHANNEL_OPEN
|
||||||
if err := (<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)).Err; err == nil {
|
if _, err := ss.Channel().SaveDirectChannel(&o1, &m1, &m2); err == nil {
|
||||||
t.Fatal("Should not be able to save non-direct channel")
|
t.Fatal("Should not be able to save non-direct channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +192,7 @@ func testChannelStoreSaveDirectChannel(t *testing.T, ss store.Store, s SqlSuppli
|
|||||||
o1.DisplayName = "Myself"
|
o1.DisplayName = "Myself"
|
||||||
o1.Name = "zz" + model.NewId() + "b"
|
o1.Name = "zz" + model.NewId() + "b"
|
||||||
o1.Type = model.CHANNEL_DIRECT
|
o1.Type = model.CHANNEL_DIRECT
|
||||||
if err := (<-ss.Channel().SaveDirectChannel(&o1, &m1, &m1)).Err; err != nil {
|
if _, err := ss.Channel().SaveDirectChannel(&o1, &m1, &m1); err != nil {
|
||||||
t.Fatal("couldn't save direct channel", err)
|
t.Fatal("couldn't save direct channel", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,11 +218,10 @@ func testChannelStoreCreateDirectChannel(t *testing.T, ss store.Store) {
|
|||||||
store.Must(ss.User().Save(u2))
|
store.Must(ss.User().Save(u2))
|
||||||
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}, -1))
|
store.Must(ss.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u2.Id}, -1))
|
||||||
|
|
||||||
res := <-ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
c1, err := ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||||
if res.Err != nil {
|
if err != nil {
|
||||||
t.Fatal("couldn't create direct channel", res.Err)
|
t.Fatal("couldn't create direct channel", err)
|
||||||
}
|
}
|
||||||
c1 := res.Data.(*model.Channel)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
<-ss.Channel().PermanentDeleteMembersByChannel(c1.Id)
|
<-ss.Channel().PermanentDeleteMembersByChannel(c1.Id)
|
||||||
<-ss.Channel().PermanentDelete(c1.Id)
|
<-ss.Channel().PermanentDelete(c1.Id)
|
||||||
@@ -394,7 +394,8 @@ func testChannelStoreGet(t *testing.T, ss store.Store, s SqlSupplier) {
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
store.Must(ss.Channel().SaveDirectChannel(&o2, &m1, &m2))
|
_, err := ss.Channel().SaveDirectChannel(&o2, &m1, &m2)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
if c2, err := ss.Channel().Get(o2.Id, false); err != nil {
|
if c2, err := ss.Channel().Get(o2.Id, false); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -469,7 +470,8 @@ func testChannelStoreGetChannelsByIds(t *testing.T, ss store.Store) {
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
store.Must(ss.Channel().SaveDirectChannel(&o2, &m1, &m2))
|
_, err := ss.Channel().SaveDirectChannel(&o2, &m1, &m2)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
if r1 := <-ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id}); r1.Err != nil {
|
if r1 := <-ss.Channel().GetChannelsByIds([]string{o1.Id, o2.Id}); r1.Err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(r1.Err)
|
||||||
@@ -1089,7 +1091,8 @@ func testChannelStoreGetAllChannels(t *testing.T, ss store.Store, s SqlSupplier)
|
|||||||
c3.Type = model.CHANNEL_PRIVATE
|
c3.Type = model.CHANNEL_PRIVATE
|
||||||
store.Must(ss.Channel().Save(&c3, -1))
|
store.Must(ss.Channel().Save(&c3, -1))
|
||||||
|
|
||||||
store.Must(ss.Channel().CreateDirectChannel(model.NewId(), model.NewId()))
|
_, err = ss.Channel().CreateDirectChannel(model.NewId(), model.NewId())
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
userIds := []string{model.NewId(), model.NewId(), model.NewId()}
|
userIds := []string{model.NewId(), model.NewId(), model.NewId()}
|
||||||
|
|
||||||
@@ -2494,8 +2497,10 @@ func testChannelStoreAutocompleteInTeamForSearch(t *testing.T, ss store.Store, s
|
|||||||
o5.Type = model.CHANNEL_PRIVATE
|
o5.Type = model.CHANNEL_PRIVATE
|
||||||
store.Must(ss.Channel().Save(&o5, -1))
|
store.Must(ss.Channel().Save(&o5, -1))
|
||||||
|
|
||||||
store.Must(ss.Channel().CreateDirectChannel(u1.Id, u2.Id))
|
_, err = ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||||
store.Must(ss.Channel().CreateDirectChannel(u2.Id, u3.Id))
|
require.Nil(t, err)
|
||||||
|
_, err = ss.Channel().CreateDirectChannel(u2.Id, u3.Id)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
tt := []struct {
|
tt := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -2601,11 +2606,9 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
|
|||||||
u2.Nickname = model.NewId()
|
u2.Nickname = model.NewId()
|
||||||
store.Must(ss.User().Save(u2))
|
store.Must(ss.User().Save(u2))
|
||||||
|
|
||||||
var d4 *model.Channel
|
d4, err := ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||||
if result := <-ss.Channel().CreateDirectChannel(u1.Id, u2.Id); result.Err != nil {
|
if err != nil {
|
||||||
t.Fatalf(result.Err.Error())
|
t.Fatalf(err.Error())
|
||||||
} else {
|
|
||||||
d4 = result.Data.(*model.Channel)
|
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
<-ss.Channel().PermanentDeleteMembersByChannel(d4.Id)
|
<-ss.Channel().PermanentDeleteMembersByChannel(d4.Id)
|
||||||
@@ -2633,7 +2636,7 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
|
|||||||
directStartCount = result.Data.(int64)
|
directStartCount = result.Data.(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := ss.Channel().Delete(o1.Id, model.GetMillis())
|
err = ss.Channel().Delete(o1.Id, model.GetMillis())
|
||||||
require.Nil(t, err, "channel should have been deleted")
|
require.Nil(t, err, "channel should have been deleted")
|
||||||
err = ss.Channel().Delete(o2.Id, model.GetMillis())
|
err = ss.Channel().Delete(o2.Id, model.GetMillis())
|
||||||
require.Nil(t, err, "channel should have been deleted")
|
require.Nil(t, err, "channel should have been deleted")
|
||||||
@@ -3015,8 +3018,8 @@ func testMaterializedPublicChannels(t *testing.T, ss store.Store, s SqlSupplier)
|
|||||||
})
|
})
|
||||||
|
|
||||||
o2.Type = model.CHANNEL_PRIVATE
|
o2.Type = model.CHANNEL_PRIVATE
|
||||||
_, apperr := ss.Channel().Update(&o2)
|
_, appErr := ss.Channel().Update(&o2)
|
||||||
require.Nil(t, apperr)
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
t.Run("o2 no longer listed since now private", func(t *testing.T) {
|
t.Run("o2 no longer listed since now private", func(t *testing.T) {
|
||||||
result := <-ss.Channel().SearchInTeam(teamId, "", true)
|
result := <-ss.Channel().SearchInTeam(teamId, "", true)
|
||||||
@@ -3025,8 +3028,8 @@ func testMaterializedPublicChannels(t *testing.T, ss store.Store, s SqlSupplier)
|
|||||||
})
|
})
|
||||||
|
|
||||||
o2.Type = model.CHANNEL_OPEN
|
o2.Type = model.CHANNEL_OPEN
|
||||||
_, apperr = ss.Channel().Update(&o2)
|
_, appErr = ss.Channel().Update(&o2)
|
||||||
require.Nil(t, apperr)
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
t.Run("o2 listed once again since now public", func(t *testing.T) {
|
t.Run("o2 listed once again since now public", func(t *testing.T) {
|
||||||
result := <-ss.Channel().SearchInTeam(teamId, "", true)
|
result := <-ss.Channel().SearchInTeam(teamId, "", true)
|
||||||
@@ -3111,8 +3114,8 @@ func testMaterializedPublicChannels(t *testing.T, ss store.Store, s SqlSupplier)
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
o4.DisplayName += " - Modified"
|
o4.DisplayName += " - Modified"
|
||||||
_, apperr = ss.Channel().Update(&o4)
|
_, appErr = ss.Channel().Update(&o4)
|
||||||
require.Nil(t, apperr)
|
require.Nil(t, appErr)
|
||||||
|
|
||||||
t.Run("verify o4 UPDATE converted to INSERT", func(t *testing.T) {
|
t.Run("verify o4 UPDATE converted to INSERT", func(t *testing.T) {
|
||||||
result := <-ss.Channel().SearchInTeam(teamId, "", true)
|
result := <-ss.Channel().SearchInTeam(teamId, "", true)
|
||||||
@@ -3318,7 +3321,7 @@ func testChannelStoreExportAllDirectChannels(t *testing.T, ss store.Store, s Sql
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
||||||
|
|
||||||
r1 := <-ss.Channel().GetAllDirectChannelsForExportAfter(10000, strings.Repeat("0", 26))
|
r1 := <-ss.Channel().GetAllDirectChannelsForExportAfter(10000, strings.Repeat("0", 26))
|
||||||
assert.Nil(t, r1.Err)
|
assert.Nil(t, r1.Err)
|
||||||
@@ -3376,7 +3379,7 @@ func testChannelStoreExportAllDirectChannelsExcludePrivateAndPublic(t *testing.T
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
||||||
|
|
||||||
r1 := <-ss.Channel().GetAllDirectChannelsForExportAfter(10000, strings.Repeat("0", 26))
|
r1 := <-ss.Channel().GetAllDirectChannelsForExportAfter(10000, strings.Repeat("0", 26))
|
||||||
assert.Nil(t, r1.Err)
|
assert.Nil(t, r1.Err)
|
||||||
@@ -3419,7 +3422,7 @@ func testChannelStoreExportAllDirectChannelsDeletedChannel(t *testing.T, ss stor
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
_ = <-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
||||||
|
|
||||||
o1.DeleteAt = 1
|
o1.DeleteAt = 1
|
||||||
err := ss.Channel().SetDeleteAt(o1.Id, 1, 1)
|
err := ss.Channel().SetDeleteAt(o1.Id, 1, 1)
|
||||||
|
|||||||
@@ -192,8 +192,8 @@ func testComplianceExportDirectMessages(t *testing.T, ss store.Store) {
|
|||||||
c1.Type = model.CHANNEL_OPEN
|
c1.Type = model.CHANNEL_OPEN
|
||||||
c1 = store.Must(ss.Channel().Save(c1, -1)).(*model.Channel)
|
c1 = store.Must(ss.Channel().Save(c1, -1)).(*model.Channel)
|
||||||
|
|
||||||
cDM := store.Must(ss.Channel().CreateDirectChannel(u1.Id, u2.Id)).(*model.Channel)
|
cDM, err := ss.Channel().CreateDirectChannel(u1.Id, u2.Id)
|
||||||
|
require.Nil(t, err)
|
||||||
o1 := &model.Post{}
|
o1 := &model.Post{}
|
||||||
o1.ChannelId = c1.Id
|
o1.ChannelId = c1.Id
|
||||||
o1.UserId = u1.Id
|
o1.UserId = u1.Id
|
||||||
@@ -470,7 +470,8 @@ func testMessageExportDirectMessageChannel(t *testing.T, ss store.Store) {
|
|||||||
}, -1))
|
}, -1))
|
||||||
|
|
||||||
// as well as a DM channel between those users
|
// as well as a DM channel between those users
|
||||||
directMessageChannel := store.Must(ss.Channel().CreateDirectChannel(user1.Id, user2.Id)).(*model.Channel)
|
directMessageChannel, err := ss.Channel().CreateDirectChannel(user1.Id, user2.Id)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
// user1 also sends a DM to user2
|
// user1 also sends a DM to user2
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
|
|||||||
@@ -99,19 +99,28 @@ func (_m *ChannelStore) ClearCaches() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateDirectChannel provides a mock function with given fields: userId, otherUserId
|
// CreateDirectChannel provides a mock function with given fields: userId, otherUserId
|
||||||
func (_m *ChannelStore) CreateDirectChannel(userId string, otherUserId string) store.StoreChannel {
|
func (_m *ChannelStore) CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
|
||||||
ret := _m.Called(userId, otherUserId)
|
ret := _m.Called(userId, otherUserId)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Channel
|
||||||
if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, string) *model.Channel); ok {
|
||||||
r0 = rf(userId, otherUserId)
|
r0 = rf(userId, otherUserId)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.Channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
|
||||||
|
r1 = rf(userId, otherUserId)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete provides a mock function with given fields: channelId, time
|
// Delete provides a mock function with given fields: channelId, time
|
||||||
@@ -954,19 +963,28 @@ func (_m *ChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64) s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SaveDirectChannel provides a mock function with given fields: channel, member1, member2
|
// SaveDirectChannel provides a mock function with given fields: channel, member1, member2
|
||||||
func (_m *ChannelStore) SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) store.StoreChannel {
|
func (_m *ChannelStore) SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, *model.AppError) {
|
||||||
ret := _m.Called(channel, member1, member2)
|
ret := _m.Called(channel, member1, member2)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 *model.Channel
|
||||||
if rf, ok := ret.Get(0).(func(*model.Channel, *model.ChannelMember, *model.ChannelMember) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(*model.Channel, *model.ChannelMember, *model.ChannelMember) *model.Channel); ok {
|
||||||
r0 = rf(channel, member1, member2)
|
r0 = rf(channel, member1, member2)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
r0 = ret.Get(0).(*model.Channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(*model.Channel, *model.ChannelMember, *model.ChannelMember) *model.AppError); ok {
|
||||||
|
r1 = rf(channel, member1, member2)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveMember provides a mock function with given fields: member
|
// SaveMember provides a mock function with given fields: member
|
||||||
|
|||||||
@@ -1251,7 +1251,8 @@ func testPostStoreGetFlaggedPostsForTeam(t *testing.T, ss store.Store, s SqlSupp
|
|||||||
m2.UserId = model.NewId()
|
m2.UserId = model.NewId()
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
c2 = store.Must(ss.Channel().SaveDirectChannel(c2, m1, m2)).(*model.Channel)
|
c2, err := ss.Channel().SaveDirectChannel(c2, m1, m2)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
o5 := &model.Post{}
|
o5 := &model.Post{}
|
||||||
o5.ChannelId = c2.Id
|
o5.ChannelId = c2.Id
|
||||||
@@ -2018,7 +2019,7 @@ func testPostStoreGetDirectPostParentsForExportAfter(t *testing.T, ss store.Stor
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
||||||
|
|
||||||
p1 := &model.Post{}
|
p1 := &model.Post{}
|
||||||
p1.ChannelId = o1.Id
|
p1.ChannelId = o1.Id
|
||||||
@@ -2070,7 +2071,7 @@ func testPostStoreGetDirectPostParentsForExportAfterDeleted(t *testing.T, ss sto
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
||||||
|
|
||||||
o1.DeleteAt = 1
|
o1.DeleteAt = 1
|
||||||
err := ss.Channel().SetDeleteAt(o1.Id, 1, 1)
|
err := ss.Channel().SetDeleteAt(o1.Id, 1, 1)
|
||||||
@@ -2134,7 +2135,7 @@ func testPostStoreGetDirectPostParentsForExportAfterBatched(t *testing.T, ss sto
|
|||||||
m2.UserId = u2.Id
|
m2.UserId = u2.Id
|
||||||
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
m2.NotifyProps = model.GetDefaultChannelNotifyProps()
|
||||||
|
|
||||||
<-ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
ss.Channel().SaveDirectChannel(&o1, &m1, &m2)
|
||||||
|
|
||||||
p1 := &model.Post{}
|
p1 := &model.Post{}
|
||||||
p1.ChannelId = o1.Id
|
p1.ChannelId = o1.Id
|
||||||
|
|||||||
@@ -1689,7 +1689,7 @@ func testUserUnreadCount(t *testing.T, ss store.Store) {
|
|||||||
m1.ChannelId = c2.Id
|
m1.ChannelId = c2.Id
|
||||||
m2.ChannelId = c2.Id
|
m2.ChannelId = c2.Id
|
||||||
|
|
||||||
if err := (<-ss.Channel().SaveDirectChannel(&c2, &m1, &m2)).Err; err != nil {
|
if _, err := ss.Channel().SaveDirectChannel(&c2, &m1, &m2); err != nil {
|
||||||
t.Fatal("couldn't save direct channel", err)
|
t.Fatal("couldn't save direct channel", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user