Shared channels plugin APIs for MS Teams plugin (#25805)
New plugin APIs and hooks for accessing Shared Channels service via plugin. - RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error) - UnregisterPluginForSharedChannels(pluginID string) error - ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error) - UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error) - UnshareChannel(channelID string) (unshared bool, err error) - UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error - SyncSharedChannel(channelID string) error - InviteRemoteToChannel(channelID string, remoteID string, userID string) error - UninviteRemoteFromChannel(channelID string, remoteID string) error Hooks - OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error) - OnSharedChannelsPing(rc *model.RemoteCluster) bool
Этот коммит содержится в:
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -14,6 +15,57 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
)
|
||||
|
||||
func (a *App) RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error) {
|
||||
// check for pluginID already registered
|
||||
rc, err := a.Srv().Store().RemoteCluster().GetByPluginID(opts.PluginID)
|
||||
if err != nil {
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
// anything other than not_found is unrecoverable
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
// if plugin is already registered then treat this as an update.
|
||||
if rc != nil {
|
||||
rc.DisplayName = opts.Displayname
|
||||
rc.Options = opts.GetOptionFlags()
|
||||
|
||||
if _, err = a.Srv().Store().RemoteCluster().Update(rc); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return rc.RemoteId, nil
|
||||
}
|
||||
|
||||
rc = &model.RemoteCluster{
|
||||
Name: opts.Displayname,
|
||||
DisplayName: opts.Displayname,
|
||||
Token: model.NewId(),
|
||||
CreatorId: opts.CreatorID,
|
||||
PluginID: opts.PluginID,
|
||||
Options: opts.GetOptionFlags(),
|
||||
}
|
||||
|
||||
rcSaved, err := a.Srv().Store().RemoteCluster().Save(rc)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return rcSaved.RemoteId, nil
|
||||
}
|
||||
|
||||
func (a *App) UnregisterPluginForSharedChannels(pluginID string) error {
|
||||
rc, err := a.Srv().Store().RemoteCluster().GetByPluginID(pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, appErr := a.DeleteRemoteCluster(rc.RemoteId)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) AddRemoteCluster(rc *model.RemoteCluster) (*model.RemoteCluster, *model.AppError) {
|
||||
rc, err := a.Srv().Store().RemoteCluster().Save(rc)
|
||||
if err != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user