Prep for MS Teams plugin API (#25565)
* - columns added to ShareChannelRemotes: lastpostcreateat, lastpostupdateat - SyncMsg and SyncResponse moved to `model` package - field added to RemoteCluster struct: PluginID * sync new posts before updated posts to ensure post order in MS Teams * add plugid to remoteclusters table and store * don't sync history by default
Этот коммит содержится в:
@@ -13,9 +13,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
@@ -1396,10 +1397,22 @@ func (s *SqlPostStore) GetPostsSinceForSync(options model.GetPostsSinceForSyncOp
|
||||
query := s.getQueryBuilder().
|
||||
Select("*").
|
||||
From("Posts").
|
||||
Where(sq.Or{sq.Gt{"Posts.UpdateAt": cursor.LastPostUpdateAt}, sq.And{sq.Eq{"Posts.UpdateAt": cursor.LastPostUpdateAt}, sq.Gt{"Posts.Id": cursor.LastPostId}}}).
|
||||
OrderBy("Posts.UpdateAt", "Id").
|
||||
Limit(uint64(limit))
|
||||
|
||||
if options.SinceCreateAt {
|
||||
query = query.Where(sq.Or{
|
||||
sq.Gt{"Posts.CreateAt": cursor.LastPostCreateAt},
|
||||
sq.And{
|
||||
sq.Eq{"Posts.CreateAt": cursor.LastPostCreateAt},
|
||||
sq.Gt{"Posts.Id": cursor.LastPostCreateID},
|
||||
},
|
||||
})
|
||||
} else {
|
||||
query = query.Where(sq.Or{sq.Gt{"Posts.UpdateAt": cursor.LastPostUpdateAt},
|
||||
sq.And{sq.Eq{"Posts.UpdateAt": cursor.LastPostUpdateAt}, sq.Gt{"Posts.Id": cursor.LastPostUpdateID}}})
|
||||
}
|
||||
|
||||
if options.ChannelId != "" {
|
||||
query = query.Where(sq.Eq{"Posts.ChannelId": options.ChannelId})
|
||||
}
|
||||
@@ -1424,8 +1437,13 @@ func (s *SqlPostStore) GetPostsSinceForSync(options model.GetPostsSinceForSyncOp
|
||||
}
|
||||
|
||||
if len(posts) != 0 {
|
||||
cursor.LastPostUpdateAt = posts[len(posts)-1].UpdateAt
|
||||
cursor.LastPostId = posts[len(posts)-1].Id
|
||||
if options.SinceCreateAt {
|
||||
cursor.LastPostCreateAt = posts[len(posts)-1].CreateAt
|
||||
cursor.LastPostCreateID = posts[len(posts)-1].Id
|
||||
} else {
|
||||
cursor.LastPostUpdateAt = posts[len(posts)-1].UpdateAt
|
||||
cursor.LastPostUpdateID = posts[len(posts)-1].Id
|
||||
}
|
||||
}
|
||||
return posts, cursor, nil
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
@@ -38,6 +39,7 @@ func remoteClusterFields(prefix string) []string {
|
||||
prefix + "RemoteToken",
|
||||
prefix + "Topics",
|
||||
prefix + "CreatorId",
|
||||
prefix + "PluginID",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,10 +51,10 @@ func (s sqlRemoteClusterStore) Save(remoteCluster *model.RemoteCluster) (*model.
|
||||
|
||||
query := `INSERT INTO RemoteClusters
|
||||
(RemoteId, RemoteTeamId, Name, DisplayName, SiteURL, CreateAt,
|
||||
LastPingAt, Token, RemoteToken, Topics, CreatorId)
|
||||
LastPingAt, Token, RemoteToken, Topics, CreatorId, PluginID)
|
||||
VALUES
|
||||
(:RemoteId, :RemoteTeamId, :Name, :DisplayName, :SiteURL, :CreateAt,
|
||||
:LastPingAt, :Token, :RemoteToken, :Topics, :CreatorId)`
|
||||
:LastPingAt, :Token, :RemoteToken, :Topics, :CreatorId, :PluginID)`
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(query, remoteCluster); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to save RemoteCluster")
|
||||
@@ -75,7 +77,8 @@ func (s sqlRemoteClusterStore) Update(remoteCluster *model.RemoteCluster) (*mode
|
||||
CreatorId = :CreatorId,
|
||||
DisplayName = :DisplayName,
|
||||
SiteURL = :SiteURL,
|
||||
Topics = :Topics
|
||||
Topics = :Topics,
|
||||
PluginID = :PluginID
|
||||
WHERE RemoteId = :RemoteId AND Name = :Name`
|
||||
|
||||
if _, err := s.GetMasterX().NamedExec(query, remoteCluster); err != nil {
|
||||
@@ -149,6 +152,10 @@ func (s sqlRemoteClusterStore) GetAll(filter model.RemoteClusterQueryFilter) ([]
|
||||
query = query.Where(sq.NotEq{"rc.SiteURL": ""})
|
||||
}
|
||||
|
||||
if filter.PluginID != "" {
|
||||
query = query.Where(sq.Eq{"rc.PluginID": filter.PluginID})
|
||||
}
|
||||
|
||||
if filter.Topic != "" {
|
||||
trimmed := strings.TrimSpace(filter.Topic)
|
||||
if trimmed == "" || trimmed == "*" {
|
||||
|
||||
@@ -11,8 +11,9 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -333,8 +334,10 @@ func (s SqlSharedChannelStore) SaveRemote(remote *model.SharedChannelRemote) (*m
|
||||
}
|
||||
|
||||
query, args, err := s.getQueryBuilder().Insert("SharedChannelRemotes").
|
||||
Columns("Id", "ChannelId", "CreatorId", "CreateAt", "UpdateAt", "IsInviteAccepted", "IsInviteConfirmed", "RemoteId", "LastPostUpdateAt", "LastPostId").
|
||||
Values(remote.Id, remote.ChannelId, remote.CreatorId, remote.CreateAt, remote.UpdateAt, remote.IsInviteAccepted, remote.IsInviteConfirmed, remote.RemoteId, remote.LastPostUpdateAt, remote.LastPostId).
|
||||
Columns("Id", "ChannelId", "CreatorId", "CreateAt", "UpdateAt", "IsInviteAccepted", "IsInviteConfirmed", "RemoteId",
|
||||
"LastPostCreateAt", "LastPostCreateId", "LastPostUpdateAt", "LastPostId").
|
||||
Values(remote.Id, remote.ChannelId, remote.CreatorId, remote.CreateAt, remote.UpdateAt, remote.IsInviteAccepted, remote.IsInviteConfirmed, remote.RemoteId,
|
||||
remote.LastPostCreateAt, remote.LastPostCreateID, remote.LastPostUpdateAt, remote.LastPostUpdateID).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "savesharedchannelremote_tosql")
|
||||
@@ -359,8 +362,10 @@ func (s SqlSharedChannelStore) UpdateRemote(remote *model.SharedChannelRemote) (
|
||||
Set("IsInviteAccepted", remote.IsInviteAccepted).
|
||||
Set("IsInviteConfirmed", remote.IsInviteConfirmed).
|
||||
Set("RemoteId", remote.RemoteId).
|
||||
Set("LastPostCreateAt", remote.LastPostUpdateAt).
|
||||
Set("LastPostCreateId", remote.LastPostCreateID).
|
||||
Set("LastPostUpdateAt", remote.LastPostUpdateAt).
|
||||
Set("LastPostId", remote.LastPostId).
|
||||
Set("LastPostId", remote.LastPostUpdateID).
|
||||
Where(sq.And{
|
||||
sq.Eq{"Id": remote.Id},
|
||||
sq.Eq{"ChannelId": remote.ChannelId},
|
||||
@@ -398,8 +403,10 @@ func sharedChannelRemoteFields(prefix string) []string {
|
||||
prefix + "IsInviteAccepted",
|
||||
prefix + "IsInviteConfirmed",
|
||||
prefix + "RemoteId",
|
||||
prefix + "LastPostCreateAt",
|
||||
"COALESCE(" + prefix + "LastPostCreateID,'') AS LastPostCreateID",
|
||||
prefix + "LastPostUpdateAt",
|
||||
prefix + "LastPostId",
|
||||
"COALESCE(" + prefix + "LastPostId,'') AS LastPostUpdateID",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,14 +539,32 @@ func (s SqlSharedChannelStore) GetRemoteForUser(remoteId string, userId string)
|
||||
return &rc, nil
|
||||
}
|
||||
|
||||
// UpdateRemoteCursor updates the LastPostUpdateAt timestamp and LastPostId for the specified SharedChannelRemote.
|
||||
// UpdateRemoteCursor updates the cursor for the specified SharedChannelRemote.
|
||||
func (s SqlSharedChannelStore) UpdateRemoteCursor(id string, cursor model.GetPostsSinceForSyncCursor) error {
|
||||
squery, args, err := s.getQueryBuilder().
|
||||
var updateNeeded bool
|
||||
|
||||
builder := s.getQueryBuilder().
|
||||
Update("SharedChannelRemotes").
|
||||
Set("LastPostUpdateAt", cursor.LastPostUpdateAt).
|
||||
Set("LastPostId", cursor.LastPostId).
|
||||
Where(sq.Eq{"Id": id}).
|
||||
ToSql()
|
||||
Where(sq.Eq{"Id": id})
|
||||
|
||||
if cursor.LastPostCreateAt > 0 || cursor.LastPostCreateID != "" {
|
||||
builder = builder.Set("LastPostCreateAt", cursor.LastPostCreateAt)
|
||||
builder = builder.Set("LastPostCreateId", cursor.LastPostCreateID)
|
||||
updateNeeded = true
|
||||
}
|
||||
|
||||
if cursor.LastPostUpdateAt > 0 || cursor.LastPostUpdateID != "" {
|
||||
builder = builder.Set("LastPostUpdateAt", cursor.LastPostUpdateAt)
|
||||
builder = builder.Set("LastPostId", cursor.LastPostUpdateID)
|
||||
updateNeeded = true
|
||||
}
|
||||
|
||||
if !updateNeeded {
|
||||
// no new cursor provided.
|
||||
return fmt.Errorf("cursor empty")
|
||||
}
|
||||
|
||||
squery, args, err := builder.ToSql()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "update_shared_channel_remote_cursor_tosql")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user