activitypub.go 1.8 KB

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