activitypub.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // Generate the keys for signing federated activity if needed.
  18. if data.GetPrivateKey() == "" {
  19. privateKey, publicKey, err := crypto.GenerateKeys()
  20. _ = data.SetPrivateKey(string(privateKey))
  21. _ = data.SetPublicKey(string(publicKey))
  22. if err != nil {
  23. log.Errorln("Unable to get private key", err)
  24. }
  25. }
  26. }
  27. // SendLive will send a "Go Live" message to followers.
  28. func SendLive() error {
  29. return outbox.SendLive()
  30. }
  31. // SendPublicFederatedMessage will send an arbitrary provided message to followers.
  32. func SendPublicFederatedMessage(message string) error {
  33. return outbox.SendPublicMessage(message)
  34. }
  35. // SendDirectFederatedMessage will send a direct message to a single account.
  36. func SendDirectFederatedMessage(message, account string) error {
  37. return outbox.SendDirectMessageToAccount(message, account)
  38. }
  39. // GetFollowerCount will return the local tracked follower count.
  40. func GetFollowerCount() (int64, error) {
  41. return persistence.GetFollowerCount()
  42. }
  43. // GetPendingFollowRequests will return the pending follow requests.
  44. func GetPendingFollowRequests() ([]models.Follower, error) {
  45. return persistence.GetPendingFollowRequests()
  46. }