Feat add actors to meilisearch (#1048)
* initial commit * update api docs * adds search token versioning * make id filterable * isLocal -> is_local * add iri to actor index * update gitignore * Merge remote-tracking branch 'origin/main' into feat-add-actors-to-meilisearch * fix sharing for newly discovered actors * fix ActorSearchResult type --------- Co-authored-by: Christian Beutel <>
This commit is contained in:
@@ -86,7 +86,7 @@ func ActorFromUser(app core.App, u *core.Record) (*core.Record, error) {
|
||||
record.Set("outbox", id+"/outbox")
|
||||
record.Set("followers", id+"/followers")
|
||||
record.Set("following", id+"/following")
|
||||
record.Set("isLocal", true)
|
||||
record.Set("is_local", true)
|
||||
record.Set("public_key", string(pubPem))
|
||||
record.Set("private_key", privEncrypted)
|
||||
record.Set("user", u.Id)
|
||||
@@ -147,7 +147,7 @@ func TrailFromActivity(activity pub.Activity, app core.App, actor *core.Record)
|
||||
// the local record; a remote actor must not be able to reference or attach
|
||||
// side effects (feeds/shares/notifications) to local content by id.
|
||||
if IsLocalIRI(iri) {
|
||||
if !actor.GetBool("isLocal") {
|
||||
if !actor.GetBool("is_local") {
|
||||
return nil, fmt.Errorf("refusing remote activity referencing local trail %q", iri)
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ func ListFromActivity(activity pub.Activity, app core.App, actor *core.Record) (
|
||||
|
||||
// Own content must never be ingested as if it were remote (see TrailFromActivity).
|
||||
if IsLocalIRI(iri) {
|
||||
if !actor.GetBool("isLocal") {
|
||||
if !actor.GetBool("is_local") {
|
||||
return nil, fmt.Errorf("refusing remote activity referencing local list %q", iri)
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
func documentFromTrailRecord(app core.App, r *core.Record, author *core.Record, includeShares bool) (map[string]interface{}, error) {
|
||||
func documentFromTrailRecord(r *core.Record, author *core.Record, includeShares bool) (map[string]interface{}, error) {
|
||||
photos := r.GetStringSlice("photos")
|
||||
thumbnail := ""
|
||||
if len(photos) > 0 {
|
||||
@@ -42,7 +42,7 @@ func documentFromTrailRecord(app core.App, r *core.Record, author *core.Record,
|
||||
bounds := getStoredBounds(r)
|
||||
|
||||
domain := ""
|
||||
if !author.GetBool("isLocal") {
|
||||
if !author.GetBool("is_local") {
|
||||
domain = author.GetString("domain")
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func documentFromListRecord(r *core.Record, author *core.Record, includeShares b
|
||||
totalDuration := 0.0
|
||||
trails := len(r.GetStringSlice("trails"))
|
||||
|
||||
if r.GetString("iri") != "" && !author.GetBool("isLocal") {
|
||||
if r.GetString("iri") != "" && !author.GetBool("is_local") {
|
||||
doc, err := documentFromRemoteRecord(r, "lists")
|
||||
if err == nil {
|
||||
totalElevationGain = doc["elevation_gain"].(float64)
|
||||
@@ -181,7 +181,7 @@ func documentFromListRecord(r *core.Record, author *core.Record, includeShares b
|
||||
}
|
||||
|
||||
domain := ""
|
||||
if !author.GetBool("isLocal") {
|
||||
if !author.GetBool("is_local") {
|
||||
domain = author.GetString("domain")
|
||||
}
|
||||
|
||||
@@ -222,6 +222,21 @@ func documentFromListRecord(r *core.Record, author *core.Record, includeShares b
|
||||
return document, nil
|
||||
}
|
||||
|
||||
func documentFromActorRecord(r *core.Record) (map[string]any, error) {
|
||||
|
||||
document := map[string]any{
|
||||
"id": r.Id,
|
||||
"username": r.GetString("username"),
|
||||
"preferred_username": r.GetString("preferred_username"),
|
||||
"domain": r.GetString("domain"),
|
||||
"iri": r.GetString("iri"),
|
||||
"icon": r.GetString("icon"),
|
||||
"is_local": r.GetBool("is_local"),
|
||||
}
|
||||
|
||||
return document, nil
|
||||
}
|
||||
|
||||
func documentFromRemoteRecord(r *core.Record, index string) (map[string]any, error) {
|
||||
client := &http.Client{}
|
||||
|
||||
@@ -309,7 +324,7 @@ func IndexTrails(app core.App, trails []*core.Record, client meilisearch.Service
|
||||
|
||||
author := r.ExpandedOne("author")
|
||||
|
||||
doc, err := documentFromTrailRecord(app, r, author, true)
|
||||
doc, err := documentFromTrailRecord(r, author, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -334,7 +349,7 @@ func UpdateTrail(app core.App, r *core.Record, author *core.Record, client meili
|
||||
return fmt.Errorf("meilisearch update trail: failed to expand category: %v", errs)
|
||||
}
|
||||
|
||||
doc, err := documentFromTrailRecord(app, r, author, false)
|
||||
doc, err := documentFromTrailRecord(r, author, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -424,6 +439,37 @@ func UpdateList(app core.App, r *core.Record, author *core.Record, client meilis
|
||||
return nil
|
||||
}
|
||||
|
||||
func IndexActors(actors []*core.Record, client meilisearch.ServiceManager) error {
|
||||
documents := make([]map[string]any, len(actors))
|
||||
|
||||
for i, r := range actors {
|
||||
|
||||
doc, err := documentFromActorRecord(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
documents[i] = doc
|
||||
}
|
||||
if _, err := client.Index("actors").AddDocuments(documents, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateActor(r *core.Record, client meilisearch.ServiceManager) error {
|
||||
documents, err := documentFromActorRecord(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err = client.Index("actors").UpdateDocuments(documents, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateListShares(listId string, shares []string, client meilisearch.ServiceManager) error {
|
||||
documents := []map[string]interface{}{
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ func SendNotification(app core.App, notification Notification, recipient *core.R
|
||||
if notification.Author == recipient.Id {
|
||||
return nil
|
||||
}
|
||||
if !recipient.GetBool("isLocal") {
|
||||
if !recipient.GetBool("is_local") {
|
||||
return nil
|
||||
}
|
||||
permissions, err := getNotificationPermissions(app, recipient.GetString("user"), notification.Type)
|
||||
|
||||
Reference in New Issue
Block a user