summaryrefslogtreecommitdiff
path: root/internal/typeutils/astointernal.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-02-02 16:41:02 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-02 16:41:02 +0100
commit271da016b91d8d575e13be03b440f970cd333ebe (patch)
tree4870baceb2266d14906f66d2c9445144fb85746b /internal/typeutils/astointernal.go
parent[feature] Implement `/api/v2/instance` endpoint (#1409) (diff)
downloadgotosocial-271da016b91d8d575e13be03b440f970cd333ebe.tar.xz
[bugfix] Read Bookwyrm Articles more thoroughly (#1410)
Diffstat (limited to 'internal/typeutils/astointernal.go')
-rw-r--r--internal/typeutils/astointernal.go55
1 files changed, 41 insertions, 14 deletions
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go
index bebf62989..7df2a138e 100644
--- a/internal/typeutils/astointernal.go
+++ b/internal/typeutils/astointernal.go
@@ -86,9 +86,10 @@ func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable a
// display name aka name
// we default to the username, but take the more nuanced name property if it exists
- acct.DisplayName = username
- if displayName, err := ap.ExtractName(accountable); err == nil {
+ if displayName := ap.ExtractName(accountable); displayName != "" {
acct.DisplayName = displayName
+ } else {
+ acct.DisplayName = username
}
// account emojis (used in bio, display name, fields)
@@ -101,10 +102,7 @@ func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable a
// TODO: fields aka attachment array
// note aka summary
- note, err := ap.ExtractSummary(accountable)
- if err == nil && note != "" {
- acct.Note = note
- }
+ acct.Note = ap.ExtractSummary(accountable)
// check for bot and actor type
switch accountable.GetTypeName() {
@@ -219,6 +217,38 @@ func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable a
return acct, nil
}
+func (c *converter) extractAttachments(i ap.WithAttachment) []*gtsmodel.MediaAttachment {
+ attachmentProp := i.GetActivityStreamsAttachment()
+ if attachmentProp == nil {
+ return nil
+ }
+
+ attachments := make([]*gtsmodel.MediaAttachment, 0, attachmentProp.Len())
+
+ for iter := attachmentProp.Begin(); iter != attachmentProp.End(); iter = iter.Next() {
+ t := iter.GetType()
+ if t == nil {
+ continue
+ }
+
+ attachmentable, ok := t.(ap.Attachmentable)
+ if !ok {
+ log.Error("ap attachment was not attachmentable")
+ continue
+ }
+
+ attachment, err := ap.ExtractAttachment(attachmentable)
+ if err != nil {
+ log.Errorf("error extracting attachment: %s", err)
+ continue
+ }
+
+ attachments = append(attachments, attachment)
+ }
+
+ return attachments
+}
+
func (c *converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusable) (*gtsmodel.Status, error) {
status := &gtsmodel.Status{}
@@ -243,11 +273,7 @@ func (c *converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
status.Content = ap.ExtractContent(statusable)
// attachments to dereference and fetch later on (we don't do that here)
- if attachments, err := ap.ExtractAttachments(statusable); err != nil {
- l.Infof("ASStatusToStatus: error extracting status attachments: %s", err)
- } else {
- status.Attachments = attachments
- }
+ status.Attachments = c.extractAttachments(statusable)
// hashtags to dereference later on
if hashtags, err := ap.ExtractHashtags(statusable); err != nil {
@@ -271,10 +297,11 @@ func (c *converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
}
// cw string for this status
- if cw, err := ap.ExtractSummary(statusable); err != nil {
- l.Infof("ASStatusToStatus: error extracting status summary: %s", err)
+ // prefer Summary, fall back to Name
+ if summary := ap.ExtractSummary(statusable); summary != "" {
+ status.ContentWarning = summary
} else {
- status.ContentWarning = cw
+ status.ContentWarning = ap.ExtractName(statusable)
}
// when was this status created?