* merge trails function added * fix conflict resolve issues * avoid incorrect authorship when merging trail comments * require edit access for all selected trails before merge * fix likes checkbox binding in trail merge modal * improve error handling * require editable target and deletable sources for merge * avoid duplicate trail fetch during merge * prevent duplicate likes when merging trails * check photo download responses during trail merge * add merge completion toast notifications * cleanup * small fixes * move merge code to backend, option to merge single trail selection with similar one, automatic merge for integrations add as option, maintenance page to find and merge similar trails added * fix build error * fix * docu, beautifying, refactoring --------- Co-authored-by: Flomp <Flomp@users.noreply.github.com>
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package trailmerge
|
|
|
|
import (
|
|
"github.com/meilisearch/meilisearch-go"
|
|
"github.com/pocketbase/pocketbase/core"
|
|
)
|
|
|
|
func TryAutoMergeImportedTrail(
|
|
app core.App,
|
|
client meilisearch.ServiceManager,
|
|
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, actor, sourceTrailID, targetTrailID, DefaultIntegrationAutoMergeMergeSettings())
|
|
}
|