1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-18 09:35:25 +02:00
focalboard/server/app/blocks.go

90 lines
2.0 KiB
Go
Raw Normal View History

package app
import (
"github.com/mattermost/mattermost-octo-tasks/server/model"
)
func (a *App) GetBlocks(parentID string, blockType string) ([]model.Block, error) {
if len(blockType) > 0 && len(parentID) > 0 {
return a.store.GetBlocksWithParentAndType(parentID, blockType)
}
if len(blockType) > 0 {
return a.store.GetBlocksWithType(blockType)
}
return a.store.GetBlocksWithParent(parentID)
}
2021-01-13 04:49:08 +02:00
func (a *App) GetRootID(blockID string) (string, error) {
return a.store.GetRootID(blockID)
}
func (a *App) GetParentID(blockID string) (string, error) {
return a.store.GetParentID(blockID)
}
func (a *App) InsertBlock(block model.Block) error {
return a.store.InsertBlock(block)
}
func (a *App) InsertBlocks(blocks []model.Block) error {
blockIDsToNotify := []string{}
uniqueBlockIDs := make(map[string]bool)
for _, block := range blocks {
if !uniqueBlockIDs[block.ID] {
blockIDsToNotify = append(blockIDsToNotify, block.ID)
}
// ParentID as empty string denotes a block at the root
if !uniqueBlockIDs[block.ParentID] {
blockIDsToNotify = append(blockIDsToNotify, block.ParentID)
}
err := a.store.InsertBlock(block)
if err != nil {
return err
}
2020-10-29 22:09:02 +02:00
2020-11-06 20:11:01 +02:00
a.wsServer.BroadcastBlockChange(block)
2020-11-02 19:07:05 +02:00
go a.webhook.NotifyUpdate(block)
}
return nil
}
2020-11-12 20:16:59 +02:00
func (a *App) GetSubTree(blockID string, levels int) ([]model.Block, error) {
// Only 2 or 3 levels are supported for now
if levels >= 3 {
return a.store.GetSubTree3(blockID)
}
return a.store.GetSubTree2(blockID)
}
func (a *App) GetAllBlocks() ([]model.Block, error) {
return a.store.GetAllBlocks()
}
2021-01-12 21:16:25 +02:00
func (a *App) DeleteBlock(blockID string, modifiedBy string) error {
blockIDsToNotify := []string{blockID}
parentID, err := a.GetParentID(blockID)
if err != nil {
return err
}
if len(parentID) > 0 {
blockIDsToNotify = append(blockIDsToNotify, parentID)
}
2021-01-12 21:16:25 +02:00
err = a.store.DeleteBlock(blockID, modifiedBy)
if err != nil {
return err
}
2020-11-06 20:11:01 +02:00
a.wsServer.BroadcastBlockDelete(blockID, parentID)
return nil
}