Per-channel retention config, daily scheduled cleanup, slash command and REST API support, plus a single Channel cleanup menu that opens a plugin modal for configure, run-now, and disable actions. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/mattermost/mattermost/server/public/plugin"
|
|
"github.com/mattermost/mattermost/server/public/pluginapi"
|
|
"github.com/mattermost/mattermost/server/public/pluginapi/cluster"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/fmartingr/mattermost-plugin-cleanup-channel/server/autocleanup"
|
|
"github.com/fmartingr/mattermost-plugin-cleanup-channel/server/command"
|
|
)
|
|
|
|
type Plugin struct {
|
|
plugin.MattermostPlugin
|
|
|
|
client *pluginapi.Client
|
|
commandClient command.Command
|
|
router *mux.Router
|
|
autoCleanupStore *autocleanup.Store
|
|
autoCleanupJob *cluster.Job
|
|
}
|
|
|
|
func (p *Plugin) OnActivate() error {
|
|
p.client = pluginapi.NewClient(p.API, p.Driver)
|
|
p.autoCleanupStore = autocleanup.NewStore(p.client)
|
|
p.commandClient = command.NewCommandHandler(p.client, p.autoCleanupStore, p.cleanupChannel)
|
|
p.router = p.initRouter()
|
|
|
|
runner := autocleanup.NewRunner(p.autoCleanupStore, p.autoCleanupChannel)
|
|
job, err := autocleanup.ScheduleDaily(p.API, runner)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to schedule auto cleanup job")
|
|
}
|
|
p.autoCleanupJob = job
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *Plugin) OnDeactivate() error {
|
|
if p.autoCleanupJob != nil {
|
|
if err := p.autoCleanupJob.Close(); err != nil {
|
|
return errors.Wrap(err, "failed to close auto cleanup job")
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
|
response, err := p.commandClient.Handle(args)
|
|
if err != nil {
|
|
return nil, model.NewAppError("ExecuteCommand", "plugin.command.execute_command.app_error", nil, err.Error(), http.StatusInternalServerError)
|
|
}
|
|
|
|
return response, nil
|
|
}
|