Advertisement
Dillon25

Untitled

Jul 13th, 2020
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.43 KB | None | 0 0
  1. //CommentViewController
  2. func sendSubComment() {
  3.         if let text = textView.text,
  4.         let username = self.username,
  5.         let user_picture = profile?.picture,
  6.         let user_id = profile?.sub,
  7.         let parent_id = parent_id {
  8.             let comment = Comment(post_id: "2d44a588-e47a-43c5-bd16-94e7073e4e14", username: username, user_picture: user_picture.absoluteString, user_id: user_id, text: text, parent_id: parent_id)
  9.  
  10.             let postRequest = CommentPostRequest(endpoint: "sub_comment")
  11.             postRequest.save(comment) { (result) in
  12.                 switch result {
  13.                 case .success(let comment):                
  14.                     self.delegate2?.didSendSubComment()
  15.              
  16.                 case .failure(let error):
  17.                     print("An error occurred: \(error)")
  18.                 }
  19.             }
  20.         }
  21.     }
  22.  
  23. //CommentCell
  24. extension CommentCell: TableViewDelegate {
  25.     func didSendSubComment() {
  26.         if let id = parent_id {
  27.         viewModel?.loadSubCommentsAfterReply(comment_id: id)
  28.         }
  29.     }
  30. }
  31.  
  32. //CommentViewModel
  33. func loadSubCommentsAfterReply(comment_id:String?) {
  34.         if let id = comment_id {
  35.         let getSubComments = GETSubComments(id: id, path: "subComments", offset: "0")
  36.             getSubComments.getAllById {
  37.                    self.subComments += $0
  38.                    self.subCommentDidInserts?($0)
  39.         }
  40.       }
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement