mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
feat: connection created event (#539)
This commit is contained in:
parent
3206b623e8
commit
16f83d75b9
4 changed files with 29 additions and 17 deletions
|
|
@ -27,10 +27,11 @@ import (
|
|||
)
|
||||
|
||||
type albyOAuthService struct {
|
||||
cfg config.Config
|
||||
oauthConf *oauth2.Config
|
||||
db *gorm.DB
|
||||
keys keys.Keys
|
||||
cfg config.Config
|
||||
oauthConf *oauth2.Config
|
||||
db *gorm.DB
|
||||
keys keys.Keys
|
||||
eventPublisher events.EventPublisher
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
@ -40,7 +41,7 @@ const (
|
|||
userIdentifierKey = "AlbyUserIdentifier"
|
||||
)
|
||||
|
||||
func NewAlbyOAuthService(db *gorm.DB, cfg config.Config, keys keys.Keys) *albyOAuthService {
|
||||
func NewAlbyOAuthService(db *gorm.DB, cfg config.Config, keys keys.Keys, eventPublisher events.EventPublisher) *albyOAuthService {
|
||||
conf := &oauth2.Config{
|
||||
ClientID: cfg.GetEnv().AlbyClientId,
|
||||
ClientSecret: cfg.GetEnv().AlbyClientSecret,
|
||||
|
|
@ -59,10 +60,11 @@ func NewAlbyOAuthService(db *gorm.DB, cfg config.Config, keys keys.Keys) *albyOA
|
|||
}
|
||||
|
||||
albyOAuthSvc := &albyOAuthService{
|
||||
oauthConf: conf,
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
keys: keys,
|
||||
oauthConf: conf,
|
||||
cfg: cfg,
|
||||
db: db,
|
||||
keys: keys,
|
||||
eventPublisher: eventPublisher,
|
||||
}
|
||||
return albyOAuthSvc
|
||||
}
|
||||
|
|
@ -382,7 +384,7 @@ func (svc *albyOAuthService) LinkAccount(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
app, _, err := db.NewDBService(svc.db).CreateApp(
|
||||
app, _, err := db.NewDBService(svc.db, svc.eventPublisher).CreateApp(
|
||||
"getalby.com",
|
||||
connectionPubkey,
|
||||
1_000_000,
|
||||
|
|
|
|||
|
|
@ -39,13 +39,13 @@ type api struct {
|
|||
albyOAuthSvc alby.AlbyOAuthService
|
||||
}
|
||||
|
||||
func NewAPI(svc service.Service, gormDB *gorm.DB, config config.Config, keys keys.Keys, albyOAuthSvc alby.AlbyOAuthService, eventsPublisher events.EventPublisher) *api {
|
||||
func NewAPI(svc service.Service, gormDB *gorm.DB, config config.Config, keys keys.Keys, albyOAuthSvc alby.AlbyOAuthService, eventPublisher events.EventPublisher) *api {
|
||||
return &api{
|
||||
db: gormDB,
|
||||
dbSvc: db.NewDBService(gormDB),
|
||||
dbSvc: db.NewDBService(gormDB, eventPublisher),
|
||||
cfg: config,
|
||||
svc: svc,
|
||||
permissionsSvc: permissions.NewPermissionsService(gormDB, eventsPublisher),
|
||||
permissionsSvc: permissions.NewPermissionsService(gormDB, eventPublisher),
|
||||
keys: keys,
|
||||
albyOAuthSvc: albyOAuthSvc,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,18 +5,21 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/getAlby/nostr-wallet-connect/events"
|
||||
"github.com/getAlby/nostr-wallet-connect/logger"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type dbService struct {
|
||||
db *gorm.DB
|
||||
db *gorm.DB
|
||||
eventPublisher events.EventPublisher
|
||||
}
|
||||
|
||||
func NewDBService(db *gorm.DB) *dbService {
|
||||
func NewDBService(db *gorm.DB, eventPublisher events.EventPublisher) *dbService {
|
||||
return &dbService{
|
||||
db: db,
|
||||
db: db,
|
||||
eventPublisher: eventPublisher,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,5 +70,12 @@ func (svc *dbService) CreateApp(name string, pubkey string, maxAmount uint64, bu
|
|||
return nil, "", err
|
||||
}
|
||||
|
||||
svc.eventPublisher.Publish(&events.Event{
|
||||
Event: "app_created",
|
||||
Properties: map[string]interface{}{
|
||||
"name": name,
|
||||
},
|
||||
})
|
||||
|
||||
return &app, pairingSecretKey, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func NewService(ctx context.Context) (*service, error) {
|
|||
ctx: ctx,
|
||||
wg: &wg,
|
||||
eventPublisher: eventPublisher,
|
||||
albyOAuthSvc: alby.NewAlbyOAuthService(gormDB, cfg, keys),
|
||||
albyOAuthSvc: alby.NewAlbyOAuthService(gormDB, cfg, keys, eventPublisher),
|
||||
nip47Service: nip47.NewNip47Service(gormDB, cfg, keys, eventPublisher),
|
||||
db: gormDB,
|
||||
keys: keys,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue