|
@@ -238,10 +238,15 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
if isContactCenter && !isRequestContactCenter && !onGoingCC {
|
|
|
var companyName = ""
|
|
|
Database.shared.database?.inTransaction({ fmdb, rollback in
|
|
|
- if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT first_name, last_name FROM BUDDY where official_account = '1'"), cursor.next() {
|
|
|
- companyName = cursor.string(forColumnIndex: 0)! + " " + cursor.string(forColumnIndex: 1)!
|
|
|
- companyName = companyName.trimmingCharacters(in: .whitespaces)
|
|
|
- cursor.close()
|
|
|
+ do {
|
|
|
+ if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "SELECT first_name, last_name FROM BUDDY where official_account = '1'"), cursor.next() {
|
|
|
+ companyName = cursor.string(forColumnIndex: 0)! + " " + cursor.string(forColumnIndex: 1)!
|
|
|
+ companyName = companyName.trimmingCharacters(in: .whitespaces)
|
|
|
+ cursor.close()
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
self.dateStartCC = "\(Date().currentTimeMillis())"
|
|
@@ -298,15 +303,20 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
alert.addAction(UIAlertAction(title: "Cancel".localized(), style: UIAlertAction.Style.default, handler: nil))
|
|
|
alert.addAction(UIAlertAction(title: "Delete".localized(), style: .destructive, handler: {(_) in
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
|
|
|
- _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
|
|
|
- let l_pin = self.dataPerson["f_pin"]!!
|
|
|
- SecureUserDefaults.shared.removeValue(forKey: "saved_\(l_pin)")
|
|
|
- NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
|
|
|
- if self.fromNotification {
|
|
|
- self.didTapExit()
|
|
|
- } else {
|
|
|
- self.navigationController?.popViewController(animated: true)
|
|
|
+ do {
|
|
|
+ _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE", _where: "(f_pin='\(self.dataPerson["f_pin"]!!)' or l_pin='\(self.dataPerson["f_pin"]!!)') and (message_scope_id='3' or message_scope_id='18') and is_call_center = 0")
|
|
|
+ _ = Database.shared.deleteRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", _where: "l_pin='\(self.dataPerson["f_pin"]!!)'")
|
|
|
+ let l_pin = self.dataPerson["f_pin"]!!
|
|
|
+ SecureUserDefaults.shared.removeValue(forKey: "saved_\(l_pin)")
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
|
|
|
+ if self.fromNotification {
|
|
|
+ self.didTapExit()
|
|
|
+ } else {
|
|
|
+ self.navigationController?.popViewController(animated: true)
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
}))
|
|
@@ -346,9 +356,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
} else {
|
|
|
DispatchQueue.main.async { [self] in
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: [
|
|
|
- "ex_block" : "0"
|
|
|
- ], _where: "f_pin = '\(self.dataPerson["f_pin"]!!)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: [
|
|
|
+ "ex_block" : "0"
|
|
|
+ ], _where: "f_pin = '\(self.dataPerson["f_pin"]!!)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
containerAction.subviews.forEach({ $0.removeFromSuperview() })
|
|
|
containerAction.removeFromSuperview()
|
|
@@ -381,9 +396,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
} else {
|
|
|
DispatchQueue.main.async { [self] in
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: [
|
|
|
- "ex_block" : "1"
|
|
|
- ], _where: "f_pin = '\(self.dataPerson["f_pin"]!!)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "BUDDY", cvalues: [
|
|
|
+ "ex_block" : "1"
|
|
|
+ ], _where: "f_pin = '\(self.dataPerson["f_pin"]!!)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
setRightButtonItem()
|
|
|
changeAppBar()
|
|
@@ -586,9 +606,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
}
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "lock" : "2"
|
|
|
- ], _where: "message_id = '\(data.key)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "lock" : "2"
|
|
|
+ ], _where: "message_id = '\(data.key)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -780,27 +805,32 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
query = "SELECT group_id, f_name, official, image_id FROM GROUPZ where group_type = 1 AND official = 1"
|
|
|
}
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
|
|
|
- if cursorData.next() {
|
|
|
- dataPerson["f_pin"] = cursorData.string(forColumnIndex: 0)
|
|
|
- dataPerson["name"] = cursorData.string(forColumnIndex: 1)?.trimmingCharacters(in: .whitespaces)
|
|
|
- dataPerson["picture"] = cursorData.string(forColumnIndex: 3)
|
|
|
- dataPerson["isOfficial"] = cursorData.string(forColumnIndex: 2)
|
|
|
- if isContactCenter && isRequestContactCenter {
|
|
|
- dataPerson["user_type"] = "0"
|
|
|
+ do {
|
|
|
+ if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
|
|
|
+ if cursorData.next() {
|
|
|
+ dataPerson["f_pin"] = cursorData.string(forColumnIndex: 0)
|
|
|
+ dataPerson["name"] = cursorData.string(forColumnIndex: 1)?.trimmingCharacters(in: .whitespaces)
|
|
|
+ dataPerson["picture"] = cursorData.string(forColumnIndex: 3)
|
|
|
+ dataPerson["isOfficial"] = cursorData.string(forColumnIndex: 2)
|
|
|
+ if isContactCenter && isRequestContactCenter {
|
|
|
+ dataPerson["user_type"] = "0"
|
|
|
+ } else {
|
|
|
+ dataPerson["user_type"] = cursorData.string(forColumnIndex: 6)
|
|
|
+ }
|
|
|
} else {
|
|
|
- dataPerson["user_type"] = cursorData.string(forColumnIndex: 6)
|
|
|
+ dataPerson["f_pin"] = "-999"
|
|
|
+ dataPerson["name"] = "Bot"
|
|
|
+ dataPerson["picture"] = ""
|
|
|
+ dataPerson["isOfficial"] = ""
|
|
|
+ dataPerson["deviceId"] = ""
|
|
|
+ dataPerson["isOffline"] = "0"
|
|
|
+ dataPerson["user_type"] = "0"
|
|
|
}
|
|
|
- } else {
|
|
|
- dataPerson["f_pin"] = "-999"
|
|
|
- dataPerson["name"] = "Bot"
|
|
|
- dataPerson["picture"] = ""
|
|
|
- dataPerson["isOfficial"] = ""
|
|
|
- dataPerson["deviceId"] = ""
|
|
|
- dataPerson["isOffline"] = "0"
|
|
|
- dataPerson["user_type"] = "0"
|
|
|
+ cursorData.close()
|
|
|
}
|
|
|
- cursorData.close()
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -810,93 +840,80 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
let queryCount = "SELECT COUNT(*) FROM MESSAGE where (f_pin='\(dataPerson["f_pin"]!!)' or l_pin='\(dataPerson["f_pin"]!!)') AND (message_scope_id = '3' OR message_scope_id = '18') AND is_call_center = 0"
|
|
|
let query = "SELECT message_id, f_pin, l_pin, message_scope_id, server_date, status, message_text, audio_id, video_id, image_id, thumb_id, read_receipts, chat_id, file_id, attachment_flag, reff_id, lock, is_stared, blog_id, credential, is_call_center, call_center_id, opposite_pin FROM MESSAGE where (f_pin='\(dataPerson["f_pin"]!!)' or l_pin='\(dataPerson["f_pin"]!!)') AND (message_scope_id = '3' OR message_scope_id = '18') AND is_call_center = 0 order by server_date asc LIMIT CASE WHEN (\(queryCount))-\(dataMessages.count)>=20 THEN 20*\(multipleOffsetUp-1) ELSE (\(queryCount))-\(dataMessages.count) END OFFSET CASE WHEN (\(queryCount))>=\(20*multipleOffsetUp) THEN (\(queryCount))-\(20*multipleOffsetUp) ELSE 0 END"
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
|
|
|
- var tempData: [[String: Any?]] = []
|
|
|
- while cursorData.next() {
|
|
|
- var row: [String: Any?] = [:]
|
|
|
- row["message_id"] = cursorData.string(forColumnIndex: 0)
|
|
|
- row["f_pin"] = cursorData.string(forColumnIndex: 1)
|
|
|
- row["l_pin"] = cursorData.string(forColumnIndex: 2)
|
|
|
- row["message_scope_id"] = cursorData.string(forColumnIndex: 3)
|
|
|
- row["server_date"] = cursorData.string(forColumnIndex: 4)
|
|
|
- row["status"] = cursorData.string(forColumnIndex: 5)
|
|
|
- row["message_text"] = cursorData.string(forColumnIndex: 6)
|
|
|
- row["audio_id"] = cursorData.string(forColumnIndex: 7)
|
|
|
- row["video_id"] = cursorData.string(forColumnIndex: 8)
|
|
|
- row["image_id"] = cursorData.string(forColumnIndex: 9)
|
|
|
- row["thumb_id"] = cursorData.string(forColumnIndex: 10)
|
|
|
- row["read_receipts"] = cursorData.string(forColumnIndex: 11)
|
|
|
- row["chat_id"] = cursorData.string(forColumnIndex: 12)
|
|
|
- row["file_id"] = cursorData.string(forColumnIndex: 13)
|
|
|
- row["attachment_flag"] = cursorData.string(forColumnIndex: 14)
|
|
|
- row["reff_id"] = cursorData.string(forColumnIndex: 15)
|
|
|
- row["lock"] = cursorData.string(forColumnIndex: 16)
|
|
|
- row["is_stared"] = cursorData.string(forColumnIndex: 17)
|
|
|
- row["blog_id"] = cursorData.string(forColumnIndex: 18)
|
|
|
- row["credential"] = cursorData.string(forColumnIndex: 19)
|
|
|
- row[TypeDataMessage.is_call_center] = cursorData.string(forColumnIndex: 20)
|
|
|
- row[TypeDataMessage.call_center_id] = cursorData.string(forColumnIndex: 21)
|
|
|
- row[TypeDataMessage.opposite_pin] = cursorData.string(forColumnIndex: 22)
|
|
|
- if let cursorStatus = Database.shared.getRecords(fmdb: fmdb, query: "SELECT status FROM MESSAGE_STATUS WHERE message_id='\(row["message_id"] as! String)'") {
|
|
|
- while cursorStatus.next() {
|
|
|
- row["status"] = cursorStatus.string(forColumnIndex: 0)
|
|
|
- }
|
|
|
- cursorStatus.close()
|
|
|
- }
|
|
|
- let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
- let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
- let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
|
- if let dirPath = paths.first {
|
|
|
- let videoURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["video_id"] as! String)
|
|
|
- let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["file_id"] as! String)
|
|
|
- if ((row["video_id"] as! String) != "") {
|
|
|
- if FileManager.default.fileExists(atPath: videoURL.path){
|
|
|
- row["progress"] = 100.0
|
|
|
- } else {
|
|
|
- row["progress"] = 0.0
|
|
|
- }
|
|
|
- } else {
|
|
|
- if FileManager.default.fileExists(atPath: fileURL.path){
|
|
|
- row["progress"] = 100.0
|
|
|
- } else {
|
|
|
- row["progress"] = 0.0
|
|
|
+ do {
|
|
|
+ if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
|
|
|
+ var tempData: [[String: Any?]] = []
|
|
|
+ while cursorData.next() {
|
|
|
+ var row: [String: Any?] = [:]
|
|
|
+ row["message_id"] = cursorData.string(forColumnIndex: 0)
|
|
|
+ row["f_pin"] = cursorData.string(forColumnIndex: 1)
|
|
|
+ row["l_pin"] = cursorData.string(forColumnIndex: 2)
|
|
|
+ row["message_scope_id"] = cursorData.string(forColumnIndex: 3)
|
|
|
+ row["server_date"] = cursorData.string(forColumnIndex: 4)
|
|
|
+ row["status"] = cursorData.string(forColumnIndex: 5)
|
|
|
+ row["message_text"] = cursorData.string(forColumnIndex: 6)
|
|
|
+ row["audio_id"] = cursorData.string(forColumnIndex: 7)
|
|
|
+ row["video_id"] = cursorData.string(forColumnIndex: 8)
|
|
|
+ row["image_id"] = cursorData.string(forColumnIndex: 9)
|
|
|
+ row["thumb_id"] = cursorData.string(forColumnIndex: 10)
|
|
|
+ row["read_receipts"] = cursorData.string(forColumnIndex: 11)
|
|
|
+ row["chat_id"] = cursorData.string(forColumnIndex: 12)
|
|
|
+ row["file_id"] = cursorData.string(forColumnIndex: 13)
|
|
|
+ row["attachment_flag"] = cursorData.string(forColumnIndex: 14)
|
|
|
+ row["reff_id"] = cursorData.string(forColumnIndex: 15)
|
|
|
+ row["lock"] = cursorData.string(forColumnIndex: 16)
|
|
|
+ row["is_stared"] = cursorData.string(forColumnIndex: 17)
|
|
|
+ row["blog_id"] = cursorData.string(forColumnIndex: 18)
|
|
|
+ row["credential"] = cursorData.string(forColumnIndex: 19)
|
|
|
+ row[TypeDataMessage.is_call_center] = cursorData.string(forColumnIndex: 20)
|
|
|
+ row[TypeDataMessage.call_center_id] = cursorData.string(forColumnIndex: 21)
|
|
|
+ row[TypeDataMessage.opposite_pin] = cursorData.string(forColumnIndex: 22)
|
|
|
+ if let cursorStatus = Database.shared.getRecords(fmdb: fmdb, query: "SELECT status FROM MESSAGE_STATUS WHERE message_id='\(row["message_id"] as! String)'") {
|
|
|
+ while cursorStatus.next() {
|
|
|
+ row["status"] = cursorStatus.string(forColumnIndex: 0)
|
|
|
}
|
|
|
+ cursorStatus.close()
|
|
|
}
|
|
|
- }
|
|
|
- row["chat_date"] = chatDate(stringDate: row["server_date"] as! String)
|
|
|
- row["isSelected"] = false
|
|
|
- if row["credential"] != nil && row["credential"] as! String == "1" {
|
|
|
- let idMe = User.getMyPin()!
|
|
|
- if row["f_pin"] as! String == idMe {
|
|
|
- let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(row["server_date"] as! String)!), end: Date())
|
|
|
- if second > 60 {
|
|
|
- listTimerCredential[row["message_id"] as! String] = 0
|
|
|
- row["lock"] = "2"
|
|
|
- row["reff_id"] = ""
|
|
|
- DispatchQueue.global().async {
|
|
|
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "lock" : "2"
|
|
|
- ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
- })
|
|
|
+ let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
+ let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
+ let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
|
+ if let dirPath = paths.first {
|
|
|
+ let videoURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["video_id"] as! String)
|
|
|
+ let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["file_id"] as! String)
|
|
|
+ if ((row["video_id"] as! String) != "") {
|
|
|
+ if FileManager.default.fileExists(atPath: videoURL.path){
|
|
|
+ row["progress"] = 100.0
|
|
|
+ } else {
|
|
|
+ row["progress"] = 0.0
|
|
|
}
|
|
|
} else {
|
|
|
- let second = 60 - second
|
|
|
- listTimerCredential[row["message_id"] as! String] = second
|
|
|
+ if FileManager.default.fileExists(atPath: fileURL.path){
|
|
|
+ row["progress"] = 100.0
|
|
|
+ } else {
|
|
|
+ row["progress"] = 0.0
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- let hasMessageId: String? = SecureUserDefaults.shared.value(forKey: row["message_id"] as! String) ?? nil
|
|
|
- if hasMessageId != nil {
|
|
|
- let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(hasMessageId!)!), end: Date())
|
|
|
+ }
|
|
|
+ row["chat_date"] = chatDate(stringDate: row["server_date"] as! String)
|
|
|
+ row["isSelected"] = false
|
|
|
+ if row["credential"] != nil && row["credential"] as! String == "1" {
|
|
|
+ let idMe = User.getMyPin()!
|
|
|
+ if row["f_pin"] as! String == idMe {
|
|
|
+ let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(row["server_date"] as! String)!), end: Date())
|
|
|
if second > 60 {
|
|
|
listTimerCredential[row["message_id"] as! String] = 0
|
|
|
row["lock"] = "2"
|
|
|
row["reff_id"] = ""
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "lock" : "2"
|
|
|
- ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "lock" : "2"
|
|
|
+ ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
@@ -904,29 +921,57 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
listTimerCredential[row["message_id"] as! String] = second
|
|
|
}
|
|
|
} else {
|
|
|
- SecureUserDefaults.shared.set("\(Date().currentTimeMillis())", forKey: row["message_id"] as! String)
|
|
|
- listTimerCredential[row["message_id"] as! String] = 60
|
|
|
+ let hasMessageId: String? = SecureUserDefaults.shared.value(forKey: row["message_id"] as! String) ?? nil
|
|
|
+ if hasMessageId != nil {
|
|
|
+ let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(hasMessageId!)!), end: Date())
|
|
|
+ if second > 60 {
|
|
|
+ listTimerCredential[row["message_id"] as! String] = 0
|
|
|
+ row["lock"] = "2"
|
|
|
+ row["reff_id"] = ""
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "lock" : "2"
|
|
|
+ ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let second = 60 - second
|
|
|
+ listTimerCredential[row["message_id"] as! String] = second
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SecureUserDefaults.shared.set("\(Date().currentTimeMillis())", forKey: row["message_id"] as! String)
|
|
|
+ listTimerCredential[row["message_id"] as! String] = 60
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- tempData.append(row)
|
|
|
- }
|
|
|
- if tempData.count != 0 && (dataMessages.firstIndex(where: { $0["message_id"] as? String == tempData[0]["message_id"] as? String }) == nil) {
|
|
|
- let lastIndex = tempData.count - 1
|
|
|
- for i in 0..<tempData.count {
|
|
|
- tableChatView.beginUpdates()
|
|
|
- dataMessages.insert(tempData[lastIndex - i], at: 0)
|
|
|
- if dataMessages.firstIndex(where: { $0["chat_date"] as? String == tempData[lastIndex - i]["chat_date"] as? String }) != nil {
|
|
|
- tableChatView.insertRows(at: [IndexPath(row: 0, section: currentIndexpath!.section)], with: .top)
|
|
|
- } else {
|
|
|
- tableChatView.insertSections(IndexSet(integer: 0), with: .top)
|
|
|
- tableChatView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .top)
|
|
|
+ tempData.append(row)
|
|
|
+ }
|
|
|
+ if tempData.count != 0 && (dataMessages.firstIndex(where: { $0["message_id"] as? String == tempData[0]["message_id"] as? String }) == nil) {
|
|
|
+ let lastIndex = tempData.count - 1
|
|
|
+ for i in 0..<tempData.count {
|
|
|
+ tableChatView.beginUpdates()
|
|
|
+ dataMessages.insert(tempData[lastIndex - i], at: 0)
|
|
|
+ if dataMessages.firstIndex(where: { $0["chat_date"] as? String == tempData[lastIndex - i]["chat_date"] as? String }) != nil {
|
|
|
+ tableChatView.insertRows(at: [IndexPath(row: 0, section: currentIndexpath!.section)], with: .top)
|
|
|
+ } else {
|
|
|
+ tableChatView.insertSections(IndexSet(integer: 0), with: .top)
|
|
|
+ tableChatView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .top)
|
|
|
+ }
|
|
|
+ tableChatView.endUpdates()
|
|
|
}
|
|
|
- tableChatView.endUpdates()
|
|
|
}
|
|
|
+ cursorData.close()
|
|
|
+ gettingDataMessage = false
|
|
|
}
|
|
|
- cursorData.close()
|
|
|
- gettingDataMessage = false
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -970,93 +1015,80 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
}
|
|
|
}
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
|
|
|
- var tempImages: [ImageGrouping] = []
|
|
|
- while cursorData.next() {
|
|
|
- var row: [String: Any?] = [:]
|
|
|
- row["message_id"] = cursorData.string(forColumnIndex: 0)
|
|
|
- row["f_pin"] = cursorData.string(forColumnIndex: 1)
|
|
|
- row["l_pin"] = cursorData.string(forColumnIndex: 2)
|
|
|
- row["message_scope_id"] = cursorData.string(forColumnIndex: 3)
|
|
|
- row["server_date"] = cursorData.string(forColumnIndex: 4)
|
|
|
- row["status"] = cursorData.string(forColumnIndex: 5)
|
|
|
- row["message_text"] = cursorData.string(forColumnIndex: 6)
|
|
|
- row["audio_id"] = cursorData.string(forColumnIndex: 7)
|
|
|
- row["video_id"] = cursorData.string(forColumnIndex: 8)
|
|
|
- row["image_id"] = cursorData.string(forColumnIndex: 9)
|
|
|
- row["thumb_id"] = cursorData.string(forColumnIndex: 10)
|
|
|
- row["read_receipts"] = cursorData.string(forColumnIndex: 11)
|
|
|
- row["chat_id"] = cursorData.string(forColumnIndex: 12)
|
|
|
- row["file_id"] = cursorData.string(forColumnIndex: 13)
|
|
|
- row["attachment_flag"] = cursorData.string(forColumnIndex: 14)
|
|
|
- row["reff_id"] = cursorData.string(forColumnIndex: 15)
|
|
|
- row["lock"] = cursorData.string(forColumnIndex: 16)
|
|
|
- row["is_stared"] = cursorData.string(forColumnIndex: 17)
|
|
|
- row["blog_id"] = cursorData.string(forColumnIndex: 18)
|
|
|
- row["credential"] = cursorData.string(forColumnIndex: 19)
|
|
|
- row[TypeDataMessage.is_call_center] = cursorData.string(forColumnIndex: 20)
|
|
|
- row[TypeDataMessage.call_center_id] = cursorData.string(forColumnIndex: 21)
|
|
|
- row[TypeDataMessage.opposite_pin] = cursorData.string(forColumnIndex: 22)
|
|
|
- if let cursorStatus = Database.shared.getRecords(fmdb: fmdb, query: "SELECT status FROM MESSAGE_STATUS WHERE message_id='\(row["message_id"] as! String)'") {
|
|
|
- while cursorStatus.next() {
|
|
|
- row["status"] = cursorStatus.string(forColumnIndex: 0)
|
|
|
- }
|
|
|
- cursorStatus.close()
|
|
|
- }
|
|
|
- let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
- let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
- let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
|
- if let dirPath = paths.first {
|
|
|
- let videoURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["video_id"] as! String)
|
|
|
- let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["file_id"] as! String)
|
|
|
- if ((row["video_id"] as! String) != "") {
|
|
|
- if FileManager.default.fileExists(atPath: videoURL.path){
|
|
|
- row["progress"] = 100.0
|
|
|
- } else {
|
|
|
- row["progress"] = 0.0
|
|
|
- }
|
|
|
- } else {
|
|
|
- if FileManager.default.fileExists(atPath: fileURL.path){
|
|
|
- row["progress"] = 100.0
|
|
|
- } else {
|
|
|
- row["progress"] = 0.0
|
|
|
+ do {
|
|
|
+ if let cursorData = Database.shared.getRecords(fmdb: fmdb, query: query) {
|
|
|
+ var tempImages: [ImageGrouping] = []
|
|
|
+ while cursorData.next() {
|
|
|
+ var row: [String: Any?] = [:]
|
|
|
+ row["message_id"] = cursorData.string(forColumnIndex: 0)
|
|
|
+ row["f_pin"] = cursorData.string(forColumnIndex: 1)
|
|
|
+ row["l_pin"] = cursorData.string(forColumnIndex: 2)
|
|
|
+ row["message_scope_id"] = cursorData.string(forColumnIndex: 3)
|
|
|
+ row["server_date"] = cursorData.string(forColumnIndex: 4)
|
|
|
+ row["status"] = cursorData.string(forColumnIndex: 5)
|
|
|
+ row["message_text"] = cursorData.string(forColumnIndex: 6)
|
|
|
+ row["audio_id"] = cursorData.string(forColumnIndex: 7)
|
|
|
+ row["video_id"] = cursorData.string(forColumnIndex: 8)
|
|
|
+ row["image_id"] = cursorData.string(forColumnIndex: 9)
|
|
|
+ row["thumb_id"] = cursorData.string(forColumnIndex: 10)
|
|
|
+ row["read_receipts"] = cursorData.string(forColumnIndex: 11)
|
|
|
+ row["chat_id"] = cursorData.string(forColumnIndex: 12)
|
|
|
+ row["file_id"] = cursorData.string(forColumnIndex: 13)
|
|
|
+ row["attachment_flag"] = cursorData.string(forColumnIndex: 14)
|
|
|
+ row["reff_id"] = cursorData.string(forColumnIndex: 15)
|
|
|
+ row["lock"] = cursorData.string(forColumnIndex: 16)
|
|
|
+ row["is_stared"] = cursorData.string(forColumnIndex: 17)
|
|
|
+ row["blog_id"] = cursorData.string(forColumnIndex: 18)
|
|
|
+ row["credential"] = cursorData.string(forColumnIndex: 19)
|
|
|
+ row[TypeDataMessage.is_call_center] = cursorData.string(forColumnIndex: 20)
|
|
|
+ row[TypeDataMessage.call_center_id] = cursorData.string(forColumnIndex: 21)
|
|
|
+ row[TypeDataMessage.opposite_pin] = cursorData.string(forColumnIndex: 22)
|
|
|
+ if let cursorStatus = Database.shared.getRecords(fmdb: fmdb, query: "SELECT status FROM MESSAGE_STATUS WHERE message_id='\(row["message_id"] as! String)'") {
|
|
|
+ while cursorStatus.next() {
|
|
|
+ row["status"] = cursorStatus.string(forColumnIndex: 0)
|
|
|
}
|
|
|
+ cursorStatus.close()
|
|
|
}
|
|
|
- }
|
|
|
- row["chat_date"] = chatDate(stringDate: row["server_date"] as! String)
|
|
|
- row["isSelected"] = false
|
|
|
- if row["credential"] != nil && row["credential"] as! String == "1" {
|
|
|
- let idMe = User.getMyPin()!
|
|
|
- if row["f_pin"] as! String == idMe {
|
|
|
- let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(row["server_date"] as! String)!), end: Date())
|
|
|
- if second > 60 {
|
|
|
- listTimerCredential[row["message_id"] as! String] = 0
|
|
|
- row["lock"] = "2"
|
|
|
- row["reff_id"] = ""
|
|
|
- DispatchQueue.global().async {
|
|
|
- Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "lock" : "2"
|
|
|
- ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
- })
|
|
|
+ let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
|
|
|
+ let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
|
|
|
+ let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
|
|
|
+ if let dirPath = paths.first {
|
|
|
+ let videoURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["video_id"] as! String)
|
|
|
+ let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(row["file_id"] as! String)
|
|
|
+ if ((row["video_id"] as! String) != "") {
|
|
|
+ if FileManager.default.fileExists(atPath: videoURL.path){
|
|
|
+ row["progress"] = 100.0
|
|
|
+ } else {
|
|
|
+ row["progress"] = 0.0
|
|
|
}
|
|
|
} else {
|
|
|
- let second = 60 - second
|
|
|
- listTimerCredential[row["message_id"] as! String] = second
|
|
|
+ if FileManager.default.fileExists(atPath: fileURL.path){
|
|
|
+ row["progress"] = 100.0
|
|
|
+ } else {
|
|
|
+ row["progress"] = 0.0
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- let hasMessageId: String? = SecureUserDefaults.shared.value(forKey: row["message_id"] as! String) ?? nil
|
|
|
- if hasMessageId != nil {
|
|
|
- let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(hasMessageId!)!), end: Date())
|
|
|
+ }
|
|
|
+ row["chat_date"] = chatDate(stringDate: row["server_date"] as! String)
|
|
|
+ row["isSelected"] = false
|
|
|
+ if row["credential"] != nil && row["credential"] as! String == "1" {
|
|
|
+ let idMe = User.getMyPin()!
|
|
|
+ if row["f_pin"] as! String == idMe {
|
|
|
+ let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(row["server_date"] as! String)!), end: Date())
|
|
|
if second > 60 {
|
|
|
listTimerCredential[row["message_id"] as! String] = 0
|
|
|
row["lock"] = "2"
|
|
|
row["reff_id"] = ""
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "lock" : "2"
|
|
|
- ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "lock" : "2"
|
|
|
+ ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
@@ -1064,49 +1096,77 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
listTimerCredential[row["message_id"] as! String] = second
|
|
|
}
|
|
|
} else {
|
|
|
- SecureUserDefaults.shared.set("\(Date().currentTimeMillis())", forKey: row["message_id"] as! String)
|
|
|
- listTimerCredential[row["message_id"] as! String] = 60
|
|
|
+ let hasMessageId: String? = SecureUserDefaults.shared.value(forKey: row["message_id"] as! String) ?? nil
|
|
|
+ if hasMessageId != nil {
|
|
|
+ let second = getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(hasMessageId!)!), end: Date())
|
|
|
+ if second > 60 {
|
|
|
+ listTimerCredential[row["message_id"] as! String] = 0
|
|
|
+ row["lock"] = "2"
|
|
|
+ row["reff_id"] = ""
|
|
|
+ DispatchQueue.global().async {
|
|
|
+ Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "lock" : "2"
|
|
|
+ ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ let second = 60 - second
|
|
|
+ listTimerCredential[row["message_id"] as! String] = second
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ SecureUserDefaults.shared.set("\(Date().currentTimeMillis())", forKey: row["message_id"] as! String)
|
|
|
+ listTimerCredential[row["message_id"] as! String] = 60
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if (dataMessages.count == 0 || dataMessages.last!["f_pin"] as! String == row["f_pin"] as! String) && tempImages.count <= 30 && row["image_id"] != nil && !(row["image_id"] as! String).isEmpty && (row["message_text"] as! String).isEmpty && (row["reff_id"] as! String).isEmpty && (row["credential"] as! String) != "1" && (row["read_receipts"] as! String) != "8" {
|
|
|
- if tempImages.count != 0 && getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(tempImages.last!.time)!), end: Date.init(milliseconds: Int64(row["server_date"] as! String)!))/60 >= 11 {
|
|
|
- if tempImages.count >= 4 {
|
|
|
- groupImages[tempImages[0].messageId] = tempImages
|
|
|
- if let idxTemp = dataMessages.firstIndex(where: { $0["message_id"] as! String == tempImages[0].messageId }) {
|
|
|
- for _ in 1..<tempImages.count {
|
|
|
- dataMessages.remove(at: idxTemp + 1)
|
|
|
+ if (dataMessages.count == 0 || dataMessages.last!["f_pin"] as! String == row["f_pin"] as! String) && tempImages.count <= 30 && row["image_id"] != nil && !(row["image_id"] as! String).isEmpty && (row["message_text"] as! String).isEmpty && (row["reff_id"] as! String).isEmpty && (row["credential"] as! String) != "1" && (row["read_receipts"] as! String) != "8" {
|
|
|
+ if tempImages.count != 0 && getSecondsDifferenceFromTwoDates(start: Date.init(milliseconds: Int64(tempImages.last!.time)!), end: Date.init(milliseconds: Int64(row["server_date"] as! String)!))/60 >= 11 {
|
|
|
+ if tempImages.count >= 4 {
|
|
|
+ groupImages[tempImages[0].messageId] = tempImages
|
|
|
+ if let idxTemp = dataMessages.firstIndex(where: { $0["message_id"] as! String == tempImages[0].messageId }) {
|
|
|
+ for _ in 1..<tempImages.count {
|
|
|
+ dataMessages.remove(at: idxTemp + 1)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ tempImages.removeAll()
|
|
|
+ }
|
|
|
+ tempImages.append(ImageGrouping(messageId: row["message_id"] as! String, thumbId: row["thumb_id"] as! String, imageId: row["image_id"] as! String, status: row["status"] as! String, time: row["server_date"] as! String, lPin: row["l_pin"] as! String, dataMessage: row, dataPerson: dataPerson, dataGroup: [:], dataTopic: [:]))
|
|
|
+ } else if tempImages.count >= 4 {
|
|
|
+ groupImages[tempImages[0].messageId] = tempImages
|
|
|
+ if let idxTemp = dataMessages.firstIndex(where: { $0["message_id"] as! String == tempImages[0].messageId }) {
|
|
|
+ for _ in 1..<tempImages.count {
|
|
|
+ dataMessages.remove(at: idxTemp + 1)
|
|
|
+ }
|
|
|
}
|
|
|
tempImages.removeAll()
|
|
|
+ } else if tempImages.count != 0 {
|
|
|
+ tempImages.removeAll()
|
|
|
+ }
|
|
|
+ dataMessages.append(row)
|
|
|
+ }
|
|
|
+ if tempImages.count >= 4 {
|
|
|
+ if tempImages.count > 30 {
|
|
|
+ tempImages.removeSubrange(30..<tempImages.count)
|
|
|
}
|
|
|
- tempImages.append(ImageGrouping(messageId: row["message_id"] as! String, thumbId: row["thumb_id"] as! String, imageId: row["image_id"] as! String, status: row["status"] as! String, time: row["server_date"] as! String, lPin: row["l_pin"] as! String, dataMessage: row, dataPerson: dataPerson, dataGroup: [:], dataTopic: [:]))
|
|
|
- } else if tempImages.count >= 4 {
|
|
|
groupImages[tempImages[0].messageId] = tempImages
|
|
|
if let idxTemp = dataMessages.firstIndex(where: { $0["message_id"] as! String == tempImages[0].messageId }) {
|
|
|
for _ in 1..<tempImages.count {
|
|
|
dataMessages.remove(at: idxTemp + 1)
|
|
|
}
|
|
|
}
|
|
|
- tempImages.removeAll()
|
|
|
- } else if tempImages.count != 0 {
|
|
|
- tempImages.removeAll()
|
|
|
- }
|
|
|
- dataMessages.append(row)
|
|
|
- }
|
|
|
- if tempImages.count >= 4 {
|
|
|
- if tempImages.count > 30 {
|
|
|
- tempImages.removeSubrange(30..<tempImages.count)
|
|
|
- }
|
|
|
- groupImages[tempImages[0].messageId] = tempImages
|
|
|
- if let idxTemp = dataMessages.firstIndex(where: { $0["message_id"] as! String == tempImages[0].messageId }) {
|
|
|
- for _ in 1..<tempImages.count {
|
|
|
- dataMessages.remove(at: idxTemp + 1)
|
|
|
- }
|
|
|
}
|
|
|
+ cursorData.close()
|
|
|
}
|
|
|
- cursorData.close()
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -1377,7 +1437,7 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
], replace: true)
|
|
|
} catch {
|
|
|
rollback.pointee = true
|
|
|
- //print(error)
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -1502,9 +1562,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
}
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "lock" : "2"
|
|
|
- ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "lock" : "2"
|
|
|
+ ], _where: "message_id = '\(row["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -2201,7 +2266,7 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
], replace: true)
|
|
|
} catch {
|
|
|
rollback.pointee = true
|
|
|
- //print(error)
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
if officer == idMe {
|
|
@@ -2394,9 +2459,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
}
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "lock" : "2"
|
|
|
- ], _where: "message_id = '\(messageId)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "lock" : "2"
|
|
|
+ ], _where: "message_id = '\(messageId)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -2808,9 +2878,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
let valueListGroupImages = listGroupImages.value
|
|
|
for i in 0..<valueListGroupImages.count {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "status" : "4"
|
|
|
- ], _where: "message_id = '\(valueListGroupImages[i].messageId)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "status" : "4"
|
|
|
+ ], _where: "message_id = '\(valueListGroupImages[i].messageId)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
message.mStatus = CoreMessage_TMessageUtil.getTID()
|
|
|
message.mBodies[CoreMessage_TMessageKey.L_PIN] = f_pin
|
|
@@ -2819,9 +2894,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
}
|
|
|
} else {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "status" : "4"
|
|
|
- ], _where: "message_id = '\(message_id)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "status" : "4"
|
|
|
+ ], _where: "message_id = '\(message_id)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
message.mStatus = CoreMessage_TMessageUtil.getTID()
|
|
|
message.mBodies[CoreMessage_TMessageKey.L_PIN] = f_pin
|
|
@@ -2951,9 +3031,14 @@ public class EditorPersonal: UIViewController, ImageVideoPickerDelegate, UIGestu
|
|
|
private func updateCounter(counter: Int) {
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", cvalues: [
|
|
|
- "counter" : "\(counter)"
|
|
|
- ], _where: "l_pin = '\(self.dataPerson["f_pin"]!!)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE_SUMMARY", cvalues: [
|
|
|
+ "counter" : "\(counter)"
|
|
|
+ ], _where: "l_pin = '\(self.dataPerson["f_pin"]!!)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadTabChats"), object: nil, userInfo: nil)
|
|
|
}
|
|
@@ -3260,13 +3345,18 @@ extension EditorPersonal: UITextViewDelegate {
|
|
|
}
|
|
|
var dataURL = ""
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select data_link from LINK_PREVIEW where link='\(text)'") {
|
|
|
- while cursor.next() {
|
|
|
- if let data = cursor.string(forColumnIndex: 0) {
|
|
|
- dataURL = data
|
|
|
+ do {
|
|
|
+ if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select data_link from LINK_PREVIEW where link='\(text)'") {
|
|
|
+ while cursor.next() {
|
|
|
+ if let data = cursor.string(forColumnIndex: 0) {
|
|
|
+ dataURL = data
|
|
|
+ }
|
|
|
}
|
|
|
+ cursor.close()
|
|
|
}
|
|
|
- cursor.close()
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
if !dataURL.isEmpty {
|
|
@@ -3312,7 +3402,7 @@ extension EditorPersonal: UITextViewDelegate {
|
|
|
], replace: true)
|
|
|
} catch {
|
|
|
rollback.pointee = true
|
|
|
- //print(error)
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
if self.showingLink != text {
|
|
@@ -3486,9 +3576,14 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
}
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "is_stared" : 1
|
|
|
- ], _where: "message_id = '\(dataMessages[indexPath!.row]["message_id"] as! String)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "is_stared" : 1
|
|
|
+ ], _where: "message_id = '\(dataMessages[indexPath!.row]["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
let idx = self.dataMessages.firstIndex(where: { $0["message_id"] as? String == dataMessages[indexPath!.row]["message_id"] as? String})
|
|
@@ -3504,9 +3599,14 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
}
|
|
|
DispatchQueue.global().async {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "is_stared" : 0
|
|
|
- ], _where: "message_id = '\(dataMessages[indexPath!.row]["message_id"] as! String)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "is_stared" : 0
|
|
|
+ ], _where: "message_id = '\(dataMessages[indexPath!.row]["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
let idx = self.dataMessages.firstIndex(where: { $0["message_id"] as? String == dataMessages[indexPath!.row]["message_id"] as? String})
|
|
@@ -3681,12 +3781,17 @@ extension EditorPersonal: UIContextMenuInteractionDelegate {
|
|
|
}
|
|
|
}
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "status" : "1"
|
|
|
- ], _where: "message_id = '\(messageId)'")
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE_STATUS", cvalues: [
|
|
|
- "status" : "1"
|
|
|
- ], _where: "message_id = '\(messageId)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "status" : "1"
|
|
|
+ ], _where: "message_id = '\(messageId)'")
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE_STATUS", cvalues: [
|
|
|
+ "status" : "1"
|
|
|
+ ], _where: "message_id = '\(messageId)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
let message = CoreMessage_TMessageBank.sendMessage(message_id: messageId,
|
|
|
l_pin: dataMessages[indexPath!.row][TypeDataMessage.l_pin] as! String,
|
|
@@ -5656,11 +5761,16 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
var dataURL = ""
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select data_link from LINK_PREVIEW where link='\(text)'"), cursor.next() {
|
|
|
- if let data = cursor.string(forColumnIndex: 0) {
|
|
|
- dataURL = data
|
|
|
+ do {
|
|
|
+ if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select data_link from LINK_PREVIEW where link='\(text)'"), cursor.next() {
|
|
|
+ if let data = cursor.string(forColumnIndex: 0) {
|
|
|
+ dataURL = data
|
|
|
+ }
|
|
|
+ cursor.close()
|
|
|
}
|
|
|
- cursor.close()
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
if dataURL.isEmpty {
|
|
@@ -5699,7 +5809,7 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
} catch {
|
|
|
rollback.pointee = true
|
|
|
- //print(error)
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
}
|
|
|
})
|
|
|
}, onError: { error in
|
|
@@ -5999,9 +6109,14 @@ extension EditorPersonal: UITableViewDelegate, UITableViewDataSource {
|
|
|
let result = Nexilis.write(message: CoreMessage_TMessageBank.getAckLocationMessage(f_pin: dataMessages[indexPath.row]["f_pin"] as! String, message_id: dataMessages[indexPath.row]["message_id"] as! String, l_pin: dataMessages[indexPath.row]["l_pin"] as! String, server_date: "\(Date().currentTimeMillis())", message_scope_id: dataMessages[indexPath.row]["message_scope_id"] as! String, longitude: "", latitude: "", description: ""))
|
|
|
if result != nil {
|
|
|
Database.shared.database?.inTransaction({ (fmdb, rollback) in
|
|
|
- _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
- "status" : "8"
|
|
|
- ], _where: "message_id = '\(dataMessages[indexPath.row]["message_id"] as! String)'")
|
|
|
+ do {
|
|
|
+ _ = Database.shared.updateRecord(fmdb: fmdb, table: "MESSAGE", cvalues: [
|
|
|
+ "status" : "8"
|
|
|
+ ], _where: "message_id = '\(dataMessages[indexPath.row]["message_id"] as! String)'")
|
|
|
+ } catch {
|
|
|
+ rollback.pointee = true
|
|
|
+ print("Access database error: \(error.localizedDescription)")
|
|
|
+ }
|
|
|
})
|
|
|
DispatchQueue.main.async {
|
|
|
if let index = self.dataMessages.firstIndex(where: {$0["message_id"] as? String == dataMessages[indexPath.row]["message_id"] as? String}) {
|