[GH-19150] Remove strings in all channel types for constants (#19535)
Automatic Merge
Этот коммит содержится в:
@@ -62,7 +62,7 @@ func TestChannelIsValid(t *testing.T) {
|
|||||||
o.Type = "U"
|
o.Type = "U"
|
||||||
require.NotNil(t, o.IsValid())
|
require.NotNil(t, o.IsValid())
|
||||||
|
|
||||||
o.Type = "P"
|
o.Type = ChannelTypePrivate
|
||||||
require.Nil(t, o.IsValid())
|
require.Nil(t, o.IsValid())
|
||||||
|
|
||||||
o.Header = strings.Repeat("01234567890", 100)
|
o.Header = strings.Repeat("01234567890", 100)
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func (worker *BleveIndexerWorker) DoJob(job *model.Job) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Same possible fail as above can happen when counting channels
|
// Same possible fail as above can happen when counting channels
|
||||||
if count, err := worker.jobServer.Store.Channel().AnalyticsTypeCount("", "O"); err != nil {
|
if count, err := worker.jobServer.Store.Channel().AnalyticsTypeCount("", model.ChannelTypeOpen); err != nil {
|
||||||
mlog.Warn("Worker: Failed to fetch total channel count for job. An estimated value will be used for progress reporting.", mlog.String("workername", worker.name), mlog.String("job_id", job.Id), mlog.Err(err))
|
mlog.Warn("Worker: Failed to fetch total channel count for job. An estimated value will be used for progress reporting.", mlog.String("workername", worker.name), mlog.String("job_id", job.Id), mlog.Err(err))
|
||||||
progress.TotalChannelsCount = EstimatedChannelCount
|
progress.TotalChannelsCount = EstimatedChannelCount
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func TestSlackParseChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
channels, err := slackParseChannels(file, "O")
|
channels, err := slackParseChannels(file, model.ChannelTypeOpen)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 6, len(channels))
|
assert.Equal(t, 6, len(channels))
|
||||||
}
|
}
|
||||||
@@ -127,7 +127,7 @@ func TestSlackParseDirectMessages(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
channels, err := slackParseChannels(file, "D")
|
channels, err := slackParseChannels(file, model.ChannelTypeDirect)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 4, len(channels))
|
assert.Equal(t, 4, len(channels))
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ func TestSlackParsePrivateChannels(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
channels, err := slackParseChannels(file, "P")
|
channels, err := slackParseChannels(file, model.ChannelTypePrivate)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 1, len(channels))
|
assert.Equal(t, 1, len(channels))
|
||||||
}
|
}
|
||||||
@@ -147,7 +147,7 @@ func TestSlackParseGroupDirectMessages(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
channels, err := slackParseChannels(file, "G")
|
channels, err := slackParseChannels(file, model.ChannelTypeGroup)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 3, len(channels))
|
assert.Equal(t, 3, len(channels))
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ func TestOldImportChannel(t *testing.T) {
|
|||||||
config.SetDefaults()
|
config.SetDefaults()
|
||||||
|
|
||||||
t.Run("No panic on direct channel", func(t *testing.T) {
|
t.Run("No panic on direct channel", func(t *testing.T) {
|
||||||
//ch := th.CreateDmChannel(u1)
|
// ch := th.CreateDmChannel(u1)
|
||||||
ch := &model.Channel{
|
ch := &model.Channel{
|
||||||
Type: model.ChannelTypeDirect,
|
Type: model.ChannelTypeDirect,
|
||||||
Name: "test-channel",
|
Name: "test-channel",
|
||||||
|
|||||||
@@ -277,23 +277,23 @@ func (ts *TelemetryService) trackActivity() {
|
|||||||
mlog.Info("Could not get team count", mlog.Err(err))
|
mlog.Info("Could not get team count", mlog.Err(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ucc, err := ts.dbStore.Channel().AnalyticsTypeCount("", "O"); err == nil {
|
if ucc, err := ts.dbStore.Channel().AnalyticsTypeCount("", model.ChannelTypeOpen); err == nil {
|
||||||
publicChannelCount = ucc
|
publicChannelCount = ucc
|
||||||
}
|
}
|
||||||
|
|
||||||
if pcc, err := ts.dbStore.Channel().AnalyticsTypeCount("", "P"); err == nil {
|
if pcc, err := ts.dbStore.Channel().AnalyticsTypeCount("", model.ChannelTypePrivate); err == nil {
|
||||||
privateChannelCount = pcc
|
privateChannelCount = pcc
|
||||||
}
|
}
|
||||||
|
|
||||||
if dcc, err := ts.dbStore.Channel().AnalyticsTypeCount("", "D"); err == nil {
|
if dcc, err := ts.dbStore.Channel().AnalyticsTypeCount("", model.ChannelTypeDirect); err == nil {
|
||||||
directChannelCount = dcc
|
directChannelCount = dcc
|
||||||
}
|
}
|
||||||
|
|
||||||
if duccr, err := ts.dbStore.Channel().AnalyticsDeletedTypeCount("", "O"); err == nil {
|
if duccr, err := ts.dbStore.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypeOpen); err == nil {
|
||||||
deletedPublicChannelCount = duccr
|
deletedPublicChannelCount = duccr
|
||||||
}
|
}
|
||||||
|
|
||||||
if dpccr, err := ts.dbStore.Channel().AnalyticsDeletedTypeCount("", "P"); err == nil {
|
if dpccr, err := ts.dbStore.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypePrivate); err == nil {
|
||||||
deletedPrivateChannelCount = dpccr
|
deletedPrivateChannelCount = dpccr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,8 +107,8 @@ func initializeMocks(cfg *model.Config) (*mocks.ServerIface, *storeMocks.Store,
|
|||||||
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeOpen).Return(int64(25), nil)
|
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeOpen).Return(int64(25), nil)
|
||||||
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypePrivate).Return(int64(26), nil)
|
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypePrivate).Return(int64(26), nil)
|
||||||
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeDirect).Return(int64(27), nil)
|
channelStore.On("AnalyticsTypeCount", "", model.ChannelTypeDirect).Return(int64(27), nil)
|
||||||
channelStore.On("AnalyticsDeletedTypeCount", "", "O").Return(int64(22), nil)
|
channelStore.On("AnalyticsDeletedTypeCount", "", model.ChannelTypeOpen).Return(int64(22), nil)
|
||||||
channelStore.On("AnalyticsDeletedTypeCount", "", "P").Return(int64(23), nil)
|
channelStore.On("AnalyticsDeletedTypeCount", "", model.ChannelTypePrivate).Return(int64(23), nil)
|
||||||
channelStore.On("GroupSyncedChannelCount").Return(int64(17), nil)
|
channelStore.On("GroupSyncedChannelCount").Return(int64(17), nil)
|
||||||
|
|
||||||
postStore := storeMocks.PostStore{}
|
postStore := storeMocks.PostStore{}
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ func (s *OpenTracingLayerBotStore) Update(bot *model.Bot) (*model.Bot, error) {
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *OpenTracingLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType string) (int64, error) {
|
func (s *OpenTracingLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType model.ChannelType) (int64, error) {
|
||||||
origCtx := s.Root.Store.Context()
|
origCtx := s.Root.Store.Context()
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AnalyticsDeletedTypeCount")
|
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "ChannelStore.AnalyticsDeletedTypeCount")
|
||||||
s.Root.Store.SetContext(newCtx)
|
s.Root.Store.SetContext(newCtx)
|
||||||
|
|||||||
@@ -577,7 +577,7 @@ func (s *RetryLayerBotStore) Update(bot *model.Bot) (*model.Bot, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RetryLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType string) (int64, error) {
|
func (s *RetryLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType model.ChannelType) (int64, error) {
|
||||||
|
|
||||||
tries := 0
|
tries := 0
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -693,7 +693,7 @@ func (s SqlChannelStore) saveChannelT(transaction *sqlxTxWrapper, channel *model
|
|||||||
|
|
||||||
if channel.Type != model.ChannelTypeDirect && channel.Type != model.ChannelTypeGroup && maxChannelsPerTeam >= 0 {
|
if channel.Type != model.ChannelTypeDirect && channel.Type != model.ChannelTypeGroup && maxChannelsPerTeam >= 0 {
|
||||||
var count int64
|
var count int64
|
||||||
if err := transaction.Get(&count, "SELECT COUNT(0) FROM Channels WHERE TeamId = ? AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", channel.TeamId); err != nil {
|
if err := transaction.Get(&count, "SELECT COUNT(0) FROM Channels WHERE TeamId = ? AND DeleteAt = 0 AND (Type = ? OR Type = ?)", channel.TeamId, model.ChannelTypeOpen, model.ChannelTypePrivate); err != nil {
|
||||||
return nil, errors.Wrapf(err, "save_channel_count: teamId=%s", channel.TeamId)
|
return nil, errors.Wrapf(err, "save_channel_count: teamId=%s", channel.TeamId)
|
||||||
} else if count >= maxChannelsPerTeam {
|
} else if count >= maxChannelsPerTeam {
|
||||||
return nil, store.NewErrLimitExceeded("channels_per_team", int(count), "teamId="+channel.TeamId)
|
return nil, store.NewErrLimitExceeded("channels_per_team", int(count), "teamId="+channel.TeamId)
|
||||||
@@ -1439,7 +1439,7 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) (*model.
|
|||||||
|
|
||||||
func (s SqlChannelStore) GetTeamChannels(teamId string) (model.ChannelList, error) {
|
func (s SqlChannelStore) GetTeamChannels(teamId string) (model.ChannelList, error) {
|
||||||
data := model.ChannelList{}
|
data := model.ChannelList{}
|
||||||
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? And Type != 'D' ORDER BY DisplayName", teamId)
|
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? And Type != ? ORDER BY DisplayName", teamId, model.ChannelTypeDirect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
|
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
|
||||||
}
|
}
|
||||||
@@ -1583,17 +1583,17 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId
|
|||||||
SELECT * FROM Channels
|
SELECT * FROM Channels
|
||||||
WHERE (TeamId = ? OR TeamId = '')
|
WHERE (TeamId = ? OR TeamId = '')
|
||||||
AND DeleteAt != 0
|
AND DeleteAt != 0
|
||||||
AND Type != 'P'
|
AND Type != ?
|
||||||
UNION
|
UNION
|
||||||
SELECT * FROM Channels
|
SELECT * FROM Channels
|
||||||
WHERE (TeamId = ? OR TeamId = '')
|
WHERE (TeamId = ? OR TeamId = '')
|
||||||
AND DeleteAt != 0
|
AND DeleteAt != 0
|
||||||
AND Type = 'P'
|
AND Type = ?
|
||||||
AND Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = ?)
|
AND Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = ?)
|
||||||
ORDER BY DisplayName LIMIT ? OFFSET ?
|
ORDER BY DisplayName LIMIT ? OFFSET ?
|
||||||
`
|
`
|
||||||
|
|
||||||
if err := s.GetReplicaX().Select(&channels, query, teamId, teamId, userId, limit, offset); err != nil {
|
if err := s.GetReplicaX().Select(&channels, query, teamId, model.ChannelTypePrivate, teamId, model.ChannelTypePrivate, userId, limit, offset); err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s,UserId=%s", teamId, userId))
|
return nil, store.NewErrNotFound("Channel", fmt.Sprintf("TeamId=%s,UserId=%s", teamId, userId))
|
||||||
}
|
}
|
||||||
@@ -2640,7 +2640,7 @@ func (s SqlChannelStore) IncrementMentionCount(channelId string, userId string,
|
|||||||
|
|
||||||
func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
|
func (s SqlChannelStore) GetAll(teamId string) ([]*model.Channel, error) {
|
||||||
data := []*model.Channel{}
|
data := []*model.Channel{}
|
||||||
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? AND Type != 'D' ORDER BY Name", teamId)
|
err := s.GetReplicaX().Select(&data, "SELECT * FROM Channels WHERE TeamId = ? AND Type != ? ORDER BY Name", teamId, model.ChannelTypeDirect)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
|
return nil, errors.Wrapf(err, "failed to find Channels with teamId=%s", teamId)
|
||||||
@@ -2743,7 +2743,7 @@ func (s SqlChannelStore) AnalyticsTypeCount(teamId string, channelType model.Cha
|
|||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, error) {
|
func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType model.ChannelType) (int64, error) {
|
||||||
query := s.getQueryBuilder().
|
query := s.getQueryBuilder().
|
||||||
Select("COUNT(Id) AS Value").
|
Select("COUNT(Id) AS Value").
|
||||||
From("Channels").
|
From("Channels").
|
||||||
@@ -2879,15 +2879,16 @@ func (s SqlChannelStore) Autocomplete(userID, term string, includeDeleted bool)
|
|||||||
`+deleteFilter+`
|
`+deleteFilter+`
|
||||||
SEARCH_CLAUSE
|
SEARCH_CLAUSE
|
||||||
AND (
|
AND (
|
||||||
c.Type != 'P'
|
c.Type != :ChannelType
|
||||||
OR (
|
OR (
|
||||||
c.Type = 'P'
|
c.Type = :ChannelType
|
||||||
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
|
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
ORDER BY c.DisplayName
|
ORDER BY c.DisplayName
|
||||||
`, term, map[string]interface{}{
|
`, term, map[string]interface{}{
|
||||||
"UserId": userID,
|
"UserId": userID,
|
||||||
|
"ChannelType": model.ChannelTypePrivate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2908,18 +2909,19 @@ func (s SqlChannelStore) AutocompleteInTeam(teamID, userID, term string, include
|
|||||||
`+deleteFilter+`
|
`+deleteFilter+`
|
||||||
SEARCH_CLAUSE
|
SEARCH_CLAUSE
|
||||||
AND (
|
AND (
|
||||||
c.Type != 'P'
|
c.Type != :ChannelType
|
||||||
OR (
|
OR (
|
||||||
c.Type = 'P'
|
c.Type = :ChannelType
|
||||||
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
|
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
ORDER BY c.DisplayName
|
ORDER BY c.DisplayName
|
||||||
LIMIT :Limit
|
LIMIT :Limit
|
||||||
`, term, map[string]interface{}{
|
`, term, map[string]interface{}{
|
||||||
"TeamId": teamID,
|
"TeamId": teamID,
|
||||||
"UserId": userID,
|
"UserId": userID,
|
||||||
"Limit": model.ChannelSearchDefaultLimit,
|
"Limit": model.ChannelSearchDefaultLimit,
|
||||||
|
"ChannelType": model.ChannelTypePrivate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2938,7 +2940,7 @@ func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId strin
|
|||||||
JOIN
|
JOIN
|
||||||
ChannelMembers AS CM ON CM.ChannelId = C.Id
|
ChannelMembers AS CM ON CM.ChannelId = C.Id
|
||||||
WHERE
|
WHERE
|
||||||
(C.TeamId = :TeamId OR (C.TeamId = '' AND C.Type = 'G'))
|
(C.TeamId = :TeamId OR (C.TeamId = '' AND C.Type = :ChannelType))
|
||||||
AND CM.UserId = :UserId
|
AND CM.UserId = :UserId
|
||||||
` + deleteFilter + `
|
` + deleteFilter + `
|
||||||
%v
|
%v
|
||||||
@@ -2947,7 +2949,7 @@ func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId strin
|
|||||||
var channels model.ChannelList
|
var channels model.ChannelList
|
||||||
|
|
||||||
if likeClause, likeTerm := s.buildLIKEClause(term, "Name, DisplayName, Purpose"); likeClause == "" {
|
if likeClause, likeTerm := s.buildLIKEClause(term, "Name, DisplayName, Purpose"); likeClause == "" {
|
||||||
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"TeamId": teamId, "UserId": userId}); err != nil {
|
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"TeamId": teamId, "UserId": userId, "ChannelType": model.ChannelTypeGroup}); err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -2958,7 +2960,7 @@ func (s SqlChannelStore) AutocompleteInTeamForSearch(teamId string, userId strin
|
|||||||
fulltextQuery := fmt.Sprintf(queryFormat, "AND "+fulltextClause)
|
fulltextQuery := fmt.Sprintf(queryFormat, "AND "+fulltextClause)
|
||||||
query := fmt.Sprintf("(%v) UNION (%v) LIMIT 50", likeQuery, fulltextQuery)
|
query := fmt.Sprintf("(%v) UNION (%v) LIMIT 50", likeQuery, fulltextQuery)
|
||||||
|
|
||||||
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"TeamId": teamId, "UserId": userId, "LikeTerm": likeTerm, "FulltextTerm": fulltextTerm}); err != nil {
|
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"TeamId": teamId, "UserId": userId, "LikeTerm": likeTerm, "FulltextTerm": fulltextTerm, "ChannelType": model.ChannelTypeGroup}); err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2998,20 +3000,20 @@ func (s SqlChannelStore) autocompleteInTeamForSearchDirectMessages(userId string
|
|||||||
%v
|
%v
|
||||||
) AS OtherUsers ON OtherUsers.ChannelId = C.Id
|
) AS OtherUsers ON OtherUsers.ChannelId = C.Id
|
||||||
WHERE
|
WHERE
|
||||||
C.Type = 'D'
|
C.Type = :ChannelType
|
||||||
AND CM.UserId = :UserId
|
AND CM.UserId = :UserId
|
||||||
LIMIT 50`
|
LIMIT 50`
|
||||||
|
|
||||||
var channels model.ChannelList
|
var channels model.ChannelList
|
||||||
|
|
||||||
if likeClause, likeTerm := s.buildLIKEClause(term, "IU.Username, IU.Nickname"); likeClause == "" {
|
if likeClause, likeTerm := s.buildLIKEClause(term, "IU.Username, IU.Nickname"); likeClause == "" {
|
||||||
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"UserId": userId}); err != nil {
|
if _, err := s.GetReplica().Select(&channels, fmt.Sprintf(queryFormat, ""), map[string]interface{}{"UserId": userId, "ChannelType": model.ChannelTypeDirect}); err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
query := fmt.Sprintf(queryFormat, "AND "+likeClause)
|
query := fmt.Sprintf(queryFormat, "AND "+likeClause)
|
||||||
|
|
||||||
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"UserId": userId, "LikeTerm": likeTerm}); err != nil {
|
if _, err := s.GetReplica().Select(&channels, query, map[string]interface{}{"UserId": userId, "LikeTerm": likeTerm, "ChannelType": model.ChannelTypeDirect}); err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
return nil, errors.Wrapf(err, "failed to find Channels with term='%s'", term)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3057,12 +3059,13 @@ func (s SqlChannelStore) SearchArchivedInTeam(teamId string, term string, userId
|
|||||||
c.TeamId = :TeamId
|
c.TeamId = :TeamId
|
||||||
SEARCH_CLAUSE
|
SEARCH_CLAUSE
|
||||||
AND c.DeleteAt != 0
|
AND c.DeleteAt != 0
|
||||||
AND c.Type != 'P'
|
AND c.Type != :ChannelType
|
||||||
ORDER BY c.DisplayName
|
ORDER BY c.DisplayName
|
||||||
LIMIT 100
|
LIMIT 100
|
||||||
`, term, map[string]interface{}{
|
`, term, map[string]interface{}{
|
||||||
"TeamId": teamId,
|
"TeamId": teamId,
|
||||||
"UserId": userId,
|
"UserId": userId,
|
||||||
|
"ChannelType": model.ChannelTypePrivate,
|
||||||
})
|
})
|
||||||
|
|
||||||
privateChannels, privateErr := s.performSearch(`
|
privateChannels, privateErr := s.performSearch(`
|
||||||
@@ -3076,13 +3079,14 @@ func (s SqlChannelStore) SearchArchivedInTeam(teamId string, term string, userId
|
|||||||
c.TeamId = :TeamId
|
c.TeamId = :TeamId
|
||||||
SEARCH_CLAUSE
|
SEARCH_CLAUSE
|
||||||
AND c.DeleteAt != 0
|
AND c.DeleteAt != 0
|
||||||
AND c.Type = 'P'
|
AND c.Type = :ChannelType
|
||||||
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
|
AND c.Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
|
||||||
ORDER BY c.DisplayName
|
ORDER BY c.DisplayName
|
||||||
LIMIT 100
|
LIMIT 100
|
||||||
`, term, map[string]interface{}{
|
`, term, map[string]interface{}{
|
||||||
"TeamId": teamId,
|
"TeamId": teamId,
|
||||||
"UserId": userId,
|
"UserId": userId,
|
||||||
|
"ChannelType": model.ChannelTypePrivate,
|
||||||
})
|
})
|
||||||
|
|
||||||
outputErr := publicErr
|
outputErr := publicErr
|
||||||
@@ -3422,7 +3426,7 @@ func (s SqlChannelStore) getSearchGroupChannelsQuery(userId, term string, isPost
|
|||||||
JOIN
|
JOIN
|
||||||
Users u on u.Id = cm.UserId
|
Users u on u.Id = cm.UserId
|
||||||
WHERE
|
WHERE
|
||||||
c.Type = 'G'
|
c.Type = :ChannelType
|
||||||
AND
|
AND
|
||||||
u.Id = :UserId
|
u.Id = :UserId
|
||||||
GROUP BY
|
GROUP BY
|
||||||
@@ -3454,7 +3458,7 @@ func (s SqlChannelStore) getSearchGroupChannelsQuery(userId, term string, isPost
|
|||||||
JOIN
|
JOIN
|
||||||
Users u on u.Id = cm.UserId
|
Users u on u.Id = cm.UserId
|
||||||
WHERE
|
WHERE
|
||||||
c.Type = 'G'
|
c.Type = :ChannelType
|
||||||
AND
|
AND
|
||||||
u.Id = :UserId
|
u.Id = :UserId
|
||||||
GROUP BY
|
GROUP BY
|
||||||
@@ -3473,7 +3477,7 @@ func (s SqlChannelStore) getSearchGroupChannelsQuery(userId, term string, isPost
|
|||||||
}
|
}
|
||||||
|
|
||||||
var likeClauses []string
|
var likeClauses []string
|
||||||
args := map[string]interface{}{"UserId": userId}
|
args := map[string]interface{}{"UserId": userId, "ChannelType": model.ChannelTypeGroup}
|
||||||
terms := strings.Split(strings.ToLower(strings.Trim(term, " ")), " ")
|
terms := strings.Split(strings.ToLower(strings.Trim(term, " ")), " ")
|
||||||
|
|
||||||
for idx, term := range terms {
|
for idx, term := range terms {
|
||||||
@@ -3748,11 +3752,11 @@ func (s SqlChannelStore) GetAllChannelsForExportAfter(limit int, afterId string)
|
|||||||
Schemes ON Channels.SchemeId = Schemes.Id
|
Schemes ON Channels.SchemeId = Schemes.Id
|
||||||
WHERE
|
WHERE
|
||||||
Channels.Id > ?
|
Channels.Id > ?
|
||||||
AND Channels.Type IN ('O', 'P')
|
AND Channels.Type IN (?, ?)
|
||||||
ORDER BY
|
ORDER BY
|
||||||
Id
|
Id
|
||||||
LIMIT ?`,
|
LIMIT ?`,
|
||||||
afterId, limit); err != nil {
|
afterId, model.ChannelTypeOpen, model.ChannelTypePrivate, limit); err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to find Channels for export")
|
return nil, errors.Wrap(err, "failed to find Channels for export")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3800,7 +3804,7 @@ func (s SqlChannelStore) GetAllDirectChannelsForExportAfter(limit int, afterId s
|
|||||||
Where(sq.And{
|
Where(sq.And{
|
||||||
sq.Gt{"Channels.Id": afterId},
|
sq.Gt{"Channels.Id": afterId},
|
||||||
sq.Eq{"Channels.DeleteAt": int(0)},
|
sq.Eq{"Channels.DeleteAt": int(0)},
|
||||||
sq.Eq{"Channels.Type": []string{"D", "G"}},
|
sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}},
|
||||||
}).
|
}).
|
||||||
OrderBy("Channels.Id").
|
OrderBy("Channels.Id").
|
||||||
Limit(uint64(limit))
|
Limit(uint64(limit))
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
|
|||||||
if cursor.LastChannelsQueryPostCreateAt == 0 {
|
if cursor.LastChannelsQueryPostCreateAt == 0 {
|
||||||
cursor.LastChannelsQueryPostCreateAt = job.StartAt
|
cursor.LastChannelsQueryPostCreateAt = job.StartAt
|
||||||
}
|
}
|
||||||
//append the named parameters of SQL query in the correct order to argsChannelsQuery
|
// append the named parameters of SQL query in the correct order to argsChannelsQuery
|
||||||
argsChannelsQuery = append(argsChannelsQuery, cursor.LastChannelsQueryPostCreateAt, cursor.LastChannelsQueryPostCreateAt, cursor.LastChannelsQueryPostID, job.EndAt)
|
argsChannelsQuery = append(argsChannelsQuery, cursor.LastChannelsQueryPostCreateAt, cursor.LastChannelsQueryPostCreateAt, cursor.LastChannelsQueryPostID, job.EndAt)
|
||||||
argsChannelsQuery = append(argsChannelsQuery, argsEmails...)
|
argsChannelsQuery = append(argsChannelsQuery, argsEmails...)
|
||||||
argsChannelsQuery = append(argsChannelsQuery, argsKeywords...)
|
argsChannelsQuery = append(argsChannelsQuery, argsKeywords...)
|
||||||
@@ -222,7 +222,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
|
|||||||
if cursor.LastDirectMessagesQueryPostCreateAt == 0 {
|
if cursor.LastDirectMessagesQueryPostCreateAt == 0 {
|
||||||
cursor.LastDirectMessagesQueryPostCreateAt = job.StartAt
|
cursor.LastDirectMessagesQueryPostCreateAt = job.StartAt
|
||||||
}
|
}
|
||||||
//append the named parameters of SQL query in the correct order to argsDirectMessagesQuery
|
// append the named parameters of SQL query in the correct order to argsDirectMessagesQuery
|
||||||
argsDirectMessagesQuery = append(argsDirectMessagesQuery, cursor.LastDirectMessagesQueryPostCreateAt, cursor.LastDirectMessagesQueryPostCreateAt, cursor.LastDirectMessagesQueryPostID, job.EndAt)
|
argsDirectMessagesQuery = append(argsDirectMessagesQuery, cursor.LastDirectMessagesQueryPostCreateAt, cursor.LastDirectMessagesQueryPostCreateAt, cursor.LastDirectMessagesQueryPostID, job.EndAt)
|
||||||
argsDirectMessagesQuery = append(argsDirectMessagesQuery, argsEmails...)
|
argsDirectMessagesQuery = append(argsDirectMessagesQuery, argsEmails...)
|
||||||
argsDirectMessagesQuery = append(argsDirectMessagesQuery, argsKeywords...)
|
argsDirectMessagesQuery = append(argsDirectMessagesQuery, argsKeywords...)
|
||||||
@@ -285,7 +285,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
|
|||||||
|
|
||||||
func (s SqlComplianceStore) MessageExport(cursor model.MessageExportCursor, limit int) ([]*model.MessageExport, model.MessageExportCursor, error) {
|
func (s SqlComplianceStore) MessageExport(cursor model.MessageExportCursor, limit int) ([]*model.MessageExport, model.MessageExportCursor, error) {
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
args = append(args, cursor.LastPostUpdateAt, cursor.LastPostUpdateAt, cursor.LastPostId, limit)
|
args = append(args, model.ChannelTypeDirect, model.ChannelTypeGroup, cursor.LastPostUpdateAt, cursor.LastPostUpdateAt, cursor.LastPostId, limit)
|
||||||
query :=
|
query :=
|
||||||
`SELECT
|
`SELECT
|
||||||
Posts.Id AS PostId,
|
Posts.Id AS PostId,
|
||||||
@@ -303,8 +303,8 @@ func (s SqlComplianceStore) MessageExport(cursor model.MessageExportCursor, limi
|
|||||||
Teams.DisplayName AS TeamDisplayName,
|
Teams.DisplayName AS TeamDisplayName,
|
||||||
Channels.Id AS ChannelId,
|
Channels.Id AS ChannelId,
|
||||||
CASE
|
CASE
|
||||||
WHEN Channels.Type = 'D' THEN 'Direct Message'
|
WHEN Channels.Type = ? THEN 'Direct Message'
|
||||||
WHEN Channels.Type = 'G' THEN 'Group Message'
|
WHEN Channels.Type = ? THEN 'Group Message'
|
||||||
ELSE Channels.DisplayName
|
ELSE Channels.DisplayName
|
||||||
END AS ChannelDisplayName,
|
END AS ChannelDisplayName,
|
||||||
Channels.Name AS ChannelName,
|
Channels.Name AS ChannelName,
|
||||||
|
|||||||
@@ -2369,7 +2369,7 @@ func (s *SqlPostStore) GetDirectPostParentsForExportAfter(limit int, afterId str
|
|||||||
sq.Eq{"p.DeleteAt": 0},
|
sq.Eq{"p.DeleteAt": 0},
|
||||||
sq.Eq{"Channels.DeleteAt": 0},
|
sq.Eq{"Channels.DeleteAt": 0},
|
||||||
sq.Eq{"Users.DeleteAt": 0},
|
sq.Eq{"Users.DeleteAt": 0},
|
||||||
sq.Eq{"Channels.Type": []string{"D", "G"}},
|
sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}},
|
||||||
}).
|
}).
|
||||||
OrderBy("p.Id").
|
OrderBy("p.Id").
|
||||||
Limit(uint64(limit))
|
Limit(uint64(limit))
|
||||||
|
|||||||
@@ -1353,7 +1353,7 @@ func (us SqlUserStore) AnalyticsActiveCountForPeriod(startTime int64, endTime in
|
|||||||
|
|
||||||
func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
||||||
query := `
|
query := `
|
||||||
SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END)
|
SELECT SUM(CASE WHEN c.Type = ? THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END)
|
||||||
FROM Channels c
|
FROM Channels c
|
||||||
INNER JOIN ChannelMembers cm
|
INNER JOIN ChannelMembers cm
|
||||||
ON cm.ChannelId = c.Id
|
ON cm.ChannelId = c.Id
|
||||||
@@ -1362,7 +1362,7 @@ func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
|||||||
`
|
`
|
||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
err := us.GetReplicaX().Get(&count, query, userId)
|
err := us.GetReplicaX().Get(&count, query, model.ChannelTypeDirect, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return count, errors.Wrapf(err, "failed to count unread Channels for userId=%s", userId)
|
return count, errors.Wrapf(err, "failed to count unread Channels for userId=%s", userId)
|
||||||
}
|
}
|
||||||
@@ -1372,7 +1372,7 @@ func (us SqlUserStore) GetUnreadCount(userId string) (int64, error) {
|
|||||||
|
|
||||||
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) (int64, error) {
|
func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) (int64, error) {
|
||||||
var count int64
|
var count int64
|
||||||
err := us.GetReplicaX().Get(&count, "SELECT SUM(CASE WHEN c.Type = 'D' THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", channelId, userId)
|
err := us.GetReplicaX().Get(&count, "SELECT SUM(CASE WHEN c.Type = ? THEN (c.TotalMsgCount - cm.MsgCount) ELSE cm.MentionCount END) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = ? AND cm.UserId = ?", model.ChannelTypeDirect, channelId, userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrapf(err, "failed to get unread count for channelId=%s and userId=%s", channelId, userId)
|
return 0, errors.Wrapf(err, "failed to get unread count for channelId=%s and userId=%s", channelId, userId)
|
||||||
}
|
}
|
||||||
@@ -1733,7 +1733,7 @@ func (us SqlUserStore) GetUsersBatchForIndexing(startTime, endTime int64, limit
|
|||||||
`).
|
`).
|
||||||
From("ChannelMembers cm").
|
From("ChannelMembers cm").
|
||||||
Join("Channels c ON cm.ChannelId = c.Id").
|
Join("Channels c ON cm.ChannelId = c.Id").
|
||||||
Where(sq.Eq{"c.Type": "O", "cm.UserId": userIds}).
|
Where(sq.Eq{"c.Type": model.ChannelTypeOpen, "cm.UserId": userIds}).
|
||||||
ToSql()
|
ToSql()
|
||||||
_, err = us.GetSearchReplica().Select(&channelMembers, channelMembersQuery, args...)
|
_, err = us.GetSearchReplica().Select(&channelMembers, channelMembersQuery, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ type ChannelStore interface {
|
|||||||
GetMembersByIds(channelID string, userIds []string) (model.ChannelMembers, error)
|
GetMembersByIds(channelID string, userIds []string) (model.ChannelMembers, error)
|
||||||
GetMembersByChannelIds(channelIds []string, userID string) (model.ChannelMembers, error)
|
GetMembersByChannelIds(channelIds []string, userID string) (model.ChannelMembers, error)
|
||||||
GetMembersInfoByChannelIds(channelIDs []string) (map[string][]*model.User, error)
|
GetMembersInfoByChannelIds(channelIDs []string) (map[string][]*model.User, error)
|
||||||
AnalyticsDeletedTypeCount(teamID string, channelType string) (int64, error)
|
AnalyticsDeletedTypeCount(teamID string, channelType model.ChannelType) (int64, error)
|
||||||
GetChannelUnread(channelID, userID string) (*model.ChannelUnread, error)
|
GetChannelUnread(channelID, userID string) (*model.ChannelUnread, error)
|
||||||
ClearCaches()
|
ClearCaches()
|
||||||
GetChannelsByScheme(schemeID string, offset int, limit int) (model.ChannelList, error)
|
GetChannelsByScheme(schemeID string, offset int, limit int) (model.ChannelList, error)
|
||||||
|
|||||||
@@ -6626,15 +6626,15 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
var openStartCount int64
|
var openStartCount int64
|
||||||
openStartCount, nErr = ss.Channel().AnalyticsDeletedTypeCount("", "O")
|
openStartCount, nErr = ss.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypeOpen)
|
||||||
require.NoError(t, nErr, nErr)
|
require.NoError(t, nErr, nErr)
|
||||||
|
|
||||||
var privateStartCount int64
|
var privateStartCount int64
|
||||||
privateStartCount, nErr = ss.Channel().AnalyticsDeletedTypeCount("", "P")
|
privateStartCount, nErr = ss.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypePrivate)
|
||||||
require.NoError(t, nErr, nErr)
|
require.NoError(t, nErr, nErr)
|
||||||
|
|
||||||
var directStartCount int64
|
var directStartCount int64
|
||||||
directStartCount, nErr = ss.Channel().AnalyticsDeletedTypeCount("", "D")
|
directStartCount, nErr = ss.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypeDirect)
|
||||||
require.NoError(t, nErr, nErr)
|
require.NoError(t, nErr, nErr)
|
||||||
|
|
||||||
nErr = ss.Channel().Delete(o1.Id, model.GetMillis())
|
nErr = ss.Channel().Delete(o1.Id, model.GetMillis())
|
||||||
@@ -6648,15 +6648,15 @@ func testChannelStoreAnalyticsDeletedTypeCount(t *testing.T, ss store.Store) {
|
|||||||
|
|
||||||
var count int64
|
var count int64
|
||||||
|
|
||||||
count, nErr = ss.Channel().AnalyticsDeletedTypeCount("", "O")
|
count, nErr = ss.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypeOpen)
|
||||||
require.NoError(t, err, nErr)
|
require.NoError(t, err, nErr)
|
||||||
assert.Equal(t, openStartCount+2, count, "Wrong open channel deleted count.")
|
assert.Equal(t, openStartCount+2, count, "Wrong open channel deleted count.")
|
||||||
|
|
||||||
count, nErr = ss.Channel().AnalyticsDeletedTypeCount("", "P")
|
count, nErr = ss.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypePrivate)
|
||||||
require.NoError(t, nErr, nErr)
|
require.NoError(t, nErr, nErr)
|
||||||
assert.Equal(t, privateStartCount+1, count, "Wrong private channel deleted count.")
|
assert.Equal(t, privateStartCount+1, count, "Wrong private channel deleted count.")
|
||||||
|
|
||||||
count, nErr = ss.Channel().AnalyticsDeletedTypeCount("", "D")
|
count, nErr = ss.Channel().AnalyticsDeletedTypeCount("", model.ChannelTypeDirect)
|
||||||
require.NoError(t, nErr, nErr)
|
require.NoError(t, nErr, nErr)
|
||||||
assert.Equal(t, directStartCount+1, count, "Wrong direct channel deleted count.")
|
assert.Equal(t, directStartCount+1, count, "Wrong direct channel deleted count.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,18 +19,18 @@ type ChannelStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsDeletedTypeCount provides a mock function with given fields: teamID, channelType
|
// AnalyticsDeletedTypeCount provides a mock function with given fields: teamID, channelType
|
||||||
func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType string) (int64, error) {
|
func (_m *ChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType model.ChannelType) (int64, error) {
|
||||||
ret := _m.Called(teamID, channelType)
|
ret := _m.Called(teamID, channelType)
|
||||||
|
|
||||||
var r0 int64
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(string, string) int64); ok {
|
if rf, ok := ret.Get(0).(func(string, model.ChannelType) int64); ok {
|
||||||
r0 = rf(teamID, channelType)
|
r0 = rf(teamID, channelType)
|
||||||
} else {
|
} else {
|
||||||
r0 = ret.Get(0).(int64)
|
r0 = ret.Get(0).(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 error
|
var r1 error
|
||||||
if rf, ok := ret.Get(1).(func(string, string) error); ok {
|
if rf, ok := ret.Get(1).(func(string, model.ChannelType) error); ok {
|
||||||
r1 = rf(teamID, channelType)
|
r1 = rf(teamID, channelType)
|
||||||
} else {
|
} else {
|
||||||
r1 = ret.Error(1)
|
r1 = ret.Error(1)
|
||||||
|
|||||||
@@ -518,7 +518,7 @@ func (s *TimerLayerBotStore) Update(bot *model.Bot) (*model.Bot, error) {
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TimerLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType string) (int64, error) {
|
func (s *TimerLayerChannelStore) AnalyticsDeletedTypeCount(teamID string, channelType model.ChannelType) (int64, error) {
|
||||||
start := timemodule.Now()
|
start := timemodule.Now()
|
||||||
|
|
||||||
result, err := s.ChannelStore.AnalyticsDeletedTypeCount(teamID, channelType)
|
result, err := s.ChannelStore.AnalyticsDeletedTypeCount(teamID, channelType)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user