605c0079eb
* skeleton lifecycle * bare minimum to satisfy mm-server import * added boards_imports.go * move boards_imports.go to correct package * bump mmserver version; remove replace in go.mod; use module workspaces; remove logger service * rename product.go --> boards.go * add FileInfoStore and Cloud services for product; create minimal pluginAPI interfaces for all packages * rename Boards -> BoardsProduct * compile success * remove hooks service; guard for nil BoardsApp * update to latest mmserver ver * upgrade mmserver to master tip * upgrade mmserver to master tip * bump plugin-api to master tip * fix users service * fix OnActivate crash; normalize AppError returns * fileBackend interface for server/app * feature flag * bump mmserver version * fix linter errors * make go.work when linting * fix go.work creation for CI * add execute flag for script * fix more linter errors * always create a go.work * fix ci go.work * OS agnostic go.work generator * fix path * fix path again * partially disable cypress test * fix case Id --> ID * bump mmserver version * include in go.work for dev * addressed review comments. Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package plugindelivery
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/mattermost/focalboard/server/services/notify"
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
|
|
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
|
)
|
|
|
|
// MentionDeliver notifies a user they have been mentioned in a blockv ia the plugin API.
|
|
func (pd *PluginDelivery) MentionDeliver(mentionedUser *mm_model.User, extract string, evt notify.BlockChangeEvent) (string, error) {
|
|
author, err := pd.api.GetUserByID(evt.ModifiedBy.UserID)
|
|
if err != nil {
|
|
return "", fmt.Errorf("cannot find user: %w", err)
|
|
}
|
|
|
|
channel, err := pd.getDirectChannel(evt.TeamID, mentionedUser.Id, pd.botID)
|
|
if err != nil {
|
|
return "", fmt.Errorf("cannot get direct channel: %w", err)
|
|
}
|
|
link := utils.MakeCardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID, evt.Card.ID)
|
|
boardLink := utils.MakeBoardLink(pd.serverRoot, evt.Board.TeamID, evt.Board.ID)
|
|
|
|
post := &mm_model.Post{
|
|
UserId: pd.botID,
|
|
ChannelId: channel.Id,
|
|
Message: formatMessage(author.Username, extract, evt.Card.Title, link, evt.BlockChanged, boardLink, evt.Board.Title),
|
|
}
|
|
|
|
if _, err := pd.api.CreatePost(post); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return mentionedUser.Id, nil
|
|
}
|