mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] tentatively start adding polls support (#2249)
This commit is contained in:
@@ -216,40 +216,10 @@ 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(nil, "ap attachment was not attachmentable")
|
||||
continue
|
||||
}
|
||||
|
||||
attachment, err := ap.ExtractAttachment(attachmentable)
|
||||
if err != nil {
|
||||
log.Errorf(nil, "error extracting attachment: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
attachments = append(attachments, attachment)
|
||||
}
|
||||
|
||||
return attachments
|
||||
}
|
||||
|
||||
// ASStatus converts a remote activitystreams 'status' representation into a gts model status.
|
||||
func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusable) (*gtsmodel.Status, error) {
|
||||
var err error
|
||||
|
||||
status := new(gtsmodel.Status)
|
||||
|
||||
// status.URI
|
||||
@@ -281,7 +251,19 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
|
||||
// status.Attachments
|
||||
//
|
||||
// Media attachments for later dereferencing.
|
||||
status.Attachments = c.extractAttachments(statusable)
|
||||
status.Attachments, err = ap.ExtractAttachments(statusable)
|
||||
if err != nil {
|
||||
l.Warnf("error(s) extracting attachments: %v", err)
|
||||
}
|
||||
|
||||
// status.Poll
|
||||
//
|
||||
// Attached poll information (the statusable will actually
|
||||
// be a Pollable, as a Question is a subset of our Status).
|
||||
if pollable, ok := ap.ToPollable(statusable); ok {
|
||||
// TODO: handle decoding poll data
|
||||
_ = pollable
|
||||
}
|
||||
|
||||
// status.Hashtags
|
||||
//
|
||||
@@ -341,7 +323,7 @@ func (c *Converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
|
||||
// error if we don't.
|
||||
attributedTo, err := ap.ExtractAttributedToURI(statusable)
|
||||
if err != nil {
|
||||
return nil, gtserror.Newf("%w", err)
|
||||
return nil, gtserror.Newf("error extracting attributed to uri: %w", err)
|
||||
}
|
||||
accountURI := attributedTo.String()
|
||||
|
||||
|
Reference in New Issue
Block a user