activitypub.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package activitypub
  2. import (
  3. "github.com/owncast/owncast/activitypub/crypto"
  4. "github.com/owncast/owncast/activitypub/inbox"
  5. "github.com/owncast/owncast/activitypub/outbox"
  6. "github.com/owncast/owncast/activitypub/persistence"
  7. "github.com/owncast/owncast/activitypub/workerpool"
  8. "github.com/owncast/owncast/core/data"
  9. "github.com/owncast/owncast/models"
  10. log "github.com/sirupsen/logrus"
  11. )
  12. // Start will initialize and start the federation support.
  13. func Start(datastore *data.Datastore) {
  14. persistence.Setup(datastore)
  15. workerpool.InitOutboundWorkerPool()
  16. inbox.InitInboxWorkerPool()
  17. StartRouter()
  18. // Generate the keys for signing federated activity if needed.
  19. if data.GetPrivateKey() == "" {
  20. privateKey, publicKey, err := crypto.GenerateKeys()
  21. _ = data.SetPrivateKey(string(privateKey))
  22. _ = data.SetPublicKey(string(publicKey))
  23. if err != nil {
  24. log.Errorln("Unable to get private key", err)
  25. }
  26. }
  27. }
  28. // SendLive will send a "Go Live" message to followers.
  29. func SendLive() error {
  30. return outbox.SendLive()
  31. }
  32. // SendPublicFederatedMessage will send an arbitrary provided message to followers.
  33. func SendPublicFederatedMessage(message string) error {
  34. return outbox.SendPublicMessage(message)
  35. }
  36. // GetFollowerCount will return the local tracked follower count.
  37. func GetFollowerCount() (int64, error) {
  38. return persistence.GetFollowerCount()
  39. }
  40. // GetPendingFollowRequests will return the pending follow requests.
  41. func GetPendingFollowRequests() ([]models.Follower, error) {
  42. return persistence.GetPendingFollowRequests()
  43. }