|
@@ -6,6 +6,7 @@
|
|
|
//
|
|
|
|
|
|
import Foundation
|
|
|
+import FMDB
|
|
|
|
|
|
public class User: Model {
|
|
|
|
|
@@ -86,13 +87,13 @@ public class User: Model {
|
|
|
return UserDefaults.standard.string(forKey: "me")
|
|
|
}
|
|
|
|
|
|
- public static func getData(pin: String?) -> User? {
|
|
|
+ public static func getData(pin: String?, fmdb: FMDatabase? = nil) -> User? {
|
|
|
guard let pin = pin else {
|
|
|
return nil
|
|
|
}
|
|
|
var user: User?
|
|
|
- Database.shared.database?.inTransaction({ fmdb, rollback in
|
|
|
- if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select f_pin, first_name, last_name, image_id, user_type, privacy_flag, offline_mode, ex_block, device_id, official_account from BUDDY where f_pin = '\(pin)' OR device_id = '\(pin)'"), cursor.next() {
|
|
|
+ if fmdb != nil {
|
|
|
+ if let cursor = Database.shared.getRecords(fmdb: fmdb!, query: "select f_pin, first_name, last_name, image_id, user_type, privacy_flag, offline_mode, ex_block, device_id, official_account from BUDDY where f_pin = '\(pin)' OR device_id = '\(pin)'"), cursor.next() {
|
|
|
user = User(pin: cursor.string(forColumnIndex: 0) ?? "",
|
|
|
firstName: cursor.string(forColumnIndex: 1) ?? "",
|
|
|
lastName: cursor.string(forColumnIndex: 2) ?? "",
|
|
@@ -114,7 +115,32 @@ public class User: Model {
|
|
|
offline_mode: "",
|
|
|
ex_block: "")
|
|
|
}
|
|
|
- })
|
|
|
+ } else {
|
|
|
+ Database.shared.database?.inTransaction({ fmdb, rollback in
|
|
|
+ if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select f_pin, first_name, last_name, image_id, user_type, privacy_flag, offline_mode, ex_block, device_id, official_account from BUDDY where f_pin = '\(pin)' OR device_id = '\(pin)'"), cursor.next() {
|
|
|
+ user = User(pin: cursor.string(forColumnIndex: 0) ?? "",
|
|
|
+ firstName: cursor.string(forColumnIndex: 1) ?? "",
|
|
|
+ lastName: cursor.string(forColumnIndex: 2) ?? "",
|
|
|
+ thumb: cursor.string(forColumnIndex: 3) ?? "",
|
|
|
+ userType: cursor.string(forColumnIndex: 4) ?? "",
|
|
|
+ privacy_flag: cursor.string(forColumnIndex: 5) ?? "",
|
|
|
+ offline_mode: cursor.string(forColumnIndex: 6) ?? "",
|
|
|
+ ex_block: cursor.string(forColumnIndex: 7) ?? "",
|
|
|
+ official: cursor.string(forColumnIndex: 9) ?? "",
|
|
|
+ device_id: cursor.string(forColumnIndex: 8) ?? "")
|
|
|
+ cursor.close()
|
|
|
+ } else {
|
|
|
+ user = User(pin: pin,
|
|
|
+ firstName: "User".localized(),
|
|
|
+ lastName: "",
|
|
|
+ thumb: "",
|
|
|
+ userType: "",
|
|
|
+ privacy_flag: "",
|
|
|
+ offline_mode: "",
|
|
|
+ ex_block: "")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
return user
|
|
|
}
|
|
|
|