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
Этот коммит содержится в:
@@ -50,6 +50,10 @@ type ServerIface interface {
|
||||
GetMetrics() einterfaces.MetricsInterface
|
||||
}
|
||||
|
||||
type AppIface interface {
|
||||
OnSharedChannelsPing(rc *model.RemoteCluster) bool
|
||||
}
|
||||
|
||||
// RemoteClusterServiceIFace is used to allow mocking where a remote cluster service is used (for testing).
|
||||
// Unfortunately it lives here because the shared channel service, app layer, and server interface all need it.
|
||||
// Putting it in app layer means shared channel service must import app package.
|
||||
@@ -78,6 +82,7 @@ type ConnectionStateListener func(rc *model.RemoteCluster, online bool)
|
||||
// Service provides inter-cluster communication via topic based messages. In product these are called "Secured Connections".
|
||||
type Service struct {
|
||||
server ServerIface
|
||||
app AppIface
|
||||
httpClient *http.Client
|
||||
send []chan any
|
||||
|
||||
@@ -88,10 +93,11 @@ type Service struct {
|
||||
topicListeners map[string]map[string]TopicListener // maps topic id to a map of listenerid->listener
|
||||
connectionStateListeners map[string]ConnectionStateListener // maps listener id to listener
|
||||
done chan struct{}
|
||||
pingFreq time.Duration
|
||||
}
|
||||
|
||||
// NewRemoteClusterService creates a RemoteClusterService instance. In product this is called a "Secured Connection".
|
||||
func NewRemoteClusterService(server ServerIface) (*Service, error) {
|
||||
func NewRemoteClusterService(server ServerIface, app AppIface) (*Service, error) {
|
||||
transport := &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
DialContext: (&net.Dialer{
|
||||
@@ -115,6 +121,7 @@ func NewRemoteClusterService(server ServerIface) (*Service, error) {
|
||||
|
||||
service := &Service{
|
||||
server: server,
|
||||
app: app,
|
||||
httpClient: client,
|
||||
topicListeners: make(map[string]map[string]TopicListener),
|
||||
connectionStateListeners: make(map[string]ConnectionStateListener),
|
||||
@@ -124,6 +131,7 @@ func NewRemoteClusterService(server ServerIface) (*Service, error) {
|
||||
for i := range service.send {
|
||||
service.send[i] = make(chan any, SendChanBuffer)
|
||||
}
|
||||
service.pingFreq = PingFreq
|
||||
|
||||
return service, nil
|
||||
}
|
||||
@@ -154,6 +162,21 @@ func (rcs *Service) Active() bool {
|
||||
return rcs.active
|
||||
}
|
||||
|
||||
// GetPingFreq gets the frequency of pings to each remote.
|
||||
func (rcs *Service) GetPingFreq() time.Duration {
|
||||
rcs.mux.Lock()
|
||||
defer rcs.mux.Unlock()
|
||||
return rcs.pingFreq
|
||||
}
|
||||
|
||||
// SetPingFreq sets the frequency of pings to each remote. Defaults to `PingFreq`.
|
||||
// This is typically used to set a higher frequency for testing.
|
||||
func (rcs *Service) SetPingFreq(freq time.Duration) {
|
||||
rcs.mux.Lock()
|
||||
defer rcs.mux.Unlock()
|
||||
rcs.pingFreq = freq
|
||||
}
|
||||
|
||||
// AddTopicListener registers a callback
|
||||
func (rcs *Service) AddTopicListener(topic string, listener TopicListener) string {
|
||||
rcs.mux.Lock()
|
||||
|
||||
Ссылка в новой задаче
Block a user