Skip to content

Commit

Permalink
fix: app notifications permissions in nip47 info event
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Dec 23, 2024
1 parent d622481 commit d46460b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions nip47/publish_nip47_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ func (svc *nip47Service) GetNip47Info(ctx context.Context, relay *nostr.Relay, a

func (svc *nip47Service) PublishNip47Info(ctx context.Context, relay nostrmodels.Relay, appWalletPubKey string, appWalletPrivKey string, lnClient lnclient.LNClient) (*nostr.Event, error) {
var capabilities []string
var notifications []string
var permitsNotifications bool
if svc.keys.GetNostrPublicKey() == appWalletPubKey {
// legacy app, so return lnClient.GetSupportedNIP47Methods()
capabilities = lnClient.GetSupportedNIP47Methods()
permitsNotifications = true
} else {
app := db.App{}
err := svc.db.First(&app, &db.App{
Expand All @@ -51,17 +54,22 @@ func (svc *nip47Service) PublishNip47Info(ctx context.Context, relay nostrmodels
return nil, err
}
capabilities = svc.permissionsService.GetPermittedMethods(&app, lnClient)
permitsNotifications = svc.permissionsService.PermitsNotifications(&app)
}
if len(lnClient.GetSupportedNIP47NotificationTypes()) > 0 {
if permitsNotifications && len(lnClient.GetSupportedNIP47NotificationTypes()) > 0 {
capabilities = append(capabilities, "notifications")
notifications = lnClient.GetSupportedNIP47NotificationTypes()
}

ev := &nostr.Event{}
ev.Kind = models.INFO_EVENT_KIND
ev.Content = strings.Join(capabilities, " ")
ev.CreatedAt = nostr.Now()
ev.PubKey = appWalletPubKey
ev.Tags = nostr.Tags{[]string{"notifications", strings.Join(lnClient.GetSupportedNIP47NotificationTypes(), " ")}}
ev.Tags = nostr.Tags{[]string{}}
if len(notifications) > 0 {
ev.Tags = append(ev.Tags, []string{"notifications", strings.Join(notifications, " ")})
}
err := ev.Sign(appWalletPrivKey)
if err != nil {
return nil, err
Expand Down

0 comments on commit d46460b

Please sign in to comment.