Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum PostType: String {
- case image = "image"
- case gif = "gif"
- case video = "video"
- case text = "text"
- case link = "link"
- case audio = "audio"
- case poll = "poll"
- case chat = "chat"
- case quote = "quote"
- }
- func loadPosts() {
- activityIndicator.startAnimating()
- Api.Feed.observeFeedPosts(withUserId: Api.Users.CURRENT_USER!.uid) {
- post in
- guard let userId = post.userUid else { return }
- self.fetchUser(uid: userId, completed: {
- self.posts.insert(post, at: 0)
- self.activityIndicator.stopAnimating()
- self.collectionView.reloadData()
- })
- }
- Api.Feed.observeFeedRemoved(withUserId: Api.Users.CURRENT_USER!.uid) { (post) in
- self.posts = self.posts.filter { $0.id != post.id } // removed all array elements matching the key
- self.users = self.users.filter { $0.id != post.userUid }
- self.collectionView.reloadData()
- }
- }
- func fetchUser(uid: String, completed: @escaping () -> Void ) {
- Api.Users.observeUsersShort(withId: uid) {
- user in
- self.users.insert(user, at: 0)
- completed()
- }
- }
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return posts.count
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CellName.postTextCVC, for: indexPath) as! PostTextCVC
- let user = users[indexPath.row]
- let post = posts[indexPath.row]
- cell.delegatePostTextCVC = self
- cell.user = user
- cell.dashboardVC = self
- cell.post = post
- return cell
- }
Add Comment
Please, Sign In to add comment