Skip to content

Commit 4f91e09

Browse files
committed
Adjust Create{Note} activity to match Betula
1 parent e2861ee commit 4f91e09

2 files changed

Lines changed: 36 additions & 11 deletions

File tree

activitypub/activitypub.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type Outbox struct {
7070

7171
// OutboxItem represents a single activity in an outbox.
7272
type OutboxItem struct {
73-
Context string `json:"@context"`
73+
Context any `json:"@context"`
7474
ID string `json:"id"`
7575
Type string `json:"type"`
7676
Actor string `json:"actor"`
@@ -95,6 +95,14 @@ type OutboxObject struct {
9595
Published string `json:"published"`
9696
Tag []Tag `json:"tag"`
9797
Replies map[string]string `json:"replies"`
98+
Name string `json:"name"`
99+
Source SourceObject `json:"source"`
100+
Attachments []Attachment `json:"attachment"`
101+
}
102+
103+
type SourceObject struct {
104+
Content string `json:"content"`
105+
MediaType string `json:"mediaType"`
98106
}
99107

100108
// Tag represents a tag or mention in ActivityPub content.
@@ -208,9 +216,10 @@ type FollowResponseObject struct {
208216
// Attachment represents a media attachment in an ActivityPub post.
209217
type Attachment struct {
210218
Type string `json:"type"`
211-
MediaType string `json:"mediaType"`
212-
URL string `json:"url"`
213-
Name string `json:"name"`
219+
MediaType string `json:"mediaType,omitempty"`
220+
URL string `json:"url,omitempty"`
221+
Href string `json:"href,omitempty"`
222+
Name string `json:"name,omitempty"`
214223
}
215224

216225
// https://docs.joinmastodon.org/spec/security/#ld

webapp/activitypub.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ func apCreateBookmarkItem(c *gin.Context, b *model.Bookmark, actor string) *ap.O
9595
body = fmt.Sprintf("<p>%s</p>", truncate(b.Notes, 350-len(title)))
9696
}
9797
item := &ap.OutboxItem{
98-
Context: "https://www.w3.org/ns/activitystreams",
99-
ID: id + "#activity",
100-
Type: createAction,
101-
Actor: actor,
98+
Context: []any{
99+
"https://www.w3.org/ns/activitystreams",
100+
map[string]string{
101+
"Hashtag": "https://www.w3.org/ns/activitystreams#Hashtag",
102+
},
103+
},
104+
ID: id + "#activity",
105+
Type: createAction,
106+
Actor: actor,
102107
To: []string{
103108
"https://www.w3.org/ns/activitystreams#Public",
104109
},
@@ -107,10 +112,10 @@ func apCreateBookmarkItem(c *gin.Context, b *model.Bookmark, actor string) *ap.O
107112
Object: ap.OutboxObject{
108113
ID: id,
109114
Type: noteAction,
110-
Summary: "",
111115
Content: fmt.Sprintf(contentTpl, b.URL, title, body, id),
112-
URL: b.URL,
116+
URL: id,
113117
URI: b.URL,
118+
Summary: "",
114119
AttributedTo: actor,
115120
To: []string{
116121
"https://www.w3.org/ns/activitystreams#Public",
@@ -119,14 +124,25 @@ func apCreateBookmarkItem(c *gin.Context, b *model.Bookmark, actor string) *ap.O
119124
Published: published,
120125
Tag: make([]ap.Tag, len(b.Tags)),
121126
Replies: map[string]string{},
127+
Name: b.Title,
128+
Source: ap.SourceObject{
129+
Content: b.Notes,
130+
MediaType: "text/plain",
131+
},
132+
Attachments: []ap.Attachment{
133+
{
134+
Type: "Link",
135+
Href: b.URL,
136+
},
137+
},
122138
},
123139
}
124140
for i, t := range b.Tags {
125141
tagBase := getFullURL(c, fmt.Sprintf("%s?tag=", URLFor("Public bookmarks")))
126142
item.Object.Tag[i] = ap.Tag{
127143
Type: "Hashtag",
128144
Href: tagBase + t.Text,
129-
Name: t.Text,
145+
Name: "#" + t.Text,
130146
}
131147
}
132148
return item

0 commit comments

Comments
 (0)