[bugfix] add so, many, nil, checks (#853)

* add so, many, nil, checks.

* remove comment
This commit is contained in:
kim 2022-09-26 09:14:36 +01:00 committed by GitHub
parent 82061b1202
commit 7bea107608
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -208,27 +208,39 @@ stackLoop:
// Look for an attached status replies (as collection) // Look for an attached status replies (as collection)
replies := current.statusable.GetActivityStreamsReplies() replies := current.statusable.GetActivityStreamsReplies()
if replies == nil || !replies.IsActivityStreamsCollection() { if replies == nil {
continue stackLoop continue stackLoop
} }
// Get the status replies collection // Get the status replies collection
collection := replies.GetActivityStreamsCollection() collection := replies.GetActivityStreamsCollection()
if collection == nil {
continue stackLoop
}
// Get the "first" property of the replies collection // Get the "first" property of the replies collection
first := collection.GetActivityStreamsFirst() first := collection.GetActivityStreamsFirst()
if first == nil || !first.IsActivityStreamsCollectionPage() { if first == nil {
continue stackLoop continue stackLoop
} }
// Set the first activity stream collection page // Set the first activity stream collection page
current.page = first.GetActivityStreamsCollectionPage() current.page = first.GetActivityStreamsCollectionPage()
if current.page == nil {
continue stackLoop
}
} }
for /* page loop */ { pageLoop:
for {
if current.itemIter == nil { if current.itemIter == nil {
// Check this page contains any items... // Get the items associated with this page
items := current.page.GetActivityStreamsItems() items := current.page.GetActivityStreamsItems()
if items == nil {
continue stackLoop
}
// Check this page contains any items...
if current.iterLen = items.Len(); current.iterLen == 0 { if current.iterLen = items.Len(); current.iterLen == 0 {
continue stackLoop continue stackLoop
} }
@ -245,15 +257,12 @@ stackLoop:
// Get next item iterator object // Get next item iterator object
current.itemIter = current.itemIter.Next() current.itemIter = current.itemIter.Next()
switch { if iri := current.itemIter.GetIRI(); iri != nil {
// Item is already an IRI // Item is already an IRI type
case current.itemIter.IsIRI(): itemIRI = iri
itemIRI = current.itemIter.GetIRI() } else if note := current.itemIter.GetActivityStreamsNote(); note != nil {
// Item is a note, fetch the note ID IRI
// Item is a note, get the note ID IRI if id := note.GetJSONLDId(); id != nil {
case current.itemIter.IsActivityStreamsNote():
note := current.itemIter.GetActivityStreamsNote()
if id := note.GetJSONLDId(); id != nil && id.IsIRI() {
itemIRI = id.GetIRI() itemIRI = id.GetIRI()
} }
} }
@ -297,12 +306,15 @@ stackLoop:
// Get the current page's "next" property // Get the current page's "next" property
pageNext := current.page.GetActivityStreamsNext() pageNext := current.page.GetActivityStreamsNext()
if pageNext == nil || !pageNext.IsIRI() { if pageNext == nil {
continue stackLoop continue stackLoop
} }
// Get the "next" page property IRI // Get the "next" page property IRI
pageNextIRI := pageNext.GetIRI() pageNextIRI := pageNext.GetIRI()
if pageNextIRI == nil {
continue stackLoop
}
// Dereference this next collection page by its IRI // Dereference this next collection page by its IRI
collectionPage, err := d.DereferenceCollectionPage(ctx, username, pageNextIRI) collectionPage, err := d.DereferenceCollectionPage(ctx, username, pageNextIRI)
@ -313,6 +325,7 @@ stackLoop:
// Set the updated collection page // Set the updated collection page
current.page = collectionPage current.page = collectionPage
continue pageLoop
} }
} }