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
Этот коммит содержится в:
Doug Lauder
2023-12-22 17:00:27 -05:00
коммит произвёл GitHub
родитель 0f3553c8ab
Коммит 2d1135ca46
40 изменённых файлов: 1725 добавлений и 168 удалений

Просмотреть файл

@@ -297,3 +297,21 @@ type SyncResponse struct {
ReactionsLastUpdateAt int64 `json:"reactions_last_update_at"`
ReactionErrors []string `json:"reaction_errors"`
}
// RegisterPluginOpts is passed by plugins to the `RegisterPluginForSharedChannels` plugin API
// to provide options for registering as a shared channels remote.
type RegisterPluginOpts struct {
Displayname string // a displayname used in status reports
PluginID string // id of this plugin registering
CreatorID string // id of the user/bot registering
AutoShareDMs bool // when true, all DMs are automatically shared to this remote
}
// GetOptionFlags returns a Bitmask of option flags as specified by the boolean options.
func (po RegisterPluginOpts) GetOptionFlags() Bitmask {
var flags Bitmask
if po.AutoShareDMs {
flags |= BitflagOptionAutoShareDMs
}
return flags
}

Просмотреть файл

@@ -32,7 +32,7 @@ type API interface {
// Minimum server version: 5.2
RegisterCommand(command *model.Command) error
// UnregisterCommand unregisters a command previously registered via RegisterCommand.
// UnregisterCommand unregisters a command previously register via RegisterCommand.
//
// @tag Command
// Minimum server version: 5.2
@@ -1207,6 +1207,73 @@ type API interface {
// @tag User
// Minimum server version: 9.3
UpdateUserAuth(userID string, userAuth *model.UserAuth) (*model.UserAuth, *model.AppError)
// RegisterPluginForSharedChannels registers the plugin as a `Remote` for SharedChannels.
// The plugin will receive synchronization messages via the `OnSharedChannelsSyncMsg` hook.
// This API is idempotent - when called repeatedly with the same `RegisterPluginOpts.PluginID`
// it will return the same remoteID.
//
// @tag SharedChannels
// Minimum server version: 9.5
RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error)
// UnregisterPluginForSharedChannels unregisters the plugin as a `Remote` for SharedChannels.
// The plugin will no longer receive synchronization messages via the `OnSharedChannelsSyncMsg` hook.
//
// @tag SharedChannels
// Minimum server version: 9.5
UnregisterPluginForSharedChannels(pluginID string) error
// ShareChannel marks a channel for sharing via shared channels. Note, this does not automatically
// invite any remote clusters to the channel - use `InviteRemote` to invite a remote , or this plugin,
// to the shared channel and start synchronization.
//
// @tag SharedChannels
// Minimum server version: 9.5
ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
// UpdateSharedChannel updates a shared channel. This can be used to change the share name,
// display name, purpose, header, etc.
//
// @tag SharedChannels
// Minimum server version: 9.5
UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
// UnshareChannel unmarks a channel for sharing. The channel will no longer be shared and
// all remotes will be uninvited to the channel.
//
// @tag SharedChannels
// Minimum server version: 9.5
UnshareChannel(channelID string) (unshared bool, err error)
// UpdateSharedChannelCursor updates the cursor for the specified channel and RemoteID (passed by
// the plugin when registering). This can be used to manually set the point of last sync, either
// forward to skip older posts, or backward to re-sync history. This call by itself does not force
// a re-sync - a change to channel contents or a call to SyncSharedChannel are needed to force a sync.
//
// @tag SharedChannels
// Minimum server version: 9.5
UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error
// SyncSharedChannel forces a shared channel to send any changed content to all remotes.
//
// @tag SharedChannels
// Minimum server version: 9.5
SyncSharedChannel(channelID string) error
// InviteRemoteToChannel invites a remote, or this plugin, as a target for synchronizing. Once invited, the
// remote will start to receive synchronization messages for any changed content in the specified channel.
//
// @tag SharedChannels
// Minimum server version: 9.5
InviteRemoteToChannel(channelID string, remoteID string, userID string) error
// UninviteRemoteFromChannel uninvites a remote, or this plugin, such that it will stop receiving sychronization
// messages for the channel.
//
// @tag SharedChannels
// Minimum server version: 9.5
UninviteRemoteFromChannel(channelID string, remoteID string) error
}
var handshake = plugin.HandshakeConfig{

Просмотреть файл

@@ -1287,3 +1287,66 @@ func (api *apiTimerLayer) UpdateUserAuth(userID string, userAuth *model.UserAuth
api.recordTime(startTime, "UpdateUserAuth", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.RegisterPluginForSharedChannels(opts)
api.recordTime(startTime, "RegisterPluginForSharedChannels", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) UnregisterPluginForSharedChannels(pluginID string) error {
startTime := timePkg.Now()
_returnsA := api.apiImpl.UnregisterPluginForSharedChannels(pluginID)
api.recordTime(startTime, "UnregisterPluginForSharedChannels", _returnsA == nil)
return _returnsA
}
func (api *apiTimerLayer) ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.ShareChannel(sc)
api.recordTime(startTime, "ShareChannel", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.UpdateSharedChannel(sc)
api.recordTime(startTime, "UpdateSharedChannel", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) UnshareChannel(channelID string) (unshared bool, err error) {
startTime := timePkg.Now()
_returnsA, _returnsB := api.apiImpl.UnshareChannel(channelID)
api.recordTime(startTime, "UnshareChannel", _returnsB == nil)
return _returnsA, _returnsB
}
func (api *apiTimerLayer) UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error {
startTime := timePkg.Now()
_returnsA := api.apiImpl.UpdateSharedChannelCursor(channelID, remoteID, cusror)
api.recordTime(startTime, "UpdateSharedChannelCursor", _returnsA == nil)
return _returnsA
}
func (api *apiTimerLayer) SyncSharedChannel(channelID string) error {
startTime := timePkg.Now()
_returnsA := api.apiImpl.SyncSharedChannel(channelID)
api.recordTime(startTime, "SyncSharedChannel", _returnsA == nil)
return _returnsA
}
func (api *apiTimerLayer) InviteRemoteToChannel(channelID string, remoteID string, userID string) error {
startTime := timePkg.Now()
_returnsA := api.apiImpl.InviteRemoteToChannel(channelID, remoteID, userID)
api.recordTime(startTime, "InviteRemoteToChannel", _returnsA == nil)
return _returnsA
}
func (api *apiTimerLayer) UninviteRemoteFromChannel(channelID string, remoteID string) error {
startTime := timePkg.Now()
_returnsA := api.apiImpl.UninviteRemoteFromChannel(channelID, remoteID)
api.recordTime(startTime, "UninviteRemoteFromChannel", _returnsA == nil)
return _returnsA
}

Просмотреть файл

@@ -947,6 +947,77 @@ func (s *hooksRPCServer) UserHasBeenDeactivated(args *Z_UserHasBeenDeactivatedAr
return nil
}
func init() {
hookNameToId["OnSharedChannelsSyncMsg"] = OnSharedChannelsSyncMsgID
}
type Z_OnSharedChannelsSyncMsgArgs struct {
A *model.SyncMsg
B *model.RemoteCluster
}
type Z_OnSharedChannelsSyncMsgReturns struct {
A model.SyncResponse
B error
}
func (g *hooksRPCClient) OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error) {
_args := &Z_OnSharedChannelsSyncMsgArgs{msg, rc}
_returns := &Z_OnSharedChannelsSyncMsgReturns{}
if g.implemented[OnSharedChannelsSyncMsgID] {
if err := g.client.Call("Plugin.OnSharedChannelsSyncMsg", _args, _returns); err != nil {
g.log.Error("RPC call OnSharedChannelsSyncMsg to plugin failed.", mlog.Err(err))
}
}
return _returns.A, _returns.B
}
func (s *hooksRPCServer) OnSharedChannelsSyncMsg(args *Z_OnSharedChannelsSyncMsgArgs, returns *Z_OnSharedChannelsSyncMsgReturns) error {
if hook, ok := s.impl.(interface {
OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error)
}); ok {
returns.A, returns.B = hook.OnSharedChannelsSyncMsg(args.A, args.B)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("Hook OnSharedChannelsSyncMsg called but not implemented."))
}
return nil
}
func init() {
hookNameToId["OnSharedChannelsPing"] = OnSharedChannelsPingID
}
type Z_OnSharedChannelsPingArgs struct {
A *model.RemoteCluster
}
type Z_OnSharedChannelsPingReturns struct {
A bool
}
func (g *hooksRPCClient) OnSharedChannelsPing(rc *model.RemoteCluster) bool {
_args := &Z_OnSharedChannelsPingArgs{rc}
_returns := &Z_OnSharedChannelsPingReturns{}
if g.implemented[OnSharedChannelsPingID] {
if err := g.client.Call("Plugin.OnSharedChannelsPing", _args, _returns); err != nil {
g.log.Error("RPC call OnSharedChannelsPing to plugin failed.", mlog.Err(err))
}
}
return _returns.A
}
func (s *hooksRPCServer) OnSharedChannelsPing(args *Z_OnSharedChannelsPingArgs, returns *Z_OnSharedChannelsPingReturns) error {
if hook, ok := s.impl.(interface {
OnSharedChannelsPing(rc *model.RemoteCluster) bool
}); ok {
returns.A = hook.OnSharedChannelsPing(args.A)
} else {
return encodableError(fmt.Errorf("Hook OnSharedChannelsPing called but not implemented."))
}
return nil
}
type Z_RegisterCommandArgs struct {
A *model.Command
}
@@ -6026,3 +6097,273 @@ func (s *apiRPCServer) UpdateUserAuth(args *Z_UpdateUserAuthArgs, returns *Z_Upd
}
return nil
}
type Z_RegisterPluginForSharedChannelsArgs struct {
A model.RegisterPluginOpts
}
type Z_RegisterPluginForSharedChannelsReturns struct {
A string
B error
}
func (g *apiRPCClient) RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error) {
_args := &Z_RegisterPluginForSharedChannelsArgs{opts}
_returns := &Z_RegisterPluginForSharedChannelsReturns{}
if err := g.client.Call("Plugin.RegisterPluginForSharedChannels", _args, _returns); err != nil {
log.Printf("RPC call to RegisterPluginForSharedChannels API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) RegisterPluginForSharedChannels(args *Z_RegisterPluginForSharedChannelsArgs, returns *Z_RegisterPluginForSharedChannelsReturns) error {
if hook, ok := s.impl.(interface {
RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (remoteID string, err error)
}); ok {
returns.A, returns.B = hook.RegisterPluginForSharedChannels(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API RegisterPluginForSharedChannels called but not implemented."))
}
return nil
}
type Z_UnregisterPluginForSharedChannelsArgs struct {
A string
}
type Z_UnregisterPluginForSharedChannelsReturns struct {
A error
}
func (g *apiRPCClient) UnregisterPluginForSharedChannels(pluginID string) error {
_args := &Z_UnregisterPluginForSharedChannelsArgs{pluginID}
_returns := &Z_UnregisterPluginForSharedChannelsReturns{}
if err := g.client.Call("Plugin.UnregisterPluginForSharedChannels", _args, _returns); err != nil {
log.Printf("RPC call to UnregisterPluginForSharedChannels API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) UnregisterPluginForSharedChannels(args *Z_UnregisterPluginForSharedChannelsArgs, returns *Z_UnregisterPluginForSharedChannelsReturns) error {
if hook, ok := s.impl.(interface {
UnregisterPluginForSharedChannels(pluginID string) error
}); ok {
returns.A = hook.UnregisterPluginForSharedChannels(args.A)
returns.A = encodableError(returns.A)
} else {
return encodableError(fmt.Errorf("API UnregisterPluginForSharedChannels called but not implemented."))
}
return nil
}
type Z_ShareChannelArgs struct {
A *model.SharedChannel
}
type Z_ShareChannelReturns struct {
A *model.SharedChannel
B error
}
func (g *apiRPCClient) ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
_args := &Z_ShareChannelArgs{sc}
_returns := &Z_ShareChannelReturns{}
if err := g.client.Call("Plugin.ShareChannel", _args, _returns); err != nil {
log.Printf("RPC call to ShareChannel API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) ShareChannel(args *Z_ShareChannelArgs, returns *Z_ShareChannelReturns) error {
if hook, ok := s.impl.(interface {
ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
}); ok {
returns.A, returns.B = hook.ShareChannel(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API ShareChannel called but not implemented."))
}
return nil
}
type Z_UpdateSharedChannelArgs struct {
A *model.SharedChannel
}
type Z_UpdateSharedChannelReturns struct {
A *model.SharedChannel
B error
}
func (g *apiRPCClient) UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
_args := &Z_UpdateSharedChannelArgs{sc}
_returns := &Z_UpdateSharedChannelReturns{}
if err := g.client.Call("Plugin.UpdateSharedChannel", _args, _returns); err != nil {
log.Printf("RPC call to UpdateSharedChannel API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) UpdateSharedChannel(args *Z_UpdateSharedChannelArgs, returns *Z_UpdateSharedChannelReturns) error {
if hook, ok := s.impl.(interface {
UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error)
}); ok {
returns.A, returns.B = hook.UpdateSharedChannel(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API UpdateSharedChannel called but not implemented."))
}
return nil
}
type Z_UnshareChannelArgs struct {
A string
}
type Z_UnshareChannelReturns struct {
A bool
B error
}
func (g *apiRPCClient) UnshareChannel(channelID string) (unshared bool, err error) {
_args := &Z_UnshareChannelArgs{channelID}
_returns := &Z_UnshareChannelReturns{}
if err := g.client.Call("Plugin.UnshareChannel", _args, _returns); err != nil {
log.Printf("RPC call to UnshareChannel API failed: %s", err.Error())
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) UnshareChannel(args *Z_UnshareChannelArgs, returns *Z_UnshareChannelReturns) error {
if hook, ok := s.impl.(interface {
UnshareChannel(channelID string) (unshared bool, err error)
}); ok {
returns.A, returns.B = hook.UnshareChannel(args.A)
returns.B = encodableError(returns.B)
} else {
return encodableError(fmt.Errorf("API UnshareChannel called but not implemented."))
}
return nil
}
type Z_UpdateSharedChannelCursorArgs struct {
A string
B string
C model.GetPostsSinceForSyncCursor
}
type Z_UpdateSharedChannelCursorReturns struct {
A error
}
func (g *apiRPCClient) UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error {
_args := &Z_UpdateSharedChannelCursorArgs{channelID, remoteID, cusror}
_returns := &Z_UpdateSharedChannelCursorReturns{}
if err := g.client.Call("Plugin.UpdateSharedChannelCursor", _args, _returns); err != nil {
log.Printf("RPC call to UpdateSharedChannelCursor API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) UpdateSharedChannelCursor(args *Z_UpdateSharedChannelCursorArgs, returns *Z_UpdateSharedChannelCursorReturns) error {
if hook, ok := s.impl.(interface {
UpdateSharedChannelCursor(channelID, remoteID string, cusror model.GetPostsSinceForSyncCursor) error
}); ok {
returns.A = hook.UpdateSharedChannelCursor(args.A, args.B, args.C)
returns.A = encodableError(returns.A)
} else {
return encodableError(fmt.Errorf("API UpdateSharedChannelCursor called but not implemented."))
}
return nil
}
type Z_SyncSharedChannelArgs struct {
A string
}
type Z_SyncSharedChannelReturns struct {
A error
}
func (g *apiRPCClient) SyncSharedChannel(channelID string) error {
_args := &Z_SyncSharedChannelArgs{channelID}
_returns := &Z_SyncSharedChannelReturns{}
if err := g.client.Call("Plugin.SyncSharedChannel", _args, _returns); err != nil {
log.Printf("RPC call to SyncSharedChannel API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) SyncSharedChannel(args *Z_SyncSharedChannelArgs, returns *Z_SyncSharedChannelReturns) error {
if hook, ok := s.impl.(interface {
SyncSharedChannel(channelID string) error
}); ok {
returns.A = hook.SyncSharedChannel(args.A)
returns.A = encodableError(returns.A)
} else {
return encodableError(fmt.Errorf("API SyncSharedChannel called but not implemented."))
}
return nil
}
type Z_InviteRemoteToChannelArgs struct {
A string
B string
C string
}
type Z_InviteRemoteToChannelReturns struct {
A error
}
func (g *apiRPCClient) InviteRemoteToChannel(channelID string, remoteID string, userID string) error {
_args := &Z_InviteRemoteToChannelArgs{channelID, remoteID, userID}
_returns := &Z_InviteRemoteToChannelReturns{}
if err := g.client.Call("Plugin.InviteRemoteToChannel", _args, _returns); err != nil {
log.Printf("RPC call to InviteRemoteToChannel API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) InviteRemoteToChannel(args *Z_InviteRemoteToChannelArgs, returns *Z_InviteRemoteToChannelReturns) error {
if hook, ok := s.impl.(interface {
InviteRemoteToChannel(channelID string, remoteID string, userID string) error
}); ok {
returns.A = hook.InviteRemoteToChannel(args.A, args.B, args.C)
returns.A = encodableError(returns.A)
} else {
return encodableError(fmt.Errorf("API InviteRemoteToChannel called but not implemented."))
}
return nil
}
type Z_UninviteRemoteFromChannelArgs struct {
A string
B string
}
type Z_UninviteRemoteFromChannelReturns struct {
A error
}
func (g *apiRPCClient) UninviteRemoteFromChannel(channelID string, remoteID string) error {
_args := &Z_UninviteRemoteFromChannelArgs{channelID, remoteID}
_returns := &Z_UninviteRemoteFromChannelReturns{}
if err := g.client.Call("Plugin.UninviteRemoteFromChannel", _args, _returns); err != nil {
log.Printf("RPC call to UninviteRemoteFromChannel API failed: %s", err.Error())
}
return _returns.A
}
func (s *apiRPCServer) UninviteRemoteFromChannel(args *Z_UninviteRemoteFromChannelArgs, returns *Z_UninviteRemoteFromChannelReturns) error {
if hook, ok := s.impl.(interface {
UninviteRemoteFromChannel(channelID string, remoteID string) error
}); ok {
returns.A = hook.UninviteRemoteFromChannel(args.A, args.B)
returns.A = encodableError(returns.A)
} else {
return encodableError(fmt.Errorf("API UninviteRemoteFromChannel called but not implemented."))
}
return nil
}

Просмотреть файл

@@ -55,6 +55,8 @@ const (
MessageHasBeenDeletedID = 37
MessagesWillBeConsumedID = 38
ServeMetricsID = 39
OnSharedChannelsSyncMsgID = 40
OnSharedChannelsPingID = 41
TotalHooksID = iota
)
@@ -330,4 +332,26 @@ type Hooks interface {
//
// Minimum server version: 9.2
ServeMetrics(c *Context, w http.ResponseWriter, r *http.Request)
// OnSharedChannelsSyncMsg is invoked for plugins that wish to receive synchronization messages from the
// Shared Channels service for which they have been invited via InviteRemote. Each SyncMsg may contain
// multiple updates (posts, reactions, attachments, users) for a single channel.
//
// The cursor will be advanced based on the SyncResponse returned.
//
// Minimum server version: 9.5
OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error)
// OnSharedChannelsPing is invoked for plugins to indicate the health of the plugin and the connection
// to the upstream service (e.g. MS Graph APIs).
//
// Return true to indicate all is well.
//
// Return false to indicate there is a problem with the plugin or connection to upstream service.
// Some number of failed pings will result in the plugin being marked offline and it will stop receiving
// OnSharedChannelsSyncMsg calls until it comes back online. The plugin will also appear offline in the status
// report via the `secure-connection status` slash command.
//
// Minimum server version: 9.5
OnSharedChannelsPing(rc *model.RemoteCluster) bool
}

Просмотреть файл

@@ -250,3 +250,17 @@ func (hooks *hooksTimerLayer) ServeMetrics(c *Context, w http.ResponseWriter, r
hooks.hooksImpl.ServeMetrics(c, w, r)
hooks.recordTime(startTime, "ServeMetrics", true)
}
func (hooks *hooksTimerLayer) OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error) {
startTime := timePkg.Now()
_returnsA, _returnsB := hooks.hooksImpl.OnSharedChannelsSyncMsg(msg, rc)
hooks.recordTime(startTime, "OnSharedChannelsSyncMsg", _returnsB == nil)
return _returnsA, _returnsB
}
func (hooks *hooksTimerLayer) OnSharedChannelsPing(rc *model.RemoteCluster) bool {
startTime := timePkg.Now()
_returnsA := hooks.hooksImpl.OnSharedChannelsPing(rc)
hooks.recordTime(startTime, "OnSharedChannelsPing", true)
return _returnsA
}

Просмотреть файл

@@ -2780,6 +2780,20 @@ func (_m *API) InstallPlugin(file io.Reader, replace bool) (*model.Manifest, *mo
return r0, r1
}
// InviteRemoteToChannel provides a mock function with given fields: channelID, remoteID, userID
func (_m *API) InviteRemoteToChannel(channelID string, remoteID string, userID string) error {
ret := _m.Called(channelID, remoteID, userID)
var r0 error
if rf, ok := ret.Get(0).(func(string, string, string) error); ok {
r0 = rf(channelID, remoteID, userID)
} else {
r0 = ret.Error(0)
}
return r0
}
// IsEnterpriseReady provides a mock function with given fields:
func (_m *API) IsEnterpriseReady() bool {
ret := _m.Called()
@@ -3309,6 +3323,30 @@ func (_m *API) RegisterCommand(command *model.Command) error {
return r0
}
// RegisterPluginForSharedChannels provides a mock function with given fields: opts
func (_m *API) RegisterPluginForSharedChannels(opts model.RegisterPluginOpts) (string, error) {
ret := _m.Called(opts)
var r0 string
var r1 error
if rf, ok := ret.Get(0).(func(model.RegisterPluginOpts) (string, error)); ok {
return rf(opts)
}
if rf, ok := ret.Get(0).(func(model.RegisterPluginOpts) string); ok {
r0 = rf(opts)
} else {
r0 = ret.Get(0).(string)
}
if rf, ok := ret.Get(1).(func(model.RegisterPluginOpts) error); ok {
r1 = rf(opts)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// RemovePlugin provides a mock function with given fields: id
func (_m *API) RemovePlugin(id string) *model.AppError {
ret := _m.Called(id)
@@ -3731,6 +3769,60 @@ func (_m *API) SetUserStatusTimedDND(userId string, endtime int64) (*model.Statu
return r0, r1
}
// ShareChannel provides a mock function with given fields: sc
func (_m *API) ShareChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
ret := _m.Called(sc)
var r0 *model.SharedChannel
var r1 error
if rf, ok := ret.Get(0).(func(*model.SharedChannel) (*model.SharedChannel, error)); ok {
return rf(sc)
}
if rf, ok := ret.Get(0).(func(*model.SharedChannel) *model.SharedChannel); ok {
r0 = rf(sc)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.SharedChannel)
}
}
if rf, ok := ret.Get(1).(func(*model.SharedChannel) error); ok {
r1 = rf(sc)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// SyncSharedChannel provides a mock function with given fields: channelID
func (_m *API) SyncSharedChannel(channelID string) error {
ret := _m.Called(channelID)
var r0 error
if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(channelID)
} else {
r0 = ret.Error(0)
}
return r0
}
// UninviteRemoteFromChannel provides a mock function with given fields: channelID, remoteID
func (_m *API) UninviteRemoteFromChannel(channelID string, remoteID string) error {
ret := _m.Called(channelID, remoteID)
var r0 error
if rf, ok := ret.Get(0).(func(string, string) error); ok {
r0 = rf(channelID, remoteID)
} else {
r0 = ret.Error(0)
}
return r0
}
// UnregisterCommand provides a mock function with given fields: teamID, trigger
func (_m *API) UnregisterCommand(teamID string, trigger string) error {
ret := _m.Called(teamID, trigger)
@@ -3745,6 +3837,44 @@ func (_m *API) UnregisterCommand(teamID string, trigger string) error {
return r0
}
// UnregisterPluginForSharedChannels provides a mock function with given fields: pluginID
func (_m *API) UnregisterPluginForSharedChannels(pluginID string) error {
ret := _m.Called(pluginID)
var r0 error
if rf, ok := ret.Get(0).(func(string) error); ok {
r0 = rf(pluginID)
} else {
r0 = ret.Error(0)
}
return r0
}
// UnshareChannel provides a mock function with given fields: channelID
func (_m *API) UnshareChannel(channelID string) (bool, error) {
ret := _m.Called(channelID)
var r0 bool
var r1 error
if rf, ok := ret.Get(0).(func(string) (bool, error)); ok {
return rf(channelID)
}
if rf, ok := ret.Get(0).(func(string) bool); ok {
r0 = rf(channelID)
} else {
r0 = ret.Get(0).(bool)
}
if rf, ok := ret.Get(1).(func(string) error); ok {
r1 = rf(channelID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateBotActive provides a mock function with given fields: botUserId, active
func (_m *API) UpdateBotActive(botUserId string, active bool) (*model.Bot, *model.AppError) {
ret := _m.Called(botUserId, active)
@@ -3999,6 +4129,46 @@ func (_m *API) UpdatePreferencesForUser(userID string, preferences []model.Prefe
return r0
}
// UpdateSharedChannel provides a mock function with given fields: sc
func (_m *API) UpdateSharedChannel(sc *model.SharedChannel) (*model.SharedChannel, error) {
ret := _m.Called(sc)
var r0 *model.SharedChannel
var r1 error
if rf, ok := ret.Get(0).(func(*model.SharedChannel) (*model.SharedChannel, error)); ok {
return rf(sc)
}
if rf, ok := ret.Get(0).(func(*model.SharedChannel) *model.SharedChannel); ok {
r0 = rf(sc)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.SharedChannel)
}
}
if rf, ok := ret.Get(1).(func(*model.SharedChannel) error); ok {
r1 = rf(sc)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateSharedChannelCursor provides a mock function with given fields: channelID, remoteID, cusror
func (_m *API) UpdateSharedChannelCursor(channelID string, remoteID string, cusror model.GetPostsSinceForSyncCursor) error {
ret := _m.Called(channelID, remoteID, cusror)
var r0 error
if rf, ok := ret.Get(0).(func(string, string, model.GetPostsSinceForSyncCursor) error); ok {
r0 = rf(channelID, remoteID, cusror)
} else {
r0 = ret.Error(0)
}
return r0
}
// UpdateTeam provides a mock function with given fields: team
func (_m *API) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
ret := _m.Called(team)

Просмотреть файл

@@ -311,6 +311,44 @@ func (_m *Hooks) OnSendDailyTelemetry() {
_m.Called()
}
// OnSharedChannelsPing provides a mock function with given fields: rc
func (_m *Hooks) OnSharedChannelsPing(rc *model.RemoteCluster) bool {
ret := _m.Called(rc)
var r0 bool
if rf, ok := ret.Get(0).(func(*model.RemoteCluster) bool); ok {
r0 = rf(rc)
} else {
r0 = ret.Get(0).(bool)
}
return r0
}
// OnSharedChannelsSyncMsg provides a mock function with given fields: msg, rc
func (_m *Hooks) OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error) {
ret := _m.Called(msg, rc)
var r0 model.SyncResponse
var r1 error
if rf, ok := ret.Get(0).(func(*model.SyncMsg, *model.RemoteCluster) (model.SyncResponse, error)); ok {
return rf(msg, rc)
}
if rf, ok := ret.Get(0).(func(*model.SyncMsg, *model.RemoteCluster) model.SyncResponse); ok {
r0 = rf(msg, rc)
} else {
r0 = ret.Get(0).(model.SyncResponse)
}
if rf, ok := ret.Get(1).(func(*model.SyncMsg, *model.RemoteCluster) error); ok {
r1 = rf(msg, rc)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// OnWebSocketConnect provides a mock function with given fields: webConnID, userID
func (_m *Hooks) OnWebSocketConnect(webConnID string, userID string) {
_m.Called(webConnID, userID)

Просмотреть файл

@@ -139,6 +139,14 @@ type ServeMetricsIFace interface {
ServeMetrics(c *Context, w http.ResponseWriter, r *http.Request)
}
type OnSharedChannelsSyncMsgIFace interface {
OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error)
}
type OnSharedChannelsPingIFace interface {
OnSharedChannelsPing(rc *model.RemoteCluster) bool
}
type HooksAdapter struct {
implemented map[int]struct{}
productHooks any
@@ -431,6 +439,24 @@ func NewAdapter(productHooks any) (*HooksAdapter, error) {
return nil, errors.New("hook has ServeMetrics method but does not implement plugin.ServeMetrics interface")
}
// Assessing the type of the productHooks if it individually implements OnSharedChannelsSyncMsg interface.
tt = reflect.TypeOf((*OnSharedChannelsSyncMsgIFace)(nil)).Elem()
if ft.Implements(tt) {
a.implemented[OnSharedChannelsSyncMsgID] = struct{}{}
} else if _, ok := ft.MethodByName("OnSharedChannelsSyncMsg"); ok {
return nil, errors.New("hook has OnSharedChannelsSyncMsg method but does not implement plugin.OnSharedChannelsSyncMsg interface")
}
// Assessing the type of the productHooks if it individually implements OnSharedChannelsPing interface.
tt = reflect.TypeOf((*OnSharedChannelsPingIFace)(nil)).Elem()
if ft.Implements(tt) {
a.implemented[OnSharedChannelsPingID] = struct{}{}
} else if _, ok := ft.MethodByName("OnSharedChannelsPing"); ok {
return nil, errors.New("hook has OnSharedChannelsPing method but does not implement plugin.OnSharedChannelsPing interface")
}
return a, nil
}
@@ -712,3 +738,21 @@ func (a *HooksAdapter) ServeMetrics(c *Context, w http.ResponseWriter, r *http.R
a.productHooks.(ServeMetricsIFace).ServeMetrics(c, w, r)
}
func (a *HooksAdapter) OnSharedChannelsSyncMsg(msg *model.SyncMsg, rc *model.RemoteCluster) (model.SyncResponse, error) {
if _, ok := a.implemented[OnSharedChannelsSyncMsgID]; !ok {
panic("product hooks must implement OnSharedChannelsSyncMsg")
}
return a.productHooks.(OnSharedChannelsSyncMsgIFace).OnSharedChannelsSyncMsg(msg, rc)
}
func (a *HooksAdapter) OnSharedChannelsPing(rc *model.RemoteCluster) bool {
if _, ok := a.implemented[OnSharedChannelsPingID]; !ok {
panic("product hooks must implement OnSharedChannelsPing")
}
return a.productHooks.(OnSharedChannelsPingIFace).OnSharedChannelsPing(rc)
}