mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] 2643 bug search for account url doesnt always work when redirected (#2673)
* update activity library so dereferencer returns full response and checks *final* link to allow for redirects * temporarily add bodged fixed library * remove unused code * update getAccountFeatured() to use dereferenceCollectionPage() * make sure to release map * perform a 2nd decode to ensure reader is empty after primary decode * add comment explaining choice of using Decode() instead of Unmarshal() * update embedded activity library to latest matching https://github.com/superseriousbusiness/activity/pull/21 * add checks to look for changed URI and re-check database if redirected * update max iteration count to 512, add checks during dereferenceAncestors() for indirect URLs * remove doubled-up code * fix use of status instead of current * use URIs for checking equality for security * use the latest known URI for boost_of_uri in case original was an indirect * add dereferenceCollection() function for dereferenceAccountFeatured() * pull in latest github.com/superseriousbusiness/activity version (and remove the bodge!!) * fix typo in code comments * update decodeType() to accept a readcloser and handle body closing * switch to checking using BoostOfID and add note why not using BoostOfURI * ensure InReplyTo gets unset when deleting status parent in case currently stubbed * add tests for Collection and CollectionPage iterators
This commit is contained in:
@@ -26,6 +26,24 @@ import (
|
||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||
)
|
||||
|
||||
// TODO: replace must of this logic with just
|
||||
// using extractIRIs() on the iterator types.
|
||||
|
||||
// ToCollectionIterator attempts to resolve the given vocab type as a Collection
|
||||
// like object and wrap in a standardised interface in order to iterate its contents.
|
||||
func ToCollectionIterator(t vocab.Type) (CollectionIterator, error) {
|
||||
switch name := t.GetTypeName(); name {
|
||||
case ObjectCollection:
|
||||
t := t.(vocab.ActivityStreamsCollection)
|
||||
return WrapCollection(t), nil
|
||||
case ObjectOrderedCollection:
|
||||
t := t.(vocab.ActivityStreamsOrderedCollection)
|
||||
return WrapOrderedCollection(t), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("%T(%s) was not Collection-like", t, name)
|
||||
}
|
||||
}
|
||||
|
||||
// ToCollectionPageIterator attempts to resolve the given vocab type as a CollectionPage
|
||||
// like object and wrap in a standardised interface in order to iterate its contents.
|
||||
func ToCollectionPageIterator(t vocab.Type) (CollectionPageIterator, error) {
|
||||
@@ -41,6 +59,16 @@ func ToCollectionPageIterator(t vocab.Type) (CollectionPageIterator, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// WrapCollection wraps an ActivityStreamsCollection in a standardised collection interface.
|
||||
func WrapCollection(collection vocab.ActivityStreamsCollection) CollectionIterator {
|
||||
return ®ularCollectionIterator{ActivityStreamsCollection: collection}
|
||||
}
|
||||
|
||||
// WrapOrderedCollection wraps an ActivityStreamsOrderedCollection in a standardised collection interface.
|
||||
func WrapOrderedCollection(collection vocab.ActivityStreamsOrderedCollection) CollectionIterator {
|
||||
return &orderedCollectionIterator{ActivityStreamsOrderedCollection: collection}
|
||||
}
|
||||
|
||||
// WrapCollectionPage wraps an ActivityStreamsCollectionPage in a standardised collection page interface.
|
||||
func WrapCollectionPage(page vocab.ActivityStreamsCollectionPage) CollectionPageIterator {
|
||||
return ®ularCollectionPageIterator{ActivityStreamsCollectionPage: page}
|
||||
@@ -51,6 +79,90 @@ func WrapOrderedCollectionPage(page vocab.ActivityStreamsOrderedCollectionPage)
|
||||
return &orderedCollectionPageIterator{ActivityStreamsOrderedCollectionPage: page}
|
||||
}
|
||||
|
||||
// regularCollectionIterator implements CollectionIterator
|
||||
// for the vocab.ActivitiyStreamsCollection type.
|
||||
type regularCollectionIterator struct {
|
||||
vocab.ActivityStreamsCollection
|
||||
items vocab.ActivityStreamsItemsPropertyIterator
|
||||
once bool // only init items once
|
||||
}
|
||||
|
||||
func (iter *regularCollectionIterator) NextItem() TypeOrIRI {
|
||||
if !iter.initItems() {
|
||||
return nil
|
||||
}
|
||||
cur := iter.items
|
||||
iter.items = iter.items.Next()
|
||||
return cur
|
||||
}
|
||||
|
||||
func (iter *regularCollectionIterator) PrevItem() TypeOrIRI {
|
||||
if !iter.initItems() {
|
||||
return nil
|
||||
}
|
||||
cur := iter.items
|
||||
iter.items = iter.items.Prev()
|
||||
return cur
|
||||
}
|
||||
|
||||
func (iter *regularCollectionIterator) initItems() bool {
|
||||
if iter.once {
|
||||
return (iter.items != nil)
|
||||
}
|
||||
iter.once = true
|
||||
if iter.ActivityStreamsCollection == nil {
|
||||
return false // no page set
|
||||
}
|
||||
items := iter.GetActivityStreamsItems()
|
||||
if items == nil {
|
||||
return false // no items found
|
||||
}
|
||||
iter.items = items.Begin()
|
||||
return (iter.items != nil)
|
||||
}
|
||||
|
||||
// orderedCollectionIterator implements CollectionIterator
|
||||
// for the vocab.ActivitiyStreamsOrderedCollection type.
|
||||
type orderedCollectionIterator struct {
|
||||
vocab.ActivityStreamsOrderedCollection
|
||||
items vocab.ActivityStreamsOrderedItemsPropertyIterator
|
||||
once bool // only init items once
|
||||
}
|
||||
|
||||
func (iter *orderedCollectionIterator) NextItem() TypeOrIRI {
|
||||
if !iter.initItems() {
|
||||
return nil
|
||||
}
|
||||
cur := iter.items
|
||||
iter.items = iter.items.Next()
|
||||
return cur
|
||||
}
|
||||
|
||||
func (iter *orderedCollectionIterator) PrevItem() TypeOrIRI {
|
||||
if !iter.initItems() {
|
||||
return nil
|
||||
}
|
||||
cur := iter.items
|
||||
iter.items = iter.items.Prev()
|
||||
return cur
|
||||
}
|
||||
|
||||
func (iter *orderedCollectionIterator) initItems() bool {
|
||||
if iter.once {
|
||||
return (iter.items != nil)
|
||||
}
|
||||
iter.once = true
|
||||
if iter.ActivityStreamsOrderedCollection == nil {
|
||||
return false // no page set
|
||||
}
|
||||
items := iter.GetActivityStreamsOrderedItems()
|
||||
if items == nil {
|
||||
return false // no items found
|
||||
}
|
||||
iter.items = items.Begin()
|
||||
return (iter.items != nil)
|
||||
}
|
||||
|
||||
// regularCollectionPageIterator implements CollectionPageIterator
|
||||
// for the vocab.ActivitiyStreamsCollectionPage type.
|
||||
type regularCollectionPageIterator struct {
|
||||
|
Reference in New Issue
Block a user