Skip to content

Commit 32e2ceb

Browse files
committed
Always consider highest subscription tier
1 parent 95565c0 commit 32e2ceb

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Client.swift

+32-1
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,39 @@ class Client {
128128
URLSession.shared.dataTask(.promise, with: try makePostRequest(urlString: mainURL + "/active-subscriptions", parameters: [:]))
129129
}.map { data, response -> [Subscription] in
130130
try self.validateApiResponse(data: data, response: response)
131-
let subscriptions = try JSONDecoder().decode([Subscription].self, from: data)
131+
var subscriptions = try JSONDecoder().decode([Subscription].self, from: data)
132132
DDLogInfo("API RESULT: active-subscriptions: \(subscriptions)")
133+
// sort subscriptions with highest tier at the top
134+
subscriptions.sort(by: { (sub1: Subscription, sub2: Subscription) -> Bool in
135+
if (sub1.planType == .proAnnual) {
136+
return true
137+
}
138+
else if (sub1.planType == .proMonthly) {
139+
if (sub2.planType == .proAnnual) {
140+
return false
141+
}
142+
else {
143+
return true
144+
}
145+
}
146+
else if (sub1.planType == .annual) {
147+
if (sub2.planType == .proAnnual || sub2.planType == .proMonthly) {
148+
return false
149+
}
150+
else {
151+
return true
152+
}
153+
}
154+
else {
155+
if (sub2.planType == .proAnnual || sub2.planType == .proMonthly || sub2.planType == .annual) {
156+
return false
157+
}
158+
else {
159+
return true
160+
}
161+
}
162+
})
163+
DDLogInfo("API RESULT: sorted-active-subscriptions: \(subscriptions)")
133164
return subscriptions
134165
}
135166
}

0 commit comments

Comments
 (0)