Skip to content

Commit 2b7af3f

Browse files
authored
Merge pull request #214 from Hirobreak/linking2
Linking Stage 2
2 parents 949a24f + 08fc1e1 commit 2b7af3f

File tree

63 files changed

+1793
-472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1793
-472
lines changed

Cartfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ github "hackiftekhar/IQKeyboardManager"
1717
github "Criptext/UIImageView-Letters" ~> 1.1.5
1818
github "ephread/Instructions" ~> 1.2.0
1919
github "malcommac/UIWindowTransitions"
20-
github "airbnb/lottie-ios" "master"
20+
github "airbnb/lottie-ios" "master"
21+
github "1024jp/GzipSwift"

Cartfile.resolved

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github "1024jp/GzipSwift" "4.0.4"
12
github "Alamofire/Alamofire" "4.7.3"
23
github "CosmicMind/Material" "2.16.4"
34
github "CosmicMind/Motion" "1.4.3"

iOS-Email-Client.xcodeproj/project.pbxproj

Lines changed: 34 additions & 8 deletions
Large diffs are not rendered by default.

iOS-Email-Client/AppDelegate.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
138138
UIApplication.shared.registerUserNotificationSettings(settings)
139139
}
140140

141-
let linkAccept = UNNotificationAction(identifier: "LINK_ACCEPT", title: "Approve", options: .authenticationRequired)
142-
let linkDeny = UNNotificationAction(identifier: "LINK_DENY", title: "Deny", options: .destructive)
141+
let linkAccept = UNNotificationAction(identifier: "LINK_ACCEPT", title: "Approve", options: .foreground)
142+
let linkDeny = UNNotificationAction(identifier: "LINK_DENY", title: "Reject", options: .destructive)
143143
let linkCategory = UNNotificationCategory(identifier: "LINK_DEVICE", actions: [linkAccept, linkDeny], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: "", options: .customDismissAction)
144144
let notificationCenter = UNUserNotificationCenter.current()
145145
notificationCenter.setNotificationCategories([linkCategory])
@@ -197,15 +197,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
197197
return snackbarController
198198
}
199199

200-
func createSystemLabels(){
201-
for systemLabel in SystemLabel.array {
202-
let newLabel = Label(systemLabel.description)
203-
newLabel.id = systemLabel.id
204-
newLabel.color = systemLabel.hexColor
205-
newLabel.type = "system"
206-
DBManager.store(newLabel)
207-
}
208-
}
200+
209201

210202
func applicationWillResignActive(_ application: UIApplication) {
211203
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
@@ -222,6 +214,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
222214
func applicationWillEnterForeground(_ application: UIApplication) {
223215
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
224216
self.triggerRefresh()
217+
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
225218
}
226219

227220
func triggerRefresh(){
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "deviceAlert.png",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"filename" : "deviceAlert@2x.png",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "universal",
15+
"filename" : "deviceAlert@3x.png",
16+
"scale" : "3x"
17+
}
18+
],
19+
"info" : {
20+
"version" : 1,
21+
"author" : "xcode"
22+
}
23+
}
1.1 KB
Loading
2.35 KB
Loading
3.79 KB
Loading

iOS-Email-Client/AsyncTasks/CreateCustomJSONFileAsyncTask.swift

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import RealmSwift
1313
class CreateCustomJSONFileAsyncTask {
1414

1515
let fileURL = CriptextFileManager.getURLForFile(name: "link-device-db")
16+
var contacts = [String: Int]()
17+
var emails = [Int: Int]()
1618

1719
func start(completion: @escaping ((Error?, URL?) -> Void)){
1820
try? FileManager.default.removeItem(at: fileURL)
@@ -23,39 +25,51 @@ class CreateCustomJSONFileAsyncTask {
2325

2426
private func createDBFile(completion: @escaping ((Error?, URL?) -> Void)){
2527
let results = DBManager.retrieveWholeDB()
26-
(results["contacts"] as! Results<Contact>).forEach {handleRow($0)}
27-
(results["labels"] as! Results<Label>).forEach {handleRow($0)}
28-
let emails = results["emails"] as! Results<Email>
29-
emails.forEach {handleRow($0)}
30-
emails.forEach { (email) in
31-
email.toDictionaryLabels().forEach({ (emailLabelDictionary) in
28+
results.contacts.enumerated().forEach {
29+
contacts[$1.email] = $0 + 1
30+
let dictionary = $1.toDictionary(id: $0 + 1)
31+
handleRow(dictionary)
32+
}
33+
results.labels.forEach {handleRow($0.toDictionary())}
34+
results.emails.enumerated().forEach {
35+
emails[$1.key] = $0 + 1
36+
let dictionary = $1.toDictionary(id: $0 + 1)
37+
handleRow(dictionary)
38+
}
39+
results.emails.forEach { (email) in
40+
email.toDictionaryLabels(emailsMap: emails).forEach({ (emailLabelDictionary) in
3241
guard let jsonString = Utils.convertToJSONString(dictionary: emailLabelDictionary) else {
3342
return
3443
}
3544
writeRowToFile(jsonRow: jsonString)
3645
})
3746
}
38-
(results["emailContacts"] as! Results<EmailContact>).forEach {handleRow($0)}
39-
(results["files"] as! Results<File>).forEach {handleRow($0)}
40-
let fileKeys = results["fileKeys"] as! Results<FileKey>
41-
fileKeys.forEach { (fileKey) in
42-
guard fileKey != fileKeys.last else {
43-
handleRow(fileKey, appendNewLine: false)
47+
results.emailContacts.enumerated().forEach {
48+
guard let emailId = emails[$1.email.key] else {
49+
return
50+
}
51+
handleRow($1.toDictionary(id: $0 + 1, emailId: emailId, contactId: contacts[$1.contact.email]!))
52+
}
53+
results.files.forEach {
54+
guard let emailId = emails[$0.emailId] else {
4455
return
4556
}
46-
handleRow(fileKey)
57+
handleRow($0.toDictionary(emailId: emailId))
58+
}
59+
results.fileKeys.forEach {
60+
guard let emailId = emails[$0.emailId] else {
61+
return
62+
}
63+
handleRow($0.toDictionary(emailId: emailId))
4764
}
4865

4966
DispatchQueue.main.async {
5067
completion(nil, self.fileURL)
5168
}
5269
}
5370

54-
private func handleRow(_ row: Any, appendNewLine: Bool = true){
55-
guard let item = row as? CustomDictionary else {
56-
return
57-
}
58-
guard let jsonString = Utils.convertToJSONString(dictionary: item.toDictionary()) else {
71+
private func handleRow(_ row: [String: Any], appendNewLine: Bool = true){
72+
guard let jsonString = Utils.convertToJSONString(dictionary: row) else {
5973
return
6074
}
6175
writeRowToFile(jsonRow: jsonString, appendNewLine: appendNewLine)

iOS-Email-Client/AsyncTasks/SendMailAsyncTask.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ class SendMailAsyncTask {
221221
requestParams["threadId"] = thread
222222
}
223223
APIManager.postMailRequest(requestParams, token: myAccount.jwt, queue: queue) { responseData in
224+
if case .TooManyRequests = responseData {
225+
DispatchQueue.main.async {
226+
self.setEmailAsFailed()
227+
completion(ResponseData.Error(CriptextError(message: "Failed to send e-mail. Email cap reached. It will be sent later.")))
228+
}
229+
return
230+
}
224231
guard case let .SuccessDictionary(updateData) = responseData else {
225232
DispatchQueue.main.async {
226233
self.setEmailAsFailed()

0 commit comments

Comments
 (0)