Skip to content

Commit

Permalink
chore: replace mattermost-server with mattermost/server/public/
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanaelhoun committed Feb 25, 2025
1 parent 9c5e60a commit d2e95e7
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"strings"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost/server/public/model"
)

//go:embed plugin.json
Expand Down
8 changes: 4 additions & 4 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin"
)

const (
Expand Down Expand Up @@ -51,7 +51,7 @@ func (p *Plugin) getAutocompleteIconData() string {
return ""
}

icon, err := ioutil.ReadFile(filepath.Join(bundlePath, "assets", "broom.svg"))
icon, err := os.ReadFile(filepath.Join(bundlePath, "assets", "broom.svg"))
if err != nil {
p.API.LogError("Failed to open icon", "error", err)
return ""
Expand Down
2 changes: 1 addition & 1 deletion server/command_last.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strconv"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost/server/public/model"

root "github.com/nathanaelhoun/mattermost-plugin-broomer"
)
Expand Down
2 changes: 1 addition & 1 deletion server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"net/http"

"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost/server/public/plugin"
)

const (
Expand Down
47 changes: 22 additions & 25 deletions server/http_dialogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,33 @@ package main

import (
"net/http"
"strconv"

"github.com/mattermost/mattermost-server/v5/model"
)

func (p *Plugin) dialogDeleteLast(w http.ResponseWriter, r *http.Request) {
request := model.SubmitDialogRequestFromJson(r.Body)
if request == nil {
w.WriteHeader(http.StatusBadRequest)
return
}
// request := model.SubmitDialogRequestFromJson(r.Body)
// if request == nil {
// w.WriteHeader(http.StatusBadRequest)
// return
// }

if request.Cancelled {
w.WriteHeader(http.StatusOK)
return
}
// if request.Canceled {
// w.WriteHeader(http.StatusOK)
// return
// }

numPostToDelete, err := strconv.Atoi(request.State)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
// numPostToDelete, err := strconv.Atoi(request.State)
// if err != nil {
// w.WriteHeader(http.StatusBadRequest)
// return
// }

w.WriteHeader(http.StatusOK)
// w.WriteHeader(http.StatusOK)

p.deleteLastPostsInChannel(&deletionOptions{
channelID: request.ChannelId,
userID: request.UserId,
numPost: numPostToDelete,
optDeletePinnedPosts: request.Submission["deletePinnedPost"] == "true",
permDeleteOthersPosts: canDeleteOthersPosts(p, request.UserId, request.ChannelId),
})
// p.deleteLastPostsInChannel(&deletionOptions{
// channelID: request.ChannelId,
// userID: request.UserId,
// numPost: numPostToDelete,
// optDeletePinnedPosts: request.Submission["deletePinnedPost"] == "true",
// permDeleteOthersPosts: canDeleteOthersPosts(p, request.UserId, request.ChannelId),
// })
}
2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost/server/public/plugin"
)

func main() {
Expand Down
11 changes: 6 additions & 5 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package main
import (
"sync"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost-server/v5/plugin"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/plugin"
"github.com/mattermost/mattermost/server/public/pluginapi"
"github.com/pkg/errors"
)

// Plugin implements the interface expected by the Mattermost server to communicate between the server and plugin processes.
type Plugin struct {
plugin.MattermostPlugin
client *pluginapi.Client

// configurationLock synchronizes access to the configuration.
configurationLock sync.RWMutex
Expand All @@ -28,14 +30,13 @@ func (p *Plugin) OnActivate() error {
return errors.Errorf("SiteURL is not configured. Please head to the System Console > Environment > Web Server > Site URL")
}

botUserID, err := p.Helpers.EnsureBot(
botUserID, err := p.client.Bot.EnsureBot(
&model.Bot{
Username: "broomerbot",
DisplayName: "Broomer",
Description: "Bot managed by the Broomer plugin.",
},
plugin.IconImagePath("/assets/broom.svg"),
plugin.ProfileImagePath("/assets/broom.png"),
pluginapi.ProfileImagePath("/assets/broom.png"),
)
if err != nil {
return errors.Wrap(err, "Failed to ensure bot")
Expand Down
10 changes: 5 additions & 5 deletions server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"strings"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost/server/public/model"
)

// Checks if the user has sysadmin permission
Expand All @@ -19,14 +19,14 @@ func isSysadmin(p *Plugin, userID string) bool {

// Checks if the user has the "delete_post" permission
func canDeletePost(p *Plugin, userID string, channelID string) bool {
return p.API.HasPermissionTo(userID, model.PERMISSION_DELETE_POST) ||
p.API.HasPermissionToChannel(userID, channelID, model.PERMISSION_DELETE_POST)
return p.API.HasPermissionTo(userID, model.PermissionDeletePost) ||
p.API.HasPermissionToChannel(userID, channelID, model.PermissionDeletePost)
}

// Checks if the user has the "delete_others_posts" permission
func canDeleteOthersPosts(p *Plugin, userID string, channelID string) bool {
return p.API.HasPermissionTo(userID, model.PERMISSION_DELETE_OTHERS_POSTS) ||
p.API.HasPermissionToChannel(userID, channelID, model.PERMISSION_DELETE_OTHERS_POSTS)
return p.API.HasPermissionTo(userID, model.PermissionDeleteOthersPosts) ||
p.API.HasPermissionToChannel(userID, channelID, model.PermissionDeleteOthersPosts)
}

// Returns "s" if the given number is > 1
Expand Down
4 changes: 2 additions & 2 deletions server/utils_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strconv"
"strings"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost/server/public/model"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -86,7 +86,7 @@ func (p *Plugin) parseAndCheckCommandArgs(args *model.CommandArgs) (string, *del
}

if numPostToDelete64 < 1 {
return subcommand, nil, errors.Errorf("You may want to delete at least one post :wink:")
return subcommand, nil, errors.Errorf("You may want to delete at least one post :wink: ")
}

currentChannel, appErr := p.API.GetChannel(args.ChannelId)
Expand Down
2 changes: 1 addition & 1 deletion server/utils_posts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"fmt"

"github.com/mattermost/mattermost-server/v5/model"
"github.com/mattermost/mattermost/server/public/model"
)

// getRelevantPostList filters out the unwanted posts and return the postList with the relevant posts
Expand Down

0 comments on commit d2e95e7

Please sign in to comment.