Skip to content

Commit

Permalink
feat: add the "to" attribute mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed May 6, 2024
1 parent 6f7307d commit 367eebf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions service/converter/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const CeKeyStarts = "starts"
const CeKeySubject = "subject"
const CeKeySummary = "summary"
const CeKeyTime = "time"
const CeKeyTo = "to"
const CeKeyUpdated = "updated"

var ErrFail = errors.New("failed to convert")
Expand Down Expand Up @@ -204,6 +205,9 @@ func (svc service) convertObject(obj *vocab.Object, evt *pb.CloudEvent) (err err
if tags := obj.Tag; tags != nil && len(tags) > 0 {
err = errors.Join(err, convertAsCollection(tags, evt, CeKeyCategories))
}
if to := obj.To; to != nil && len(to) > 0 {
err = errors.Join(err, convertAsCollection(to, evt, CeKeyTo))
}
if !obj.Updated.IsZero() {
evt.Attributes[CeKeyUpdated] = &pb.CloudEventAttributeValue{
Attr: &pb.CloudEventAttributeValue_CeTimestamp{
Expand Down Expand Up @@ -301,6 +305,9 @@ func (svc service) convertActivityAsObject(obj vocab.Activity, evt *pb.CloudEven
if tags := obj.Tag; tags != nil && len(tags) > 0 {
err = errors.Join(err, convertAsCollection(tags, evt, CeKeyCategories))
}
if to := obj.To; to != nil && len(to) > 0 {
err = errors.Join(err, convertAsCollection(to, evt, CeKeyTo))
}
if !obj.Updated.IsZero() {
evt.Attributes[CeKeyUpdated] = &pb.CloudEventAttributeValue{
Attr: &pb.CloudEventAttributeValue_CeTimestamp{
Expand Down
20 changes: 20 additions & 0 deletions service/converter/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func TestService_Convert(t *testing.T) {
CeString: "https://mastodon.social/users/akurilov/followers",
},
},
"to": {
Attr: &pb.CloudEventAttributeValue_CeString{
CeString: "https://www.w3.org/ns/activitystreams#Public",
},
},
"object": {
Attr: &pb.CloudEventAttributeValue_CeString{
CeString: "Note",
Expand Down Expand Up @@ -154,6 +159,11 @@ func TestService_Convert(t *testing.T) {
CeString: "https://e14n.com/evan",
},
},
"to": {
Attr: &pb.CloudEventAttributeValue_CeString{
CeString: "https://rhiaro.co.uk/followers/",
},
},
"object": {
Attr: &pb.CloudEventAttributeValue_CeString{
CeString: "Article",
Expand Down Expand Up @@ -243,6 +253,11 @@ func TestService_Convert(t *testing.T) {
},
},
},
"to": {
Attr: &pb.CloudEventAttributeValue_CeString{
CeString: "https://www.w3.org/ns/activitystreams#Public",
},
},
},
Data: &pb.CloudEvent_TextData{
TextData: "I just checked-in to <a href=\"https://www.openstreetmap.org/way/958999496\">John Lennon's Imagine Mosaic</a>.",
Expand Down Expand Up @@ -289,6 +304,11 @@ func TestService_Convert(t *testing.T) {
},
},
},
"to": {
Attr: &pb.CloudEventAttributeValue_CeString{
CeString: "https://rhiaro.co.uk/#amy https://dustycloud.org/followers https://rhiaro.co.uk/followers/",
},
},
},
Data: &pb.CloudEvent_TextData{
TextData: "Chris liked 'Minimal ActivityPub update client'",
Expand Down

0 comments on commit 367eebf

Please sign in to comment.