Skip to content

Commit

Permalink
deleteSubscriptionNode done
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Jun 22, 2022
1 parent bc43955 commit 26abc08
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
24 changes: 24 additions & 0 deletions PotatsoModel/DBUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,30 @@ open class DBUtils {
// Query
extension DBUtils {

public static func deleteSubscriptionNode(_ node: ProxyNode, completion:((Bool, Error?)->Void)? = nil) {
sharedQueueForRealm.async {
var success = false
var err:Error?
do {
try DBUtils.softDelete(node.uuid, type: ProxyNode.self)
let allNodes: [ProxyNode?] = allNotDeleted(ProxyNode.self, sorted: "createAt").map({ $0 })
let subNodes = allNodes.filter { item in
item?.sourceUuid == node.uuid
}
for node2 in subNodes {
guard let node2 = node2 else {
continue
}
try DBUtils.softDelete(node2.uuid, type: ProxyNode.self)
}
success = true
} catch {
err = error
}
completion?(success, err)
}
}

public static func refreshSubscriptions(_ completion:((Bool)->Void)? = nil) {
sharedQueueForRealm.async {
var success = false
Expand Down
21 changes: 21 additions & 0 deletions iShadowsocksR/ProxyListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class ProxyListViewController: FormViewController {
guard indexPath.row < self.proxyNodes.count, let node = (self.form[indexPath] as? ProxyNodeRow)?.value else {
return
}

if node.type == .Subscription {
self.deleteSubscriptionNode(node)
return
}

do {
try DBUtils.softDelete(node.uuid, type: ProxyNode.self)
self.proxyNodes.remove(at: indexPath.row)
Expand Down Expand Up @@ -242,6 +248,21 @@ class ProxyListViewController: FormViewController {
return ac
}

func deleteSubscriptionNode(_ node:ProxyNode) {
self.showProgreeHUD("Delete subscription node...".localized())
DBUtils.deleteSubscriptionNode(node) { success, error in
Async.main(after: 0.1) {
self.hideHUD()
if !success {
Alert.show(self, message: "Fail to delete node".localized())
} else {
self.showTextHUD("Delete node successfully".localized(), dismissAfterDelay: 1.5)
}
self.reloadData()
}
}
}

func parseSubscriptions() {
self.showProgreeHUD("Refresh subscription nodes...".localized())
DBUtils.refreshSubscriptions { success in
Expand Down

0 comments on commit 26abc08

Please sign in to comment.