我一直在嘗試從帖子中刪除帖子,當帖子獲取2個以上的標誌時。我嘗試了很多方法,但無法弄清楚。我有一些圖片附加幫助將不勝感激! '在標記帖子時從firebase中刪除孩子
// 4
if poster.uid != User.current.uid {
let flagAction = UIAlertAction(title: "Report as Inappropriate", style: .default) { _ in
PostService.flag(post)
/// addedflag
let flaggedPostRef = Database.database().reference().child("flaggedPosts").child(postKey!)
// 3
var flaggedDict = ["text": post.textData,
"poster_uid": post.poster.uid,
"reporter_uid": User.current.uid]
// 4
flaggedPostRef.updateChildValues(flaggedDict)
// 5
let flagCountRef = flaggedPostRef.child("flag_count")
flagCountRef.runTransactionBlock({ (mutableData) -> TransactionResult in
let currentCount = mutableData.value as? Int ?? 0
mutableData.value = currentCount
if mutableData.value as! Int >= 1 {
let uid = FIRAuth.auth()!.poster.uid!.uid
// Remove the post from the DB
ref.child("posts").child(postKey).removeValue { error in
if error != nil {
print("error \(error)")
}
}
postKey?.removeVolue()
let timelinePostDict = ["poster_uid" : poster.uid]
var updatedData: [String : Any] = ["timeline/\(poster.uid)/\(postKey)" : timelinePostDict]
let postToBeDeleted = Database.database().reference().child("posts")
updatedData["timeline/\(poster.uid)/\(postKey)"] = timelinePostDict
updatedData["posts/\(poster.uid)/\(postKey)"] = postKey
print("Delete case: mutableData.value = \(mutableData.value)")
} else {
print("Case not met. Either not equal to 2 or not able to cast as Integer type. The value of the casted in is \(mutableData.value as? Int)")
}
mutableData.value = currentCount + 1
return TransactionResult.success(withValue: mutableData)
})
擴展flaging的代碼在這裏,我無法發佈它。 –
這是一個有趣的問題....我最近一直在使用firebase,這是一個很好的問題!讓我們來看看,在我想了解一下之後,我是否可以在這裏向你提出一個想法。 – archae0pteryx
你的標誌位置在firebase的哪裏,顯示圖像也是如何將標誌保存在firebase中? – 3stud1ant3