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 удалений

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

@@ -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)
}