merge trails function added (#627)
* 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>
This commit is contained in:
44
db/trailmerge/integration_merge.go
Normal file
44
db/trailmerge/integration_merge.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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())
|
||||
}
|
||||
Reference in New Issue
Block a user