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 sqlstore
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -50,6 +51,19 @@ func (s sqlRemoteClusterStore) Save(remoteCluster *model.RemoteCluster) (*model.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// check for pluginID collisions - on collision treat as idempotent
|
||||
if remoteCluster.PluginID != "" {
|
||||
rc, err := s.GetByPluginID(remoteCluster.PluginID)
|
||||
if err == nil {
|
||||
// if this plugin id already exists, just return it
|
||||
return rc, nil
|
||||
}
|
||||
if !errors.Is(err, sql.ErrNoRows) {
|
||||
// anything other than NotFound is unexpected
|
||||
return nil, errors.Wrapf(err, "failed to lookup RemoteCluster by pluginID %s", remoteCluster.PluginID)
|
||||
}
|
||||
}
|
||||
|
||||
query := `INSERT INTO RemoteClusters
|
||||
(RemoteId, RemoteTeamId, Name, DisplayName, SiteURL, CreateAt,
|
||||
LastPingAt, Token, RemoteToken, Topics, CreatorId, PluginID, Options)
|
||||
@@ -69,6 +83,7 @@ func (s sqlRemoteClusterStore) Update(remoteCluster *model.RemoteCluster) (*mode
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// not all fields can be updated.
|
||||
query := `UPDATE RemoteClusters
|
||||
SET Token = :Token,
|
||||
RemoteTeamId = :RemoteTeamId,
|
||||
@@ -129,6 +144,24 @@ func (s sqlRemoteClusterStore) Get(remoteId string) (*model.RemoteCluster, error
|
||||
return &rc, nil
|
||||
}
|
||||
|
||||
func (s sqlRemoteClusterStore) GetByPluginID(pluginID string) (*model.RemoteCluster, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select(remoteClusterFields("")...).
|
||||
From("RemoteClusters").
|
||||
Where(sq.Eq{"PluginID": pluginID})
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "remote_cluster_get_by_pluginid_tosql")
|
||||
}
|
||||
|
||||
var rc model.RemoteCluster
|
||||
if err := s.GetReplicaX().Get(&rc, queryString, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to find RemoteCluster by plugin_id")
|
||||
}
|
||||
return &rc, nil
|
||||
}
|
||||
|
||||
func (s sqlRemoteClusterStore) GetAll(filter model.RemoteClusterQueryFilter) ([]*model.RemoteCluster, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select(remoteClusterFields("rc")...).
|
||||
|
||||
Ссылка в новой задаче
Block a user