activitypub.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // SendDirectFederatedMessage will send a direct message to a single account.
  37. func SendDirectFederatedMessage(message, account string) error {
  38. return outbox.SendDirectMessageToAccount(message, account)
  39. }
  40. // GetFollowerCount will return the local tracked follower count.
  41. func GetFollowerCount() (int64, error) {
  42. return persistence.GetFollowerCount()
  43. }
  44. // GetPendingFollowRequests will return the pending follow requests.
  45. func GetPendingFollowRequests() ([]models.Follower, error) {
  46. return persistence.GetPendingFollowRequests()
  47. }