mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-01 19:11:05 +02:00
nip34: fixes.
This commit is contained in:
@ -52,7 +52,7 @@ func ParseRepository(event nostr.Event) Repository {
|
|||||||
return repo
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Repository) ToEvent() nostr.Event {
|
func (r Repository) ToEvent() *nostr.Event {
|
||||||
tags := make(nostr.Tags, 0, 10)
|
tags := make(nostr.Tags, 0, 10)
|
||||||
|
|
||||||
tags = append(tags, nostr.Tag{"d", r.ID})
|
tags = append(tags, nostr.Tag{"d", r.ID})
|
||||||
@ -91,12 +91,29 @@ func (r Repository) ToEvent() nostr.Event {
|
|||||||
tags = append(tags, tag)
|
tags = append(tags, tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nostr.Event{
|
return &nostr.Event{
|
||||||
Kind: 30617,
|
Kind: nostr.KindRepositoryAnnouncement,
|
||||||
Tags: tags,
|
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 {
|
func (repo Repository) GetPatchesSync(ctx context.Context, s nostr.RelayStore) []Patch {
|
||||||
res, _ := s.QuerySync(ctx, nostr.Filter{
|
res, _ := s.QuerySync(ctx, nostr.Filter{
|
||||||
Kinds: []int{nostr.KindPatch},
|
Kinds: []int{nostr.KindPatch},
|
||||||
|
@ -45,20 +45,23 @@ func ParseRepositoryState(event nostr.Event) RepositoryState {
|
|||||||
return st
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rs RepositoryState) ToEvent() nostr.Event {
|
func (rs RepositoryState) ToEvent() *nostr.Event {
|
||||||
tags := make(nostr.Tags, 0, 2+len(rs.Branches)+len(rs.Tags))
|
tags := make(nostr.Tags, 1, 2+len(rs.Branches)+len(rs.Tags))
|
||||||
|
|
||||||
tags = append(tags, nostr.Tag{"d", rs.ID})
|
tags[0] = nostr.Tag{"d", rs.ID}
|
||||||
tags = append(tags, nostr.Tag{"ref: refs/heads/" + rs.HEAD})
|
|
||||||
for branchName, commitId := range rs.Branches {
|
for branchName, commitId := range rs.Branches {
|
||||||
tags = append(tags, nostr.Tag{"refs/heads/" + branchName, commitId})
|
tags = append(tags, nostr.Tag{"refs/heads/" + branchName, commitId})
|
||||||
}
|
}
|
||||||
for tagName, commitId := range rs.Tags {
|
for tagName, commitId := range rs.Tags {
|
||||||
tags = append(tags, nostr.Tag{"refs/tags/" + tagName, commitId})
|
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{
|
return &nostr.Event{
|
||||||
Kind: 30618,
|
Kind: 30618,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
|
CreatedAt: nostr.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user