mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
* [MM-68037] Managed Sidebar Categories (MVF) * PR feedback * PR feedback * Fix test issue again * Fixed a few things * Fix again * PR feedback * Update server/i18n/en.json Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update server/i18n/en.json Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * PR feedback * PR feedback * More PR feedback * Test fixes * This one too * PR feedback * more * More feedback * More * more * Yup * More * PR feedback * Update webapp/channels/src/components/channel_settings_modal/managed_category_selector.scss Co-authored-by: Matthew Birtch <[email protected]> * Block setting behind Enterprise license * Update webapp/channels/src/packages/mattermost-redux/src/selectors/entities/channel_categories.ts Co-authored-by: Harrison Healey <[email protected]> * Update webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts Co-authored-by: Harrison Healey <[email protected]> * PR feedback * Don't await for the initial managed category check * Turn into its own action --------- Co-authored-by: Mattermost Build <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Matthew Birtch <[email protected]> Co-authored-by: Harrison Healey <[email protected]>
102 lines
3.5 KiB
Go
102 lines
3.5 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"regexp"
|
|
)
|
|
|
|
type SidebarCategoryType string
|
|
type SidebarCategorySorting string
|
|
|
|
const (
|
|
// Each sidebar category has a 'type'. System categories are Channels, Favorites and DMs
|
|
// All user-created categories will have type Custom
|
|
SidebarCategoryChannels SidebarCategoryType = "channels"
|
|
SidebarCategoryDirectMessages SidebarCategoryType = "direct_messages"
|
|
SidebarCategoryFavorites SidebarCategoryType = "favorites"
|
|
SidebarCategoryCustom SidebarCategoryType = "custom"
|
|
SidebarCategoryManaged SidebarCategoryType = "managed"
|
|
// Increment to use when adding/reordering things in the sidebar
|
|
MinimalSidebarSortDistance = 10
|
|
// Default Sort Orders for categories
|
|
DefaultSidebarSortOrderFavorites = 0
|
|
DefaultSidebarSortOrderChannels = DefaultSidebarSortOrderFavorites + MinimalSidebarSortDistance
|
|
DefaultSidebarSortOrderDMs = DefaultSidebarSortOrderChannels + MinimalSidebarSortDistance
|
|
// Sorting modes
|
|
// default for all categories except DMs (behaves like manual)
|
|
SidebarCategorySortDefault SidebarCategorySorting = ""
|
|
// sort manually
|
|
SidebarCategorySortManual SidebarCategorySorting = "manual"
|
|
// sort by recency (default for DMs)
|
|
SidebarCategorySortRecent SidebarCategorySorting = "recent"
|
|
// sort by display name alphabetically
|
|
SidebarCategorySortAlphabetical SidebarCategorySorting = "alpha"
|
|
|
|
ManagedCategoryPropertyGroupName = "managed_channel_categories"
|
|
ManagedCategoryPropertyFieldName = "category_name"
|
|
)
|
|
|
|
// SidebarCategory represents the corresponding DB table
|
|
type SidebarCategory struct {
|
|
Id string `json:"id"`
|
|
UserId string `json:"user_id"`
|
|
TeamId string `json:"team_id"`
|
|
SortOrder int64 `json:"sort_order"`
|
|
Sorting SidebarCategorySorting `json:"sorting"`
|
|
Type SidebarCategoryType `json:"type"`
|
|
DisplayName string `json:"display_name"`
|
|
Muted bool `json:"muted"`
|
|
Collapsed bool `json:"collapsed"`
|
|
}
|
|
|
|
// SidebarCategoryWithChannels combines data from SidebarCategory table with the Channel IDs that belong to that category
|
|
type SidebarCategoryWithChannels struct {
|
|
SidebarCategory
|
|
Channels []string `json:"channel_ids"`
|
|
}
|
|
|
|
func (sc SidebarCategoryWithChannels) ChannelIds() []string {
|
|
return sc.Channels
|
|
}
|
|
|
|
type SidebarCategoryOrder []string
|
|
|
|
// OrderedSidebarCategories combines categories, their channel IDs and an array of Category IDs, sorted
|
|
type OrderedSidebarCategories struct {
|
|
Categories SidebarCategoriesWithChannels `json:"categories"`
|
|
Order SidebarCategoryOrder `json:"order"`
|
|
}
|
|
|
|
type SidebarChannel struct {
|
|
ChannelId string `json:"channel_id"`
|
|
UserId string `json:"user_id"`
|
|
CategoryId string `json:"category_id"`
|
|
SortOrder int64 `json:"-"`
|
|
}
|
|
|
|
type SidebarChannels []*SidebarChannel
|
|
type SidebarCategoriesWithChannels []*SidebarCategoryWithChannels
|
|
|
|
var categoryIdPattern = regexp.MustCompile("(favorites|channels|direct_messages)_[a-z0-9]{26}_[a-z0-9]{26}")
|
|
|
|
func IsValidCategoryId(s string) bool {
|
|
// Category IDs can either be regular IDs
|
|
if IsValidId(s) {
|
|
return true
|
|
}
|
|
|
|
// Or default categories can follow the pattern {type}_{userID}_{teamID}
|
|
return categoryIdPattern.MatchString(s)
|
|
}
|
|
|
|
func (t SidebarCategoryType) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(string(t))
|
|
}
|
|
|
|
func (t SidebarCategorySorting) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(string(t))
|
|
}
|