nip34: fixes.

This commit is contained in:
fiatjaf
2024-08-28 09:33:42 -03:00
parent 106ca136fd
commit 0750057b13
2 changed files with 31 additions and 11 deletions

View File

@ -52,7 +52,7 @@ func ParseRepository(event nostr.Event) Repository {
return repo
}
func (r Repository) ToEvent() nostr.Event {
func (r Repository) ToEvent() *nostr.Event {
tags := make(nostr.Tags, 0, 10)
tags = append(tags, nostr.Tag{"d", r.ID})
@ -91,12 +91,29 @@ func (r Repository) ToEvent() nostr.Event {
tags = append(tags, tag)
}
return nostr.Event{
Kind: 30617,
Tags: tags,
return &nostr.Event{
Kind: nostr.KindRepositoryAnnouncement,
Tags: tags,
CreatedAt: nostr.Now(),
}
}
func (repo Repository) FetchState(ctx context.Context, s nostr.RelayStore) *RepositoryState {
res, _ := s.QuerySync(ctx, nostr.Filter{
Kinds: []int{nostr.KindRepositoryState},
Tags: nostr.TagMap{
"d": []string{repo.Tags.GetD()},
},
})
if len(res) == 0 {
return nil
}
rs := ParseRepositoryState(*res[0])
return &rs
}
func (repo Repository) GetPatchesSync(ctx context.Context, s nostr.RelayStore) []Patch {
res, _ := s.QuerySync(ctx, nostr.Filter{
Kinds: []int{nostr.KindPatch},

View File

@ -45,20 +45,23 @@ func ParseRepositoryState(event nostr.Event) RepositoryState {
return st
}
func (rs RepositoryState) ToEvent() nostr.Event {
tags := make(nostr.Tags, 0, 2+len(rs.Branches)+len(rs.Tags))
func (rs RepositoryState) ToEvent() *nostr.Event {
tags := make(nostr.Tags, 1, 2+len(rs.Branches)+len(rs.Tags))
tags = append(tags, nostr.Tag{"d", rs.ID})
tags = append(tags, nostr.Tag{"ref: refs/heads/" + rs.HEAD})
tags[0] = nostr.Tag{"d", rs.ID}
for branchName, commitId := range rs.Branches {
tags = append(tags, nostr.Tag{"refs/heads/" + branchName, commitId})
}
for tagName, commitId := range rs.Tags {
tags = append(tags, nostr.Tag{"refs/tags/" + tagName, commitId})
}
if rs.HEAD != "" {
tags = append(tags, nostr.Tag{"HEAD", "ref: refs/heads/" + rs.HEAD})
}
return nostr.Event{
Kind: 30618,
Tags: tags,
return &nostr.Event{
Kind: 30618,
Tags: tags,
CreatedAt: nostr.Now(),
}
}