MM-45395: Exclude bot and webhook posts from Top Team Channels. Exclude webhook posts from My Top Channels. (#20599)
* MM-45395: Exclude bot and webhook posts from Top Team Channels. Exclude webhook posts from My Top Channels. * MM-45395: Adds missing error test. * MM-45395: Adds missing whitespace.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
f639122376
Коммит
a46840e96b
@@ -2382,7 +2382,31 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
channel2 := th.CreateChannel(th.BasicTeam)
|
channel2 := th.CreateChannel(th.BasicTeam)
|
||||||
|
|
||||||
|
// add a bot post to ensure it's not counted
|
||||||
|
_, err := th.Server.Store.Post().Save(&model.Post{
|
||||||
|
Message: "hello from a bot",
|
||||||
|
ChannelId: channel2.Id,
|
||||||
|
UserId: th.BasicUser.Id,
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"from_bot": true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
channel3 := th.CreatePrivateChannel(th.BasicTeam)
|
channel3 := th.CreatePrivateChannel(th.BasicTeam)
|
||||||
|
|
||||||
|
// add a webhook post to ensure it's not counted
|
||||||
|
_, err = th.Server.Store.Post().Save(&model.Post{
|
||||||
|
Message: "hello from a webhook",
|
||||||
|
ChannelId: channel3.Id,
|
||||||
|
UserId: th.BasicUser.Id,
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"from_webhook": true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
channel4 := th.CreatePrivateChannel(th.BasicTeam)
|
channel4 := th.CreatePrivateChannel(th.BasicTeam)
|
||||||
channel5 := th.CreateChannel(th.BasicTeam)
|
channel5 := th.CreateChannel(th.BasicTeam)
|
||||||
channel6 := th.CreatePrivateChannel(th.BasicTeam)
|
channel6 := th.CreatePrivateChannel(th.BasicTeam)
|
||||||
@@ -2436,7 +2460,31 @@ func TestGetTopChannelsForUserSince(t *testing.T) {
|
|||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
channel2 := th.CreateChannel(th.BasicTeam)
|
channel2 := th.CreateChannel(th.BasicTeam)
|
||||||
|
|
||||||
|
// add a bot post to ensure it's not counted
|
||||||
|
_, err := th.Server.Store.Post().Save(&model.Post{
|
||||||
|
Message: "hello from a bot",
|
||||||
|
ChannelId: channel2.Id,
|
||||||
|
UserId: th.BasicUser.Id,
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"from_bot": true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
channel3 := th.CreatePrivateChannel(th.BasicTeam)
|
channel3 := th.CreatePrivateChannel(th.BasicTeam)
|
||||||
|
|
||||||
|
// add a webhook post to ensure it's not counted
|
||||||
|
_, err = th.Server.Store.Post().Save(&model.Post{
|
||||||
|
Message: "hello from a webhook",
|
||||||
|
ChannelId: channel3.Id,
|
||||||
|
UserId: th.BasicUser.Id,
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"from_webhook": true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
channel4 := th.CreatePrivateChannel(th.BasicTeam)
|
channel4 := th.CreatePrivateChannel(th.BasicTeam)
|
||||||
channel5 := th.CreateChannel(th.BasicTeam)
|
channel5 := th.CreateChannel(th.BasicTeam)
|
||||||
channel6 := th.CreatePrivateChannel(th.BasicTeam)
|
channel6 := th.CreatePrivateChannel(th.BasicTeam)
|
||||||
|
|||||||
@@ -4158,8 +4158,8 @@ func (s SqlChannelStore) GetTeamForChannel(channelID string) (*model.Team, error
|
|||||||
func (s SqlChannelStore) GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
func (s SqlChannelStore) GetTopChannelsForTeamSince(teamID string, userID string, since int64, offset int, limit int) (*model.TopChannelList, error) {
|
||||||
channels := make([]*model.TopChannel, 0)
|
channels := make([]*model.TopChannel, 0)
|
||||||
var args []any
|
var args []any
|
||||||
postgresPropQuery := `AND (Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false')`
|
postgresPropQuery := `AND (Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false') AND (Posts.Props ->> 'from_webhook' IS NULL OR Posts.Props ->> 'from_webhook' = 'false')`
|
||||||
mySqlPropsQuery := `AND (JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false')`
|
mySqlPropsQuery := `AND (JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_webhook') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_webhook') = 'false')`
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
SELECT
|
SELECT
|
||||||
@@ -4260,6 +4260,13 @@ func (s SqlChannelStore) GetTopChannelsForUserSince(userID string, teamID string
|
|||||||
var args []any
|
var args []any
|
||||||
var query string
|
var query string
|
||||||
|
|
||||||
|
var propsQuery string
|
||||||
|
if s.DriverName() == model.DatabaseDriverMysql {
|
||||||
|
propsQuery = `AND (JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_webhook') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_webhook') = 'false')`
|
||||||
|
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
||||||
|
propsQuery = `AND (Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false') AND (Posts.Props ->> 'from_webhook' IS NULL OR Posts.Props ->> 'from_webhook' = 'false')`
|
||||||
|
}
|
||||||
|
|
||||||
query = `
|
query = `
|
||||||
SELECT
|
SELECT
|
||||||
Posts.ChannelId AS ID,
|
Posts.ChannelId AS ID,
|
||||||
@@ -4279,7 +4286,9 @@ func (s SqlChannelStore) GetTopChannelsForUserSince(userID string, teamID string
|
|||||||
AND Posts.UserID = ?
|
AND Posts.UserID = ?
|
||||||
AND Channels.DeleteAt = 0
|
AND Channels.DeleteAt = 0
|
||||||
AND (Channels.Type = 'O' OR Channels.Type = 'P')
|
AND (Channels.Type = 'O' OR Channels.Type = 'P')
|
||||||
AND ChannelMembers.UserId = ?`
|
AND ChannelMembers.UserId = ? `
|
||||||
|
|
||||||
|
query += propsQuery
|
||||||
|
|
||||||
args = []any{since, userID, userID}
|
args = []any{since, userID, userID}
|
||||||
|
|
||||||
@@ -4323,14 +4332,14 @@ func (s SqlChannelStore) PostCountsByDuration(channelIDs []string, sinceUnixMill
|
|||||||
} else {
|
} else {
|
||||||
unixSelect = `DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(Posts.CreateAt / 1000), 'GMT', '` + loc + `'),'%Y-%m-%dT%H') AS duration`
|
unixSelect = `DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(Posts.CreateAt / 1000), 'GMT', '` + loc + `'),'%Y-%m-%dT%H') AS duration`
|
||||||
}
|
}
|
||||||
propsQuery = `(JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false')`
|
propsQuery = `(JSON_EXTRACT(Posts.Props, '$.from_bot') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_bot') = 'false') AND (JSON_EXTRACT(Posts.Props, '$.from_webhook') IS NULL OR JSON_EXTRACT(Posts.Props, '$.from_webhook') = 'false')`
|
||||||
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
} else if s.DriverName() == model.DatabaseDriverPostgres {
|
||||||
if duration == model.PostsByDay {
|
if duration == model.PostsByDay {
|
||||||
unixSelect = fmt.Sprintf(`TO_CHAR(TO_TIMESTAMP(Posts.CreateAt / 1000) AT TIME ZONE '%s', 'YYYY-MM-DD') AS duration`, loc)
|
unixSelect = fmt.Sprintf(`TO_CHAR(TO_TIMESTAMP(Posts.CreateAt / 1000) AT TIME ZONE '%s', 'YYYY-MM-DD') AS duration`, loc)
|
||||||
} else {
|
} else {
|
||||||
unixSelect = fmt.Sprintf(`TO_CHAR(TO_TIMESTAMP(Posts.CreateAt / 1000) AT TIME ZONE '%s', 'YYYY-MM-DD"T"HH24') AS duration`, loc)
|
unixSelect = fmt.Sprintf(`TO_CHAR(TO_TIMESTAMP(Posts.CreateAt / 1000) AT TIME ZONE '%s', 'YYYY-MM-DD"T"HH24') AS duration`, loc)
|
||||||
}
|
}
|
||||||
propsQuery = `(Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false')`
|
propsQuery = `(Posts.Props ->> 'from_bot' IS NULL OR Posts.Props ->> 'from_bot' = 'false') AND (Posts.Props ->> 'from_webhook' IS NULL OR Posts.Props ->> 'from_webhook' = 'false')`
|
||||||
}
|
}
|
||||||
query := sq.
|
query := sq.
|
||||||
Select("Posts.ChannelId AS channelid", unixSelect, "count(Posts.Id) AS postcount").
|
Select("Posts.ChannelId AS channelid", unixSelect, "count(Posts.Id) AS postcount").
|
||||||
|
|||||||
@@ -7935,6 +7935,26 @@ func testChannelPostCountsByDuration(t *testing.T, ss store.Store) {
|
|||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = ss.Post().Save(&model.Post{
|
||||||
|
UserId: userID,
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
Message: "test",
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"from_bot": true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = ss.Post().Save(&model.Post{
|
||||||
|
UserId: userID,
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
Message: "test",
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"from_webhook": true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
dpc, err := ss.Channel().PostCountsByDuration([]string{channelSaved.Id}, 0, &userID, model.PostsByDay, time.Now().Location())
|
dpc, err := ss.Channel().PostCountsByDuration([]string{channelSaved.Id}, 0, &userID, model.PostsByDay, time.Now().Location())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, dpc, 1)
|
require.Len(t, dpc, 1)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user