Skip to content

Commit

Permalink
Fix mentions delivery (#2358)
Browse files Browse the repository at this point in the history
* fix sql syntax error for SearchUsersByTeam

* fix mentions delivery

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
  • Loading branch information
wiggin77 and mattermod authored Feb 18, 2022
1 parent 48c2282 commit a588a4d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 27 deletions.
2 changes: 1 addition & 1 deletion server/app/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (a *App) notifyBlockChanged(action notify.Action, block *model.Block, oldBl

evt := notify.BlockChangeEvent{
Action: action,
Team: board.TeamID,
TeamID: board.TeamID,
Board: board,
Card: card,
BlockChanged: block,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (b *Backend) BlockChanged(evt notify.BlockChangeEvent) error {
mlog.Err(err),
)
}
b.wsAdapter.BroadcastSubscriptionChange(evt.Team, sub)
b.wsAdapter.BroadcastSubscriptionChange(evt.TeamID, sub)
}

// notify board subscribers
Expand Down Expand Up @@ -200,7 +200,7 @@ func (b *Backend) OnMention(userID string, evt notify.BlockChangeEvent) {
)
return
}
b.wsAdapter.BroadcastSubscriptionChange(evt.Team, sub)
b.wsAdapter.BroadcastSubscriptionChange(evt.TeamID, sub)

b.logger.Debug("Subscribed mentioned user to card",
mlog.String("user_id", userID),
Expand Down
7 changes: 1 addition & 6 deletions server/services/notify/plugindelivery/mention_deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import (

// MentionDeliver notifies a user they have been mentioned in a block.
func (pd *PluginDelivery) MentionDeliver(mentionUsername string, extract string, evt notify.BlockChangeEvent) (string, error) {
teamID, err := pd.getTeamID(evt)
if err != nil {
return "", fmt.Errorf("cannot determine teamID for block change notification: %w", err)
}

member, err := teamMemberFromUsername(pd.api, mentionUsername, teamID)
member, err := teamMemberFromUsername(pd.api, mentionUsername, evt.TeamID)
if err != nil {
if isErrNotFound(err) {
// not really an error; could just be someone typed "@sometext"
Expand Down
19 changes: 2 additions & 17 deletions server/services/notify/plugindelivery/plugin_delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ func New(botID string, serverRoot string, api PluginAPI) *PluginDelivery {
}

func (pd *PluginDelivery) Deliver(mentionUsername string, extract string, evt notify.BlockChangeEvent) error {
// determine which team the workspace is associated with
teamID, err := pd.getTeamID(evt)
if err != nil {
return fmt.Errorf("cannot determine teamID for block change notification: %w", err)
}

member, err := teamMemberFromUsername(pd.api, mentionUsername, teamID)
member, err := teamMemberFromUsername(pd.api, mentionUsername, evt.TeamID)
if err != nil {
if isErrNotFound(err) {
// not really an error; could just be someone typed "@sometext"
Expand All @@ -81,7 +75,7 @@ func (pd *PluginDelivery) Deliver(mentionUsername string, extract string, evt no
if err != nil {
return fmt.Errorf("cannot get direct channel: %w", err)
}
link := makeLink(pd.serverRoot, evt.Team, evt.Board.ID, evt.Card.ID)
link := makeLink(pd.serverRoot, evt.TeamID, evt.Board.ID, evt.Card.ID)

post := &model.Post{
UserId: pd.botID,
Expand All @@ -90,12 +84,3 @@ func (pd *PluginDelivery) Deliver(mentionUsername string, extract string, evt no
}
return pd.api.CreatePost(post)
}

func (pd *PluginDelivery) getTeamID(evt notify.BlockChangeEvent) (string, error) {
// for now, the workspace ID is also the channel ID
channel, err := pd.api.GetChannelByID(evt.Team)
if err != nil {
return "", err
}
return channel.TeamId, nil
}
2 changes: 1 addition & 1 deletion server/services/notify/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (

type BlockChangeEvent struct {
Action Action
Team string
TeamID string
Board *model.Board
Card *model.Block
BlockChanged *model.Block
Expand Down

0 comments on commit a588a4d

Please sign in to comment.