diff options
author | 2022-09-26 09:14:36 +0100 | |
---|---|---|
committer | 2022-09-26 10:14:36 +0200 | |
commit | 7bea1076086418198280a66e35b55277edc90ee6 (patch) | |
tree | aef97ec1cbc2205be056acbf42912382d3599ed9 /internal/federation/dereferencing/thread.go | |
parent | [bugfix] panic during child thread iteration (#852) (diff) | |
download | gotosocial-7bea1076086418198280a66e35b55277edc90ee6.tar.xz |
[bugfix] add so, many, nil, checks (#853)
* add so, many, nil, checks.
* remove comment
Diffstat (limited to 'internal/federation/dereferencing/thread.go')
-rw-r--r-- | internal/federation/dereferencing/thread.go | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go index 7626454a6..c0a758ee3 100644 --- a/internal/federation/dereferencing/thread.go +++ b/internal/federation/dereferencing/thread.go @@ -208,27 +208,39 @@ stackLoop: // Look for an attached status replies (as collection) replies := current.statusable.GetActivityStreamsReplies() - if replies == nil || !replies.IsActivityStreamsCollection() { + if replies == nil { continue stackLoop } // Get the status replies collection collection := replies.GetActivityStreamsCollection() + if collection == nil { + continue stackLoop + } // Get the "first" property of the replies collection first := collection.GetActivityStreamsFirst() - if first == nil || !first.IsActivityStreamsCollectionPage() { + if first == nil { continue stackLoop } // Set the first activity stream collection page current.page = first.GetActivityStreamsCollectionPage() + if current.page == nil { + continue stackLoop + } } - for /* page loop */ { + pageLoop: + for { if current.itemIter == nil { - // Check this page contains any items... + // Get the items associated with this page items := current.page.GetActivityStreamsItems() + if items == nil { + continue stackLoop + } + + // Check this page contains any items... if current.iterLen = items.Len(); current.iterLen == 0 { continue stackLoop } @@ -245,15 +257,12 @@ stackLoop: // Get next item iterator object current.itemIter = current.itemIter.Next() - switch { - // Item is already an IRI - case current.itemIter.IsIRI(): - itemIRI = current.itemIter.GetIRI() - - // Item is a note, get the note ID IRI - case current.itemIter.IsActivityStreamsNote(): - note := current.itemIter.GetActivityStreamsNote() - if id := note.GetJSONLDId(); id != nil && id.IsIRI() { + if iri := current.itemIter.GetIRI(); iri != nil { + // Item is already an IRI type + itemIRI = iri + } else if note := current.itemIter.GetActivityStreamsNote(); note != nil { + // Item is a note, fetch the note ID IRI + if id := note.GetJSONLDId(); id != nil { itemIRI = id.GetIRI() } } @@ -297,12 +306,15 @@ stackLoop: // Get the current page's "next" property pageNext := current.page.GetActivityStreamsNext() - if pageNext == nil || !pageNext.IsIRI() { + if pageNext == nil { continue stackLoop } // Get the "next" page property IRI pageNextIRI := pageNext.GetIRI() + if pageNextIRI == nil { + continue stackLoop + } // Dereference this next collection page by its IRI collectionPage, err := d.DereferenceCollectionPage(ctx, username, pageNextIRI) @@ -313,6 +325,7 @@ stackLoop: // Set the updated collection page current.page = collectionPage + continue pageLoop } } |