Refine statuses (#26)
Remote media is now dereferenced and attached properly to incoming federated statuses. Mentions are now dereferenced and attached properly to incoming federated statuses. Small fixes to status visibility. Allow URL params for filtering statuses: // ExcludeRepliesKey is for specifying whether to exclude replies in a list of returned statuses by an account. // PinnedKey is for specifying whether to include pinned statuses in a list of returned statuses by an account. // MaxIDKey is for specifying the maximum ID of the status to retrieve. // MediaOnlyKey is for specifying that only statuses with media should be returned in a list of returned statuses by an account. Add endpoint for fetching an account's statuses.
This commit is contained in:
@ -29,6 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-fed/activity/pub"
|
||||
"github.com/go-fed/activity/streams"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
)
|
||||
@ -304,12 +305,24 @@ func extractAttachments(i withAttachment) ([]*gtsmodel.MediaAttachment, error) {
|
||||
|
||||
attachmentProp := i.GetActivityStreamsAttachment()
|
||||
for iter := attachmentProp.Begin(); iter != attachmentProp.End(); iter = iter.Next() {
|
||||
attachmentable, ok := iter.(Attachmentable)
|
||||
|
||||
t := iter.GetType()
|
||||
if t == nil {
|
||||
fmt.Printf("\n\n\nGetType() nil\n\n\n")
|
||||
continue
|
||||
}
|
||||
|
||||
m, _ := streams.Serialize(t)
|
||||
fmt.Printf("\n\n\n%s\n\n\n", m)
|
||||
|
||||
attachmentable, ok := t.(Attachmentable)
|
||||
if !ok {
|
||||
fmt.Printf("\n\n\nnot attachmentable\n\n\n")
|
||||
continue
|
||||
}
|
||||
attachment, err := extractAttachment(attachmentable)
|
||||
if err != nil {
|
||||
fmt.Printf("\n\n\n%s\n\n\n", err)
|
||||
continue
|
||||
}
|
||||
attachments = append(attachments, attachment)
|
||||
@ -343,23 +356,20 @@ func extractAttachment(i Attachmentable) (*gtsmodel.MediaAttachment, error) {
|
||||
attachment.Description = name
|
||||
}
|
||||
|
||||
blurhash, err := extractBlurhash(i)
|
||||
if err == nil {
|
||||
attachment.Blurhash = blurhash
|
||||
}
|
||||
attachment.Processing = gtsmodel.ProcessingStatusReceived
|
||||
|
||||
return attachment, nil
|
||||
}
|
||||
|
||||
func extractBlurhash(i withBlurhash) (string, error) {
|
||||
if i.GetTootBlurhashProperty() == nil {
|
||||
return "", errors.New("blurhash property was nil")
|
||||
}
|
||||
if i.GetTootBlurhashProperty().Get() == "" {
|
||||
return "", errors.New("empty blurhash string")
|
||||
}
|
||||
return i.GetTootBlurhashProperty().Get(), nil
|
||||
}
|
||||
// func extractBlurhash(i withBlurhash) (string, error) {
|
||||
// if i.GetTootBlurhashProperty() == nil {
|
||||
// return "", errors.New("blurhash property was nil")
|
||||
// }
|
||||
// if i.GetTootBlurhashProperty().Get() == "" {
|
||||
// return "", errors.New("empty blurhash string")
|
||||
// }
|
||||
// return i.GetTootBlurhashProperty().Get(), nil
|
||||
// }
|
||||
|
||||
func extractHashtags(i withTag) ([]*gtsmodel.Tag, error) {
|
||||
tags := []*gtsmodel.Tag{}
|
||||
|
@ -69,8 +69,6 @@ type Attachmentable interface {
|
||||
withMediaType
|
||||
withURL
|
||||
withName
|
||||
withBlurhash
|
||||
withFocalPoint
|
||||
}
|
||||
|
||||
// Hashtaggable represents the minimum activitypub interface for representing a 'hashtag' tag.
|
||||
@ -212,13 +210,13 @@ type withMediaType interface {
|
||||
GetActivityStreamsMediaType() vocab.ActivityStreamsMediaTypeProperty
|
||||
}
|
||||
|
||||
type withBlurhash interface {
|
||||
GetTootBlurhashProperty() vocab.TootBlurhashProperty
|
||||
}
|
||||
// type withBlurhash interface {
|
||||
// GetTootBlurhashProperty() vocab.TootBlurhashProperty
|
||||
// }
|
||||
|
||||
type withFocalPoint interface {
|
||||
// TODO
|
||||
}
|
||||
// type withFocalPoint interface {
|
||||
// // TODO
|
||||
// }
|
||||
|
||||
type withHref interface {
|
||||
GetActivityStreamsHref() vocab.ActivityStreamsHrefProperty
|
||||
|
@ -281,7 +281,7 @@ func (c *converter) ASStatusToStatus(statusable Statusable) (*gtsmodel.Status, e
|
||||
|
||||
// if it's CC'ed to public, it's public or unlocked
|
||||
// mentioned SPECIFIC ACCOUNTS also get added to CC'es if it's not a direct message
|
||||
if isPublic(to) {
|
||||
if isPublic(cc) || isPublic(to) {
|
||||
visibility = gtsmodel.VisibilityPublic
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ package typeutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
@ -86,16 +87,12 @@ func (c *converter) AccountToMastoPublic(a *gtsmodel.Account) (*model.Account, e
|
||||
}
|
||||
|
||||
// count statuses
|
||||
statuses := []gtsmodel.Status{}
|
||||
if err := c.db.GetStatusesByAccountID(a.ID, &statuses); err != nil {
|
||||
statusesCount, err := c.db.CountStatusesByAccountID(a.ID)
|
||||
if err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); !ok {
|
||||
return nil, fmt.Errorf("error getting last statuses: %s", err)
|
||||
}
|
||||
}
|
||||
var statusesCount int
|
||||
if statuses != nil {
|
||||
statusesCount = len(statuses)
|
||||
}
|
||||
|
||||
// check when the last status was
|
||||
lastStatus := >smodel.Status{}
|
||||
@ -195,7 +192,7 @@ func (c *converter) AppToMastoPublic(a *gtsmodel.Application) (*model.Applicatio
|
||||
func (c *converter) AttachmentToMasto(a *gtsmodel.MediaAttachment) (model.Attachment, error) {
|
||||
return model.Attachment{
|
||||
ID: a.ID,
|
||||
Type: string(a.Type),
|
||||
Type: strings.ToLower(string(a.Type)),
|
||||
URL: a.URL,
|
||||
PreviewURL: a.Thumbnail.URL,
|
||||
RemoteURL: a.RemoteURL,
|
||||
@ -294,7 +291,6 @@ func (c *converter) StatusToMasto(
|
||||
var faved bool
|
||||
var reblogged bool
|
||||
var bookmarked bool
|
||||
var pinned bool
|
||||
var muted bool
|
||||
|
||||
// requestingAccount will be nil for public requests without auth
|
||||
@ -319,11 +315,6 @@ func (c *converter) StatusToMasto(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error checking if requesting account has bookmarked status: %s", err)
|
||||
}
|
||||
|
||||
pinned, err = c.db.StatusPinnedBy(s, requestingAccount.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error checking if requesting account has pinned status: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
var mastoRebloggedStatus *model.Status
|
||||
@ -522,7 +513,7 @@ func (c *converter) StatusToMasto(
|
||||
Reblogged: reblogged,
|
||||
Muted: muted,
|
||||
Bookmarked: bookmarked,
|
||||
Pinned: pinned,
|
||||
Pinned: s.Pinned,
|
||||
Content: s.Content,
|
||||
Reblog: mastoRebloggedStatus,
|
||||
Application: mastoApplication,
|
||||
|
Reference in New Issue
Block a user