1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-24 08:22:29 +02:00
focalboard/server/app/subscriptions.go
Doug Lauder 75bd409ba0
Notifications phase 1 (#1851)
Backend support for subscribing/unsubscribing to blocks, typically cards and boards. Notifies subscribers when changes are made to cards they are subscribed to.
2021-12-10 10:46:37 -05:00

43 lines
1.2 KiB
Go

package app
import (
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/store"
"github.com/mattermost/focalboard/server/utils"
)
func (a *App) CreateSubscription(c store.Container, sub *model.Subscription) (*model.Subscription, error) {
sub, err := a.store.CreateSubscription(c, sub)
if err != nil {
return nil, err
}
a.notifySubscriptionChanged(c, sub)
return sub, nil
}
func (a *App) DeleteSubscription(c store.Container, blockID string, subscriberID string) (*model.Subscription, error) {
sub, err := a.store.GetSubscription(c, blockID, subscriberID)
if err != nil {
return nil, err
}
if err := a.store.DeleteSubscription(c, blockID, subscriberID); err != nil {
return nil, err
}
sub.DeleteAt = utils.GetMillis()
a.notifySubscriptionChanged(c, sub)
return sub, nil
}
func (a *App) GetSubscriptions(c store.Container, subscriberID string) ([]*model.Subscription, error) {
return a.store.GetSubscriptions(c, subscriberID)
}
func (a *App) notifySubscriptionChanged(c store.Container, subscription *model.Subscription) {
if a.notifications == nil {
return
}
a.notifications.BroadcastSubscriptionChange(c.WorkspaceID, subscription)
}