main

mattermost/focalboard

Last updated at: 29/12/2023 09:40

util.go

TLDR

This file contains functions and a type definition related to handling notification subscriptions.

Methods

getBoardDescription

This method takes a model.Block object representing a board and returns the description of the board as a string. If the board is nil or if the description field is not present or not a string, an empty string is returned.

stripNewlines

This method takes a string and removes leading and trailing whitespaces, as well as replaces newline characters with "¶ ". The modified string is then returned.

Type

StringMap

This type is an alias for the map[string]string type. It provides additional methods for adding, appending, retrieving keys, and retrieving values from the map.

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

package notifysubscriptions

import (
	"strings"

	"github.com/mattermost/focalboard/server/model"
)

func getBoardDescription(board *model.Block) string {
	if board == nil {
		return ""
	}

	descr, ok := board.Fields["description"]
	if !ok {
		return ""
	}

	description, ok := descr.(string)
	if !ok {
		return ""
	}

	return description
}

func stripNewlines(s string) string {
	return strings.TrimSpace(strings.ReplaceAll(s, "\n", "¶ "))
}

type StringMap map[string]string

func (sm StringMap) Add(k string, v string) {
	sm[k] = v
}

func (sm StringMap) Append(m StringMap) {
	for k, v := range m {
		sm[k] = v
	}
}

func (sm StringMap) Keys() []string {
	keys := make([]string, 0, len(sm))
	for k := range sm {
		keys = append(keys, k)
	}
	return keys
}

func (sm StringMap) Values() []string {
	values := make([]string, 0, len(sm))
	for _, v := range sm {
		values = append(values, v)
	}
	return values
}