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
Этот коммит содержится в:
@@ -5,6 +5,7 @@ package remotecluster
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -28,6 +29,7 @@ func (rcs *Service) pingGenerator(pingChan chan *model.RemoteCluster, done <-cha
|
||||
defer close(pingChan)
|
||||
|
||||
for {
|
||||
pingFreq := rcs.GetPingFreq()
|
||||
start := time.Now()
|
||||
|
||||
// get all remotes, including any previously offline.
|
||||
@@ -35,7 +37,7 @@ func (rcs *Service) pingGenerator(pingChan chan *model.RemoteCluster, done <-cha
|
||||
if err != nil {
|
||||
rcs.server.Log().Log(mlog.LvlRemoteClusterServiceError, "Ping remote cluster failed (could not get list of remotes)", mlog.Err(err))
|
||||
select {
|
||||
case <-time.After(PingFreq):
|
||||
case <-time.After(pingFreq):
|
||||
continue
|
||||
case <-done:
|
||||
return
|
||||
@@ -50,8 +52,8 @@ func (rcs *Service) pingGenerator(pingChan chan *model.RemoteCluster, done <-cha
|
||||
|
||||
// try to maintain frequency
|
||||
elapsed := time.Since(start)
|
||||
if elapsed < PingFreq {
|
||||
sleep := time.Until(start.Add(PingFreq))
|
||||
if elapsed < pingFreq {
|
||||
sleep := time.Until(start.Add(pingFreq))
|
||||
select {
|
||||
case <-time.After(sleep):
|
||||
case <-done:
|
||||
@@ -77,6 +79,7 @@ func (rcs *Service) pingEmitter(pingChan <-chan *model.RemoteCluster, done <-cha
|
||||
rcs.server.Log().Log(mlog.LvlRemoteClusterServiceWarn, "Remote cluster ping failed",
|
||||
mlog.String("remote", rc.DisplayName),
|
||||
mlog.String("remoteId", rc.RemoteId),
|
||||
mlog.String("pluginId", rc.PluginID),
|
||||
mlog.Err(err),
|
||||
)
|
||||
}
|
||||
@@ -93,25 +96,36 @@ func (rcs *Service) pingEmitter(pingChan <-chan *model.RemoteCluster, done <-cha
|
||||
}
|
||||
}
|
||||
|
||||
var ErrPluginPingFail = errors.New("plugin ping failed")
|
||||
|
||||
// pingRemote make a synchronous ping to a remote cluster. Return is error if ping is
|
||||
// unsuccessful and nil on success.
|
||||
func (rcs *Service) pingRemote(rc *model.RemoteCluster) error {
|
||||
frame, err := makePingFrame(rc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s", rc.SiteURL, PingURL)
|
||||
|
||||
resp, err := rcs.sendFrameToRemote(PingTimeout, rc, frame, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rc.LastPingAt = model.GetMillis()
|
||||
|
||||
ping := model.RemoteClusterPing{}
|
||||
err = json.Unmarshal(resp, &ping)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
if rc.PluginID != "" {
|
||||
ping.SentAt = model.GetMillis()
|
||||
if ok := rcs.app.OnSharedChannelsPing(rc); !ok {
|
||||
return ErrPluginPingFail
|
||||
}
|
||||
ping.RecvAt = model.GetMillis()
|
||||
} else {
|
||||
frame, err := makePingFrame(rc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s", rc.SiteURL, PingURL)
|
||||
|
||||
resp, err := rcs.sendFrameToRemote(PingTimeout, rc, frame, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rc.LastPingAt = model.GetMillis()
|
||||
|
||||
err = json.Unmarshal(resp, &ping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := rcs.server.GetStore().RemoteCluster().SetLastPingAt(rc.RemoteId); err != nil {
|
||||
@@ -135,6 +149,7 @@ func (rcs *Service) pingRemote(rc *model.RemoteCluster) error {
|
||||
rcs.server.Log().Log(mlog.LvlRemoteClusterServiceDebug, "Remote cluster ping",
|
||||
mlog.String("remote", rc.DisplayName),
|
||||
mlog.String("remoteId", rc.RemoteId),
|
||||
mlog.String("pluginId", rc.PluginID),
|
||||
mlog.Int("SentAt", ping.SentAt),
|
||||
mlog.Int("RecvAt", ping.RecvAt),
|
||||
mlog.Int("Diff", ping.RecvAt-ping.SentAt),
|
||||
|
||||
Ссылка в новой задаче
Block a user