-
Notifications
You must be signed in to change notification settings - Fork 1
/
instance.go
30 lines (24 loc) · 928 Bytes
/
instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package services
import (
"context"
"net/url"
"github.com/shigde/sfu/internal/activitypub/instance"
"github.com/shigde/sfu/internal/activitypub/models"
)
type InstanceService struct {
config *instance.FederationConfig
instanceRepo *models.InstanceRepository
}
func NewInstanceService(config *instance.FederationConfig, instanceRepo *models.InstanceRepository) *InstanceService {
return &InstanceService{config: config, instanceRepo: instanceRepo}
}
func (s *InstanceService) getInstanceByActorIri(ctx context.Context, iri *url.URL) (*models.Instance, bool) {
if shigInstance, err := s.instanceRepo.GetInstanceByActorIri(ctx, iri); err == nil {
return shigInstance, true
}
return nil, false
}
func (s *InstanceService) upsertInstanceByActor(ctx context.Context, actor *models.Actor) (*models.Instance, error) {
shigInstance := models.NewInstance(actor)
return s.instanceRepo.Upsert(ctx, shigInstance)
}