feat: Adds a webhook for when a user follows the stream (#4362)
* feat: Adds a webhook for when a user follow the stream Frontend: Adds a checkbox which renders only when social features are enabled. Backend: - Defines a new type for the event - Implements the webhook including unit testing - Fires the webhook inside the ApproveFollower handler * Removes unnecessary Type fiels from Events struct * refactor: renames SendUserFollowedEvent func to FediverseEngagementFollow and fixes linting errors * fix: fixes unit test to reflect removed Type field from FediverseEngagementFollowEvent * feat: fires webhook also when manual approvals are not required * chore: slight cleanup --------- Co-authored-by: Gabe Kangas <gabek@real-ity.com>
This commit is contained in:
co-authored by
Gabe Kangas
parent
9cc58d14c3
commit
80850b15d0
@@ -0,0 +1,19 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/teris-io/shortid"
|
||||
)
|
||||
|
||||
// Event is any kind of event.
|
||||
type Event struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// SetDefaults will set default properties of all inbound events.
|
||||
func (e *Event) SetDefaults() {
|
||||
e.ID = shortid.MustGenerate()
|
||||
e.Timestamp = time.Now()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package events
|
||||
|
||||
type FediverseEngagementFollowEvent struct {
|
||||
Event
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
Image string `json:"image"`
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/owncast/owncast/activitypub/requests"
|
||||
"github.com/owncast/owncast/activitypub/resolvers"
|
||||
"github.com/owncast/owncast/core/chat/events"
|
||||
"github.com/owncast/owncast/core/webhooks"
|
||||
"github.com/owncast/owncast/persistence/configrepository"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -39,20 +40,19 @@ func handleFollowInboxRequest(c context.Context, activity vocab.ActivityStreamsF
|
||||
}
|
||||
|
||||
localAccountName := configRepository.GetDefaultFederationUsername()
|
||||
actorReference := activity.GetActivityStreamsActor()
|
||||
object := activity.GetActivityStreamsObject()
|
||||
objectIRI := object.At(0).GetIRI().String()
|
||||
actorIRI := actorReference.At(0).GetIRI().String()
|
||||
|
||||
if approved {
|
||||
if err := requests.SendFollowAccept(follow.Inbox, activity, localAccountName); err != nil {
|
||||
log.Errorln("unable to send follow accept", err)
|
||||
return err
|
||||
}
|
||||
go webhooks.SendFediverseEngagementFollowEvent(actorIRI)
|
||||
}
|
||||
|
||||
// Save as an activity
|
||||
actorReference := activity.GetActivityStreamsActor()
|
||||
object := activity.GetActivityStreamsObject()
|
||||
objectIRI := object.At(0).GetIRI().String()
|
||||
actorIRI := actorReference.At(0).GetIRI().String()
|
||||
|
||||
// If this request is approved and we have not previously sent an action to
|
||||
// chat due to a previous follow request, then do so.
|
||||
hasPreviouslyhandled := true // Default so we don't send anything if it fails.
|
||||
|
||||
Reference in New Issue
Block a user