Plugin API hook for Shared Channel file attachment sync (#25874)
* option for auto inviting plugin to all shared channels. * auto-invite remotes to shared channels when flag set * fix unit test * immediately ping new remotes; fix unique siteurl bug * make i18n-extract * fix translations * plugin hooks for file attachments * hook for profile image sync * fix profile image sync * fix unit test --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -41,6 +41,10 @@ func (scs *Service) sendAttachmentForRemote(fi *model.FileInfo, post *model.Post
|
||||
return fmt.Errorf("cannot update remote cluster for remote id %s; Remote Cluster Service not enabled", rc.RemoteId)
|
||||
}
|
||||
|
||||
if rc.IsPlugin() {
|
||||
return scs.sendAttachmentToPlugin(fi, post, rc)
|
||||
}
|
||||
|
||||
us := &model.UploadSession{
|
||||
Id: model.NewId(),
|
||||
Type: model.UploadTypeAttachment,
|
||||
@@ -120,11 +124,7 @@ func (scs *Service) sendAttachmentForRemote(fi *model.FileInfo, post *model.Post
|
||||
}
|
||||
|
||||
// save file attachment record in SharedChannelAttachments table
|
||||
sca := &model.SharedChannelAttachment{
|
||||
FileId: fi.Id,
|
||||
RemoteId: rc.RemoteId,
|
||||
}
|
||||
if _, err2 := scs.server.GetStore().SharedChannel().UpsertAttachment(sca); err2 != nil {
|
||||
if err2 := scs.saveSharedAttachment(&fi, rc); err2 != nil {
|
||||
scs.server.Log().Log(mlog.LvlSharedChannelServiceError, "error saving SharedChannelAttachment",
|
||||
mlog.String("remote", rc.DisplayName),
|
||||
mlog.String("uploadId", usResp.Id),
|
||||
@@ -140,6 +140,24 @@ func (scs *Service) sendAttachmentForRemote(fi *model.FileInfo, post *model.Post
|
||||
})
|
||||
}
|
||||
|
||||
// sendAttachmentToPlugin asynchronously sends a file attachment to a remote cluster.
|
||||
func (scs *Service) sendAttachmentToPlugin(fi *model.FileInfo, post *model.Post, rc *model.RemoteCluster) error {
|
||||
if err := scs.app.OnSharedChannelsAttachmentSyncMsg(fi, post, rc); err != nil {
|
||||
return fmt.Errorf("cannot send attachment to plugin %s: %w", rc.PluginID, err)
|
||||
}
|
||||
return scs.saveSharedAttachment(fi, rc)
|
||||
}
|
||||
|
||||
// saveSharedAttachment saves the attachment in SharedChannelAttachments table.
|
||||
func (scs *Service) saveSharedAttachment(fi *model.FileInfo, rc *model.RemoteCluster) error {
|
||||
sca := &model.SharedChannelAttachment{
|
||||
FileId: fi.Id,
|
||||
RemoteId: rc.RemoteId,
|
||||
}
|
||||
_, err := scs.server.GetStore().SharedChannel().UpsertAttachment(sca)
|
||||
return err
|
||||
}
|
||||
|
||||
// onReceiveUploadCreate is called when a message requesting to create an upload session is received. An upload session is
|
||||
// created and the id returned in the response.
|
||||
func (scs *Service) onReceiveUploadCreate(msg model.RemoteClusterMsg, rc *model.RemoteCluster, response *remotecluster.Response) error {
|
||||
|
||||
Ссылка в новой задаче
Block a user