* fix(ap): add safe constructors, getters, and validators to ActivityPub actors to address #4701 * chore: replace nil check with the new Validate() method * chore(test): added test to verify the values extracted from actors * fix: return the specific error type + test for it * fix(ap): add recovery for each AP inbox worker for a worst case scenario * fix(ap): add additional safe accessor methods to other AP entities other than actors * chore(tests): add tests for the new safe accessors * fix(ap): handle empty public keys in AP actors
49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package inbox
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/go-fed/activity/streams/vocab"
|
|
"github.com/owncast/owncast/activitypub/apmodels"
|
|
"github.com/owncast/owncast/activitypub/persistence"
|
|
"github.com/owncast/owncast/core/chat/events"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func handleLikeRequest(c context.Context, activity vocab.ActivityStreamsLike) error {
|
|
objectIRI, err := apmodels.GetIRIStringFromObjectProperty(activity.GetActivityStreamsObject())
|
|
if err != nil {
|
|
return errors.Wrap(err, "like activity is missing object IRI")
|
|
}
|
|
|
|
actorIRI, err := apmodels.GetIRIStringFromActorProperty(activity.GetActivityStreamsActor())
|
|
if err != nil {
|
|
return errors.Wrap(err, "like activity is missing actor IRI")
|
|
}
|
|
|
|
actorReference := activity.GetActivityStreamsActor()
|
|
|
|
if hasPreviouslyhandled, err := persistence.HasPreviouslyHandledInboundActivity(objectIRI, actorIRI, events.FediverseEngagementLike); hasPreviouslyhandled || err != nil {
|
|
return errors.Wrap(err, "inbound activity of like has already been handled")
|
|
}
|
|
|
|
// Likes need to match a post we had already sent.
|
|
_, isLiveNotification, timestamp, err := persistence.GetObjectByIRI(objectIRI)
|
|
if err != nil {
|
|
return errors.Wrap(err, "Could not find post locally")
|
|
}
|
|
|
|
// Don't allow old activities to be liked
|
|
if time.Since(timestamp) > maxAgeForEngagement {
|
|
return errors.New("Activity is too old to be liked")
|
|
}
|
|
|
|
// Save as an accepted activity
|
|
if err := persistence.SaveInboundFediverseActivity(objectIRI, actorIRI, events.FediverseEngagementLike, time.Now()); err != nil {
|
|
return errors.Wrap(err, "unable to save inbound like activity")
|
|
}
|
|
|
|
return handleEngagementActivity(events.FediverseEngagementLike, isLiveNotification, actorReference, events.FediverseEngagementLike)
|
|
}
|