MM-20897 Add category muting (#16225)
* Make UpdateSidebarCategories return the original categories * MM-20897 Add category muting * Prevent muting the DMs category * Fix muted state not being stored in the database * Address feedback * Address some feedback * Fix unit tests * MM-20897 Mute/unmute channels in the database in bulk * Satisfy golangci-lint
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7f6b43a15f
Коммит
2ebc8ec90f
@@ -2955,27 +2955,30 @@ func (s SqlChannelStore) SearchGroupChannels(userId, term string) (*model.Channe
|
||||
|
||||
func (s SqlChannelStore) GetMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
props := make(map[string]interface{})
|
||||
idQuery := ""
|
||||
|
||||
for index, userId := range userIds {
|
||||
if len(idQuery) > 0 {
|
||||
idQuery += ", "
|
||||
}
|
||||
|
||||
props["userId"+strconv.Itoa(index)] = userId
|
||||
idQuery += ":userId" + strconv.Itoa(index)
|
||||
}
|
||||
|
||||
keys, props := MapStringsToQueryParams(userIds, "User")
|
||||
props["ChannelId"] = channelId
|
||||
|
||||
if _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId IN ("+idQuery+")", props); err != nil {
|
||||
if _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.ChannelId = :ChannelId AND ChannelMembers.UserId IN "+keys, props); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with channelId=%s and userId in %v", channelId, userIds)
|
||||
}
|
||||
|
||||
return dbMembers.ToModel(), nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetMembersByChannelIds(channelIds []string, userId string) (*model.ChannelMembers, error) {
|
||||
var dbMembers channelMemberWithSchemeRolesList
|
||||
|
||||
keys, props := MapStringsToQueryParams(channelIds, "Channel")
|
||||
props["UserId"] = userId
|
||||
|
||||
if _, err := s.GetReplica().Select(&dbMembers, CHANNEL_MEMBERS_WITH_SCHEME_SELECT_QUERY+"WHERE ChannelMembers.UserId = :UserId AND ChannelMembers.ChannelId IN "+keys, props); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find ChannelMembers with userId=%s and channelId in %v", userId, channelIds)
|
||||
}
|
||||
|
||||
return dbMembers.ToModel(), nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetChannelsByScheme(schemeId string, offset int, limit int) (model.ChannelList, error) {
|
||||
var channels model.ChannelList
|
||||
_, err := s.GetReplica().Select(&channels, "SELECT * FROM Channels WHERE SchemeId = :SchemeId ORDER BY DisplayName LIMIT :Limit OFFSET :Offset", map[string]interface{}{"SchemeId": schemeId, "Offset": offset, "Limit": limit})
|
||||
|
||||
@@ -266,6 +266,7 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
|
||||
Sorting: model.SidebarCategorySortDefault,
|
||||
SortOrder: int64(model.MinimalSidebarSortDistance * len(newOrder)), // first we place it at the end of the list
|
||||
Type: model.SidebarCategoryCustom,
|
||||
Muted: newCategory.Muted,
|
||||
}
|
||||
if err = transaction.Insert(category); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save SidebarCategory")
|
||||
@@ -605,18 +606,19 @@ func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categ
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, error) {
|
||||
func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, []*model.SidebarCategoryWithChannels, error) {
|
||||
transaction, err := s.GetMaster().Begin()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "begin_transaction")
|
||||
return nil, nil, errors.Wrap(err, "begin_transaction")
|
||||
}
|
||||
defer finalizeTransaction(transaction)
|
||||
|
||||
updatedCategories := []*model.SidebarCategoryWithChannels{}
|
||||
originalCategories := []*model.SidebarCategoryWithChannels{}
|
||||
for _, category := range categories {
|
||||
originalCategory, err2 := s.GetSidebarCategory(category.Id)
|
||||
if err2 != nil {
|
||||
return nil, errors.Wrap(err2, "failed to find SidebarCategories")
|
||||
return nil, nil, errors.Wrap(err2, "failed to find SidebarCategories")
|
||||
}
|
||||
|
||||
// Copy category to avoid modifying an argument
|
||||
@@ -629,24 +631,28 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
|
||||
updatedCategory.TeamId = originalCategory.TeamId
|
||||
updatedCategory.SortOrder = originalCategory.SortOrder
|
||||
updatedCategory.Type = originalCategory.Type
|
||||
updatedCategory.Muted = originalCategory.Muted
|
||||
|
||||
if updatedCategory.Type != model.SidebarCategoryCustom {
|
||||
updatedCategory.DisplayName = originalCategory.DisplayName
|
||||
}
|
||||
|
||||
if category.Type != model.SidebarCategoryDirectMessages {
|
||||
if updatedCategory.Type != model.SidebarCategoryDirectMessages {
|
||||
updatedCategory.Channels = make([]string, len(category.Channels))
|
||||
copy(updatedCategory.Channels, category.Channels)
|
||||
|
||||
updatedCategory.Muted = category.Muted
|
||||
}
|
||||
|
||||
updateQuery, updateParams, _ := s.getQueryBuilder().
|
||||
Update("SidebarCategories").
|
||||
Set("DisplayName", updatedCategory.DisplayName).
|
||||
Set("Sorting", updatedCategory.Sorting).
|
||||
Set("Muted", updatedCategory.Muted).
|
||||
Where(sq.Eq{"Id": updatedCategory.Id}).ToSql()
|
||||
|
||||
if _, err = transaction.Exec(updateQuery, updateParams...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to update SidebarCategories")
|
||||
return nil, nil, errors.Wrap(err, "failed to update SidebarCategories")
|
||||
}
|
||||
|
||||
// if we are updating DM category, it's order can't channel order cannot be changed.
|
||||
@@ -667,11 +673,11 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
|
||||
).ToSql()
|
||||
|
||||
if err2 != nil {
|
||||
return nil, errors.Wrap(err2, "update_sidebar_catetories_tosql")
|
||||
return nil, nil, errors.Wrap(err2, "update_sidebar_catetories_tosql")
|
||||
}
|
||||
|
||||
if _, err = transaction.Exec(query, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to delete SidebarChannels")
|
||||
return nil, nil, errors.Wrap(err, "failed to delete SidebarChannels")
|
||||
}
|
||||
|
||||
var channels []interface{}
|
||||
@@ -687,7 +693,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
|
||||
}
|
||||
|
||||
if err = transaction.Insert(channels...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save SidebarChannels")
|
||||
return nil, nil, errors.Wrap(err, "failed to save SidebarChannels")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -703,7 +709,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
|
||||
).ToSql()
|
||||
|
||||
if _, err = transaction.Exec(sql, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to delete Preferences")
|
||||
return nil, nil, errors.Wrap(err, "failed to delete Preferences")
|
||||
}
|
||||
|
||||
// And then add the new ones
|
||||
@@ -716,7 +722,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
|
||||
Category: model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL,
|
||||
Value: "true",
|
||||
}); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save Preference")
|
||||
return nil, nil, errors.Wrap(err, "failed to save Preference")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -729,32 +735,33 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
|
||||
},
|
||||
).ToSql()
|
||||
if nErr != nil {
|
||||
return nil, errors.Wrap(nErr, "update_sidebar_categories_tosql")
|
||||
return nil, nil, errors.Wrap(nErr, "update_sidebar_categories_tosql")
|
||||
}
|
||||
|
||||
if _, nErr = transaction.Exec(query, args...); nErr != nil {
|
||||
return nil, errors.Wrap(nErr, "failed to delete Preferences")
|
||||
return nil, nil, errors.Wrap(nErr, "failed to delete Preferences")
|
||||
}
|
||||
}
|
||||
|
||||
updatedCategories = append(updatedCategories, updatedCategory)
|
||||
originalCategories = append(originalCategories, originalCategory)
|
||||
}
|
||||
|
||||
// Ensure Channels are populated for Channels/Direct Messages category if they change
|
||||
for i, updatedCategory := range updatedCategories {
|
||||
populated, nErr := s.completePopulatingCategoryChannelsT(transaction, updatedCategory)
|
||||
if nErr != nil {
|
||||
return nil, nErr
|
||||
return nil, nil, nErr
|
||||
}
|
||||
|
||||
updatedCategories[i] = populated
|
||||
}
|
||||
|
||||
if err = transaction.Commit(); err != nil {
|
||||
return nil, errors.Wrap(err, "commit_transaction")
|
||||
return nil, nil, errors.Wrap(err, "commit_transaction")
|
||||
}
|
||||
|
||||
return updatedCategories, nil
|
||||
return updatedCategories, originalCategories, nil
|
||||
}
|
||||
|
||||
// UpdateSidebarChannelsByPreferences is called when the Preference table is being updated to keep SidebarCategories in sync
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
const (
|
||||
CURRENT_SCHEMA_VERSION = VERSION_5_29_0
|
||||
VERSION_5_30_0 = "5.30.0"
|
||||
VERSION_5_29_0 = "5.29.0"
|
||||
VERSION_5_28_1 = "5.28.1"
|
||||
VERSION_5_28_0 = "5.28.0"
|
||||
@@ -866,15 +867,6 @@ func upgradeDatabaseToVersion5281(sqlStore SqlStore) {
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion530(sqlStore SqlStore) {
|
||||
// if shouldPerformUpgrade(sqlStore, VERSION_5_29_0, VERSION_5_30_0) {
|
||||
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("FileInfo", "Content", "longtext", "text")
|
||||
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_30_0)
|
||||
// }
|
||||
}
|
||||
|
||||
func precheckMigrationToVersion528(sqlStore SqlStore) error {
|
||||
teamsQuery, _, err := sqlStore.getQueryBuilder().Select(`COALESCE(SUM(CASE
|
||||
WHEN CHAR_LENGTH(SchemeId) > 26 THEN 1
|
||||
@@ -948,3 +940,14 @@ func upgradeDatabaseToVersion529(sqlStore SqlStore) {
|
||||
saveSchemaVersion(sqlStore, VERSION_5_29_0)
|
||||
}
|
||||
}
|
||||
|
||||
func upgradeDatabaseToVersion530(sqlStore SqlStore) {
|
||||
// if shouldPerformUpgrade(sqlStore, VERSION_5_29_0, VERSION_5_30_0) {
|
||||
|
||||
sqlStore.CreateColumnIfNotExistsNoDefault("FileInfo", "Content", "longtext", "text")
|
||||
|
||||
sqlStore.CreateColumnIfNotExists("SidebarCategories", "Muted", "tinyint(1)", "boolean", "0")
|
||||
|
||||
// saveSchemaVersion(sqlStore, VERSION_5_30_0)
|
||||
// }
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user