func loadPost()

in FriendlyPix/FPFeedViewController.swift [508:533]


  func loadPost(_ postSnapshot: DataSnapshot) {
    if appDelegate.isBlocked(postSnapshot) {
      loadingPostCount -= 1
      return
    }
    let postId = postSnapshot.key
    commentsRef.child(postId).observeSingleEvent(of: .value, with: { commentsSnapshot in
      var commentsArray = [FPComment]()
      let enumerator = commentsSnapshot.children
      while let commentSnapshot = enumerator.nextObject() as? DataSnapshot {
        if !self.appDelegate.isBlocked(commentSnapshot) {
          let comment = FPComment(snapshot: commentSnapshot)
          commentsArray.append(comment)
        }
      }
      self.likesRef.child(postId).observeSingleEvent(of: .value, with: { snapshot in
        let likes = snapshot.value as? [String: Any]
        let post = FPPost(snapshot: postSnapshot, andComments: commentsArray, andLikes: likes)
        self.posts.append(post)
        let last = self.posts.count - 1
        let lastIndex = [IndexPath(item: last, section: 0)]
        self.listenPost(post)
        self.collectionView?.insertItems(at: lastIndex)
      })
    })
  }