[MM-52969] Revert "MM-51482_Create Apps Category and link to bots DM (#22918)" (#23647)

* Revert "MM-51482_Create Apps Category and link to bots DM (#22918)"

This reverts commit 1051925eec.

* Revert "MM-51711_Feature flag: APPS sidebar category (#22766)"

This reverts commit 9156205178.
Этот коммит содержится в:
Pablo Andrés Vélez Vidal
2023-06-14 11:05:21 +02:00
коммит произвёл GitHub
родитель 16ad573979
Коммит 6a5bb53963
22 изменённых файлов: 113 добавлений и 3697 удалений

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

@@ -1190,38 +1190,6 @@ func (s SqlChannelStore) GetChannelsByUser(userId string, includeDeleted bool, l
return channels, nil
}
func (s SqlChannelStore) GetBotChannelsByUser(userId string, opts store.ChannelSearchOpts) (model.ChannelList, error) {
query := s.getQueryBuilder().
Select("C.*").
From("Channels as C, ChannelMembers as CM1, ChannelMembers as CM2, Bots as B").
Where(sq.And{
sq.Expr("C.Id = CM1.ChannelId"),
sq.Eq{"CM1.UserId": userId},
sq.Eq{"C.Type": model.ChannelTypeDirect},
sq.Expr("C.Id = CM2.ChannelId"),
sq.Expr("CM2.UserId = B.UserId"),
sq.Eq{"B.DeleteAt": 0},
}).
OrderBy("C.Id ASC")
if !opts.IncludeDeleted {
query = query.Where(sq.Eq{"C.DeleteAt": int(0)})
}
sql, args, err := query.ToSql()
if err != nil {
return nil, errors.Wrap(err, "GetBotChannelsByUser_ToSql")
}
channels := model.ChannelList{}
err = s.GetReplicaX().Select(&channels, sql, args...)
if err != nil {
return nil, errors.Wrapf(err, "failed to get bot channels with UserId=%s", userId)
}
return channels, nil
}
func (s SqlChannelStore) GetAllChannelMembersById(channelID string) ([]string, error) {
sql, args, err := s.channelMembersForTeamWithSchemeSelectQuery.Where(sq.Eq{
"ChannelId": channelID,

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

@@ -58,7 +58,11 @@ func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrap
From("SidebarCategories").
Where(sq.Eq{
"UserId": userId,
"Type": model.SystemSidebarCategories,
"Type": []model.SidebarCategoryType{
model.SidebarCategoryFavorites,
model.SidebarCategoryChannels,
model.SidebarCategoryDirectMessages,
},
})
if !opts.ExcludeTeam {
@@ -153,15 +157,6 @@ func (s SqlChannelStore) createInitialSidebarCategoriesT(transaction *sqlxTxWrap
hasInsert = true
}
if opts.AppsCategoryEnabled {
teamIDs = getRequiredTeamIDs(model.SidebarCategoryApps, opts)
for _, teamID := range teamIDs {
appsCategoryId := fmt.Sprintf("%s_%s_%s", model.SidebarCategoryApps, userId, teamID)
insertBuilder = insertBuilder.Values(appsCategoryId, userId, teamID, model.DefaultSidebarSortOrderApps, model.SidebarCategorySortDefault, model.SidebarCategoryApps, "Apps" /* This will be retranslated by the client into the user's locale */, false, false)
hasInsert = true
}
}
if hasInsert {
sql, args, err := insertBuilder.ToSql()
if err != nil {
@@ -301,7 +296,7 @@ type sidebarCategoryForJoin struct {
ChannelId *string
}
func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels, options ...*store.SidebarCategorySearchOpts) (_ *model.SidebarCategoryWithChannels, err error) {
func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels) (_ *model.SidebarCategoryWithChannels, err error) {
transaction, err := s.GetMasterX().Beginx()
if err != nil {
return nil, errors.Wrap(err, "begin_transaction")
@@ -309,15 +304,9 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
defer finalizeTransactionX(transaction, &err)
appsCategoryEnabled := false
if len(options) > 0 {
appsCategoryEnabled = options[0].AppsCategoryEnabled
}
opts := &store.SidebarCategorySearchOpts{
TeamID: teamId,
ExcludeTeam: false,
AppsCategoryEnabled: appsCategoryEnabled,
TeamID: teamId,
ExcludeTeam: false,
}
categoriesWithOrder, err := s.getSidebarCategoriesT(transaction, userId, opts)
if err != nil {
@@ -429,14 +418,14 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
return result, nil
}
func (s SqlChannelStore) completePopulatingCategoryChannels(category *model.SidebarCategoryWithChannels, appsCategoryEnabled bool) (_ *model.SidebarCategoryWithChannels, err error) {
func (s SqlChannelStore) completePopulatingCategoryChannels(category *model.SidebarCategoryWithChannels) (_ *model.SidebarCategoryWithChannels, err error) {
transaction, err := s.GetMasterX().Beginx()
if err != nil {
return nil, errors.Wrap(err, "begin_transaction")
}
defer finalizeTransactionX(transaction, &err)
result, err := s.completePopulatingCategoryChannelsT(transaction, category, appsCategoryEnabled)
result, err := s.completePopulatingCategoryChannelsT(transaction, category)
if err != nil {
return nil, err
}
@@ -448,38 +437,15 @@ func (s SqlChannelStore) completePopulatingCategoryChannels(category *model.Side
return result, nil
}
func (s SqlChannelStore) completePopulatingCategoryChannelsT(db dbSelecter, category *model.SidebarCategoryWithChannels, appsCategoryEnabled bool) (*model.SidebarCategoryWithChannels, error) {
func (s SqlChannelStore) completePopulatingCategoryChannelsT(db dbSelecter, category *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, error) {
if category.Type == model.SidebarCategoryCustom || category.Type == model.SidebarCategoryFavorites {
return category, nil
}
var channelTypeFilter sq.Sqlizer
if category.Type == model.SidebarCategoryApps || category.Type == model.SidebarCategoryDirectMessages {
botChannelsIDs := []string{}
if appsCategoryEnabled {
botChannels, err := s.SqlStore.stores.channel.GetBotChannelsByUser(category.UserId, store.ChannelSearchOpts{})
if err != nil {
return nil, err
}
for _, botChannel := range botChannels {
botChannelsIDs = append(botChannelsIDs, botChannel.Id)
}
}
if category.Type == model.SidebarCategoryApps {
// any DM channels with Bots that aren't in any category should be returned as part of the Apps category
channelTypeFilter = sq.And{
sq.Eq{"Channels.Type": model.ChannelTypeDirect},
sq.Eq{"Channels.Id": botChannelsIDs},
}
} else if category.Type == model.SidebarCategoryDirectMessages {
// any DM/GM channels with Users that aren't in any category should be returned as part of the Direct Messages category
channelTypeFilter = sq.And{
sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}},
sq.NotEq{"Channels.Id": botChannelsIDs},
}
}
if category.Type == model.SidebarCategoryDirectMessages {
// any DM/GM channels that aren't in any category should be returned as part of the Direct Messages category
channelTypeFilter = sq.Eq{"Channels.Type": []model.ChannelType{model.ChannelTypeDirect, model.ChannelTypeGroup}}
} else if category.Type == model.SidebarCategoryChannels {
// any public/private channels that are on the current team and aren't in any category should be returned as part of the Channels category
channelTypeFilter = sq.And{
@@ -502,12 +468,6 @@ func (s SqlChannelStore) completePopulatingCategoryChannelsT(db dbSelecter, cate
}).
Suffix(")")
if !appsCategoryEnabled {
doesNotHaveSidebarChannel = doesNotHaveSidebarChannel.Where(
sq.NotEq{"SidebarCategories.Type": model.SidebarCategoryApps},
)
}
channels := []string{}
sql, args, err := s.getQueryBuilder().
Select("Id").
@@ -532,7 +492,7 @@ func (s SqlChannelStore) completePopulatingCategoryChannelsT(db dbSelecter, cate
return category, nil
}
func (s SqlChannelStore) GetSidebarCategory(categoryId string, options ...*store.SidebarCategorySearchOpts) (*model.SidebarCategoryWithChannels, error) {
func (s SqlChannelStore) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, error) {
sql, args, err := s.getQueryBuilder().
Select("SidebarCategories.*", "SidebarChannels.ChannelId").
From("SidebarCategories").
@@ -561,13 +521,7 @@ func (s SqlChannelStore) GetSidebarCategory(categoryId string, options ...*store
result.Channels = append(result.Channels, *category.ChannelId)
}
}
appsCategoryEnabled := false
if len(options) > 0 {
appsCategoryEnabled = options[0].AppsCategoryEnabled
}
return s.completePopulatingCategoryChannels(result, appsCategoryEnabled)
return s.completePopulatingCategoryChannels(result)
}
func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId string, opts *store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
@@ -599,10 +553,6 @@ func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId string, opt
query = query.Where(sq.Eq{"SidebarCategories.TeamId": opts.TeamID})
}
if !opts.AppsCategoryEnabled {
query = query.Where(sq.NotEq{"SidebarCategories.Type": model.SidebarCategoryApps})
}
sql, args, err := query.ToSql()
if err != nil {
return nil, errors.Wrap(err, "sidebar_categories_tosql")
@@ -633,7 +583,7 @@ func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId string, opt
}
}
for _, category := range oc.Categories {
if _, err := s.completePopulatingCategoryChannelsT(db, category, opts.AppsCategoryEnabled); err != nil {
if _, err := s.completePopulatingCategoryChannelsT(db, category); err != nil {
return nil, err
}
}
@@ -641,16 +591,10 @@ func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId string, opt
return &oc, nil
}
func (s SqlChannelStore) GetSidebarCategoriesForTeamForUser(userId, teamId string, options ...*store.SidebarCategorySearchOpts) (*model.OrderedSidebarCategories, error) {
appsCategoryEnabled := false
if len(options) > 0 {
appsCategoryEnabled = options[0].AppsCategoryEnabled
}
func (s SqlChannelStore) GetSidebarCategoriesForTeamForUser(userId, teamId string) (*model.OrderedSidebarCategories, error) {
opts := &store.SidebarCategorySearchOpts{
TeamID: teamId,
ExcludeTeam: false,
AppsCategoryEnabled: appsCategoryEnabled,
TeamID: teamId,
ExcludeTeam: false,
}
return s.getSidebarCategoriesT(s.GetReplicaX(), userId, opts)
}
@@ -744,22 +688,17 @@ func (s SqlChannelStore) UpdateSidebarCategoryOrder(userId, teamId string, categ
}
//nolint:unparam
func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels, options ...*store.SidebarCategorySearchOpts) (updated []*model.SidebarCategoryWithChannels, original []*model.SidebarCategoryWithChannels, err error) {
func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) (updated []*model.SidebarCategoryWithChannels, original []*model.SidebarCategoryWithChannels, err error) {
transaction, err := s.GetMasterX().Beginx()
if err != nil {
return nil, nil, errors.Wrap(err, "begin_transaction")
}
defer finalizeTransactionX(transaction, &err)
opts := &store.SidebarCategorySearchOpts{}
if len(options) > 0 {
opts = options[0]
}
updatedCategories := []*model.SidebarCategoryWithChannels{}
originalCategories := []*model.SidebarCategoryWithChannels{}
for _, category := range categories {
srcCategory, err2 := s.GetSidebarCategory(category.Id, opts)
srcCategory, err2 := s.GetSidebarCategory(category.Id)
if err2 != nil {
return nil, nil, errors.Wrap(err2, "failed to find SidebarCategories")
}
@@ -780,7 +719,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
destCategory.DisplayName = srcCategory.DisplayName
}
if destCategory.Type != model.SidebarCategoryDirectMessages && destCategory.Type != model.SidebarCategoryApps {
if destCategory.Type != model.SidebarCategoryDirectMessages {
destCategory.Channels = make([]string, len(category.Channels))
copy(destCategory.Channels, category.Channels)
@@ -807,7 +746,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
}
// if we are updating DM category, it's order can't channel order cannot be changed.
if category.Type != model.SidebarCategoryDirectMessages && destCategory.Type != model.SidebarCategoryApps {
if category.Type != model.SidebarCategoryDirectMessages {
// Remove any SidebarChannels entries that were either:
// - previously in this category (and any ones that are still in the category will be recreated below)
// - in another category and are being added to this category
@@ -904,7 +843,7 @@ func (s SqlChannelStore) UpdateSidebarCategories(userId, teamId string, categori
// Ensure Channels are populated for Channels/Direct Messages category if they change
for i, updatedCategory := range updatedCategories {
populated, nErr := s.completePopulatingCategoryChannelsT(transaction, updatedCategory, opts.AppsCategoryEnabled)
populated, nErr := s.completePopulatingCategoryChannelsT(transaction, updatedCategory)
if nErr != nil {
return nil, nil, nErr
}

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

@@ -11,5 +11,4 @@ import (
func TestChannelStoreCategories(t *testing.T) {
StoreTestWithSqlStore(t, storetest.TestChannelStoreCategories)
StoreTestWithSqlStore(t, storetest.TestChannelStoreCategoriesWithAppsCategory)
}