* initial commit * add lists * update permissions * fix waypoint create * needs_full_sync for activitypub trails * fixes build issues * fix list get * further CSRF protection * update API docs * adds rate limiter * fix tiptap mentions * a bit more cleanup of main.go * Fix migration order * fixes reviewed notes * require context for activitpub server calls * improve hashing for identifier * fix copy paste error * fix sync trail/list issues * fix summit log/comment duplicates * adaptions after trail merge * fix dockerignore --------- Co-authored-by: Christian Beutel <> Co-authored-by: slothful-vassal <89943360+slothful-vassal@users.noreply.github.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package trailmerge
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/meilisearch/meilisearch-go"
|
|
"github.com/pocketbase/pocketbase/core"
|
|
)
|
|
|
|
func TryAutoMergeImportedTrail(
|
|
app core.App,
|
|
client meilisearch.ServiceManager,
|
|
ctx context.Context,
|
|
actor *core.Record,
|
|
sourceTrailID string,
|
|
settings IntegrationAutoMergeSettings,
|
|
) error {
|
|
if actor == nil || sourceTrailID == "" || !settings.Enabled {
|
|
return nil
|
|
}
|
|
|
|
response, err := Suggest(app, actor.Id, SuggestRequest{
|
|
Mode: SuggestModeAutoDiscovery,
|
|
SourceTrailID: sourceTrailID,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
selectableCandidates := make([]SuggestCandidate, 0, len(response.Candidates))
|
|
for _, candidate := range response.Candidates {
|
|
if candidate.Selectable {
|
|
selectableCandidates = append(selectableCandidates, candidate)
|
|
}
|
|
}
|
|
|
|
if len(selectableCandidates) != 1 {
|
|
return nil
|
|
}
|
|
|
|
targetTrailID := selectableCandidates[0].TrailID
|
|
if targetTrailID == "" || targetTrailID == sourceTrailID {
|
|
return nil
|
|
}
|
|
|
|
return Merge(app, client, ctx, actor, sourceTrailID, targetTrailID, DefaultIntegrationAutoMergeMergeSettings())
|
|
}
|