Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/plugin/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ func (p *Plugin) handleUnsubscribe(_ *plugin.Context, args *model.CommandArgs, p
owner = strings.ToLower(owner)
repo = strings.ToLower(repo)
if err := p.Unsubscribe(args.ChannelId, repo, owner); err != nil {
if strings.Contains(err.Error(), "no subscription exists") {
return err.Error()
}
Comment thread
Kshitij-Katiyar marked this conversation as resolved.
Outdated

p.client.Log.Warn("Failed to unsubscribe", "repo", repo, "error", err.Error())
return "Encountered an error trying to unsubscribe. Please try again."
}
Expand Down
15 changes: 9 additions & 6 deletions server/plugin/subscriptions.go
Comment thread
abbas-dependable-naqvi marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (
)

const (
SubscriptionsKey = "subscriptions"
flagExcludeOrgMember = "exclude-org-member"
flagRenderStyle = "render-style"
flagFeatures = "features"
flagExcludeRepository = "exclude"
SubscriptionsKey = "subscriptions"
flagExcludeOrgMember = "exclude-org-member"
flagRenderStyle = "render-style"
flagFeatures = "features"
flagExcludeRepository = "exclude"
SubscriptionUnavailable = "no subscription exists for `%s` in the channel"
)

type SubscriptionFlags struct {
Expand Down Expand Up @@ -388,7 +389,7 @@ func (p *Plugin) Unsubscribe(channelID, repo, owner string) error {

repoSubs := subs.Repositories[repoWithOwner]
if repoSubs == nil {
return nil
return errors.Errorf(SubscriptionUnavailable, strings.TrimSuffix(repoWithOwner, "/"))
}

removed := false
Expand All @@ -405,6 +406,8 @@ func (p *Plugin) Unsubscribe(channelID, repo, owner string) error {
if err := p.StoreSubscriptions(subs); err != nil {
return errors.Wrap(err, "could not store subscriptions")
}
} else {
return errors.Errorf(SubscriptionUnavailable, strings.TrimSuffix(repoWithOwner, "/"))
}
Comment thread
Kshitij-Katiyar marked this conversation as resolved.

return nil
Expand Down
3 changes: 3 additions & 0 deletions server/plugin/test_utils.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

package plugin

import (
Expand Down
Loading