returns the updated block count for the parent object
(ctx context.Context, blockId string)
| 192 | |
| 193 | // returns the updated block count for the parent object |
| 194 | func deleteBlockObj(ctx context.Context, blockId string) (int, error) { |
| 195 | return wstore.WithTxRtn(ctx, func(tx *wstore.TxWrap) (int, error) { |
| 196 | block, err := wstore.DBGet[*waveobj.Block](tx.Context(), blockId) |
| 197 | if err != nil { |
| 198 | return -1, fmt.Errorf("error getting block: %w", err) |
| 199 | } |
| 200 | if block == nil { |
| 201 | return -1, fmt.Errorf("block not found: %q", blockId) |
| 202 | } |
| 203 | if len(block.SubBlockIds) > 0 { |
| 204 | return -1, fmt.Errorf("block has subblocks, must delete subblocks first") |
| 205 | } |
| 206 | parentORef := waveobj.ParseORefNoErr(block.ParentORef) |
| 207 | parentBlockCount := -1 |
| 208 | if parentORef != nil { |
| 209 | if parentORef.OType == waveobj.OType_Tab { |
| 210 | tab, _ := wstore.DBGet[*waveobj.Tab](tx.Context(), parentORef.OID) |
| 211 | if tab != nil { |
| 212 | tab.BlockIds = utilfn.RemoveElemFromSlice(tab.BlockIds, blockId) |
| 213 | wstore.DBUpdate(tx.Context(), tab) |
| 214 | parentBlockCount = len(tab.BlockIds) |
| 215 | } |
| 216 | } else if parentORef.OType == waveobj.OType_Block { |
| 217 | parentBlock, _ := wstore.DBGet[*waveobj.Block](tx.Context(), parentORef.OID) |
| 218 | if parentBlock != nil { |
| 219 | parentBlock.SubBlockIds = utilfn.RemoveElemFromSlice(parentBlock.SubBlockIds, blockId) |
| 220 | wstore.DBUpdate(tx.Context(), parentBlock) |
| 221 | parentBlockCount = len(parentBlock.SubBlockIds) |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | wstore.DBDelete(tx.Context(), waveobj.OType_Block, blockId) |
| 226 | |
| 227 | // Clean up block runtime info |
| 228 | blockORef := waveobj.MakeORef(waveobj.OType_Block, blockId) |
| 229 | wstore.DeleteRTInfo(blockORef) |
| 230 | |
| 231 | return parentBlockCount, nil |
| 232 | }) |
| 233 | } |
| 234 | |
| 235 | func sendBlockCloseEvent(blockId string) { |
| 236 | waveEvent := wps.WaveEvent{ |
no test coverage detected