Skip to content

Commit d0bf236

Browse files
author
Arief Nur Putranto
committed
add log and improve reconnect realtime using period time
1 parent d5161a2 commit d0bf236

13 files changed

+164
-52
lines changed

QiscusCore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "QiscusCore"
3-
s.version = "1.13.4"
3+
s.version = "1.13.5"
44
s.summary = "Qiscus Core SDK for iOS"
55
s.description = <<-DESC
66
Qiscus SDK for iOS contains Qiscus public Model.

Source/QiscusCore/Database/CommentStorage.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CommentStorage : QiscusStorage {
2626

2727
func loadData() {
2828
self.data = self.loadFromLocal()
29-
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "finish loadData() comment \(QiscusLogger.getDateTime()) with data comment count \(self.data.count)")
29+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "finish loadData() comment loadFromLocal() with data comment count \(self.data.count) \(QiscusLogger.getDateTime())")
3030
}
3131

3232
func removeAll() {
@@ -277,7 +277,7 @@ extension CommentStorage {
277277
}else {
278278
result = Comment.generate() // prepare create new
279279
}
280-
QiscusThread.background {
280+
//QiscusThread.background {
281281
result.id = core.id
282282
result.type = core.type
283283
result.userAvatarUrl = core.userAvatarUrl?.absoluteString
@@ -302,7 +302,7 @@ extension CommentStorage {
302302
if let userExtras = core.userExtras {
303303
result.userExtras = userExtras.dict2json()
304304
}
305-
}
305+
//}
306306
return result
307307
}
308308

@@ -323,7 +323,7 @@ extension CommentStorage {
323323
guard let timestamp = data.timestamp else { return result }
324324
guard let commentBeforeId = data.commentBeforeId else { return result }
325325

326-
QiscusThread.background {
326+
//QiscusThread.background {
327327
result.id = id
328328
result.type = type
329329
result.userAvatarUrl = URL(string: userAvatarUrl)
@@ -361,7 +361,7 @@ extension CommentStorage {
361361
}else {
362362
result.userExtras = nil
363363
}
364-
}
364+
//}
365365
return result
366366
}
367367

Source/QiscusCore/Database/MemberDatabase.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class MemberDatabase {
1717
}
1818

1919
func loadData() {
20-
self.data = loadFromLocal()
21-
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "finish loadData() member \(QiscusLogger.getDateTime()) with data member count \(self.data.count)")
20+
self.data = self.loadFromLocal()
21+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "finish loadData() member loadFromLocal() with data member count \(self.data.count) \(QiscusLogger.getDateTime())")
2222
}
2323

2424
func removeAll() {
@@ -125,7 +125,7 @@ extension MemberDatabase {
125125
}else {
126126
result = Member.generate() // prepare create new
127127
}
128-
QiscusThread.background {
128+
//QiscusThread.background {
129129
result.id = core.id
130130
result.avatarUrl = core.avatarUrl?.absoluteString
131131
result.email = core.email
@@ -136,7 +136,7 @@ extension MemberDatabase {
136136
if let extras = core.extras {
137137
result.extras = extras.dict2json()
138138
}
139-
}
139+
//}
140140
return result
141141
}
142142

@@ -147,7 +147,6 @@ extension MemberDatabase {
147147
guard let name = member.username else { return result }
148148
guard let email = member.email else { return result }
149149
guard let avatarUrl = member.avatarUrl else { return result }
150-
QiscusThread.background {
151150
result.id = id
152151
result.username = name
153152
result.email = email
@@ -160,7 +159,6 @@ extension MemberDatabase {
160159
}else {
161160
result.extras = nil
162161
}
163-
}
164162
return result
165163
}
166164

Source/QiscusCore/Database/QiscusDatabase/Model/Comment+CoreDataClass.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ protocol ActiveRecord {
2525
extension Comment {
2626
// create behaviour like active record
2727
static func all() -> [Comment] {
28+
if Thread.isMainThread {
29+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "start load comment.ALL() with running in main thread with time \(QiscusLogger.getDateTime())")
30+
}else{
31+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "start load comment.ALL() with running in background thread with time \(QiscusLogger.getDateTime())")
32+
}
33+
2834
let fetchRequest:NSFetchRequest<Comment> = Comment.fetchRequest()
2935
var results = [Comment]()
3036
var resultsNullData = [Comment]()
@@ -45,6 +51,13 @@ extension Comment {
4551
} catch {
4652

4753
}
54+
55+
if Thread.isMainThread {
56+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "finish load room.ALL() with running in main thread with time \(QiscusLogger.getDateTime())")
57+
}else{
58+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "finish load room.ALL() with running in background thread with time \(QiscusLogger.getDateTime())")
59+
}
60+
4861
return results
4962
}
5063

Source/QiscusCore/Database/QiscusDatabase/Model/Member+CoreDataClass.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public class Member: NSManagedObject {
1717
extension Member {
1818
// create behaviour like active record
1919
static func all() -> [Member] {
20+
if Thread.isMainThread {
21+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "start load member.ALL() with running in main thread with time \(QiscusLogger.getDateTime())")
22+
}else{
23+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "start load member.ALL() with running in background thread with time \(QiscusLogger.getDateTime())")
24+
}
25+
2026
let fetchRequest:NSFetchRequest<Member> = Member.fetchRequest()
2127
var results = [Member]()
2228
var resultsNullData = [Member]()
@@ -35,6 +41,13 @@ extension Member {
3541
} catch {
3642

3743
}
44+
45+
if Thread.isMainThread {
46+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "finish load member.ALL() with running in main thread with time \(QiscusLogger.getDateTime())")
47+
}else{
48+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "finish load member.ALL() with running in background thread with time \(QiscusLogger.getDateTime())")
49+
}
50+
3851
return results
3952
}
4053

Source/QiscusCore/Database/QiscusDatabase/Model/Room+CoreDataClass.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ public class Room: NSManagedObject {
1818
extension Room {
1919
// create behaviour like active record
2020
static func all() -> [Room] {
21+
if Thread.isMainThread {
22+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "start load room.ALL() with running in main thread with time \(QiscusLogger.getDateTime())")
23+
}else{
24+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "start load room.ALL() with running in background thread with time \(QiscusLogger.getDateTime())")
25+
}
26+
27+
2128
let fetchRequest:NSFetchRequest<Room> = Room.fetchRequest()
2229
var results = [Room]()
2330
var resultsNullData = [Room]()
2431

2532
do {
33+
// log disini
2634
results = try PresistentStore.context.fetch(fetchRequest)
2735
//check null data
2836
resultsNullData = results.filter{ $0.id == nil || $0.id == ""}
@@ -39,6 +47,13 @@ extension Room {
3947
} catch {
4048
//
4149
}
50+
51+
if Thread.isMainThread {
52+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "finish load room.ALL() with running in main thread with time \(QiscusLogger.getDateTime())")
53+
}else{
54+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-loadData()", message: "finish load room.ALL() with running in background thread with time \(QiscusLogger.getDateTime())")
55+
}
56+
4257
return results
4358
}
4459

Source/QiscusCore/Database/QiscusDatabaseManager.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ public class QiscusDatabaseManager {
2121
public func loadData() {
2222
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "start loadData() member \(QiscusLogger.getDateTime())")
2323

24-
member.loadData()
25-
24+
self.member.loadData()
25+
2626
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "start loadData() room \(QiscusLogger.getDateTime())")
2727

28-
room.loadData()
28+
self.room.loadData()
2929

3030
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "start loadData() comment \(QiscusLogger.getDateTime())")
3131

32-
comment.loadData()
32+
self.comment.loadData()
33+
3334

3435
}
3536

Source/QiscusCore/Database/RoomStorage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class RoomStorage {
2020
}
2121

2222
func loadData() {
23-
let local = loadFromLocal()
24-
data = sort(local)
23+
let local = self.loadFromLocal()
24+
self.data = self.sort(local)
2525

26-
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "finish loadData() room \(QiscusLogger.getDateTime()) with data room count \(data.count)")
26+
QiscusCore.eventdelegate?.onDebugEvent("InitQiscus-LoadData()", message: "finish loadData() room loadFromLocal() with data room count \(self.data.count) \(QiscusLogger.getDateTime())")
2727
}
2828

2929
func removeAll() {

Source/QiscusCore/QiscusCore.swift

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public class QiscusCore: NSObject {
110110
public static var enableExpiredToken : Bool = true
111111
public static var enableRefreshToken : Bool = false
112112

113+
public static var fromSetupWithCustomServer : Bool = false
114+
public static var reconnectCounter : Int = 0
115+
113116
@available(*, deprecated, message: "will soon become unavailable.")
114117
public static var enableDebugPrint: Bool = false
115118
public class func enableDebugMode(value : Bool = false){
@@ -138,27 +141,42 @@ public class QiscusCore: NSObject {
138141
/// - Parameter WithAppID: Qiscus SDK App ID
139142
@available(*, deprecated, message: "will soon become unavailable.")
140143
public class func setup(WithAppID id: String, server: QiscusServer? = nil) {
144+
if Thread.isMainThread {
145+
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "running in main thread with time \(QiscusLogger.getDateTime())")
146+
}else{
147+
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "running in background thread with time \(QiscusLogger.getDateTime())")
148+
}
149+
141150
if QiscusCore.hasSetupUser() == true {
142151
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "start with was login \(QiscusLogger.getDateTime())")
143152
}else{
144153
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "start with no login \(QiscusLogger.getDateTime())")
145154
}
146155

147156
config.appID = id
157+
config.eventdelegate = self.eventdelegate
158+
reconnectCounter = 0
159+
148160
if let _server = server {
149161
config.server = _server
150162
}else {
151163
config.server = QiscusServer(url: URL.init(string: "https://api.qiscus.com")!, realtimeURL: self.defaultRealtimeURL, realtimePort: 1885, brokerLBUrl: self.defaultBrokerUrl)
152164
}
153165

154-
if QiscusCore.isLogined{
155-
// Populate data from db
156-
QiscusCore.database.loadData()
157-
}
166+
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "start check QiscusCore.isLogined \(QiscusLogger.getDateTime())")
167+
self.fromSetupWithCustomServer = true
158168

159-
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "finish loadData() \(QiscusLogger.getDateTime())")
169+
QiscusThread.background {
170+
if QiscusCore.isLogined{
171+
// Populate data from db
172+
QiscusCore.database.loadData()
173+
}
174+
175+
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "finish loadData() \(QiscusLogger.getDateTime())")
176+
177+
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "start load getAppConfig \(QiscusLogger.getDateTime())")
178+
}
160179

161-
self.eventdelegate?.onDebugEvent("InitQiscus-setup(WithAppID)", message: "start load getAppConfig \(QiscusLogger.getDateTime())")
162180

163181
getAppConfig()
164182
}
@@ -167,27 +185,38 @@ public class QiscusCore: NSObject {
167185
///
168186
/// - Parameter WithAppID: Qiscus SDK App ID
169187
public class func setup(AppID: String) {
188+
if Thread.isMainThread {
189+
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "running in main thread with time \(QiscusLogger.getDateTime())")
190+
}else{
191+
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "running in background thread with time \(QiscusLogger.getDateTime())")
192+
}
193+
170194
if QiscusCore.hasSetupUser() == true {
171195
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "start with was login \(QiscusLogger.getDateTime())")
172196
}else{
173197
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "start with no login \(QiscusLogger.getDateTime())")
174198
}
175199

176200
config.appID = AppID
201+
config.eventdelegate = self.eventdelegate
202+
reconnectCounter = 0
177203

178204
config.server = QiscusServer(url: URL.init(string: "https://api.qiscus.com")!, realtimeURL: self.defaultRealtimeURL, realtimePort: 1885, brokerLBUrl: self.defaultBrokerUrl)
179205

180-
206+
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "start check QiscusCore.isLogined \(QiscusLogger.getDateTime())")
207+
self.fromSetupWithCustomServer = true
181208

182-
if QiscusCore.isLogined{
183-
// Populate data from db
184-
QiscusCore.database.loadData()
209+
QiscusThread.background {
210+
if QiscusCore.isLogined{
211+
// Populate data from db
212+
QiscusCore.database.loadData()
213+
}
214+
215+
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "finish loadData() \(QiscusLogger.getDateTime())")
216+
217+
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "start load getAppConfig \(QiscusLogger.getDateTime())")
185218
}
186219

187-
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "finish loadData() \(QiscusLogger.getDateTime())")
188-
189-
self.eventdelegate?.onDebugEvent("InitQiscus-setup()", message: "start load getAppConfig \(QiscusLogger.getDateTime())")
190-
191220
getAppConfig()
192221
}
193222

@@ -200,14 +229,22 @@ public class QiscusCore: NSObject {
200229
/// brokerLBUrl: brokerLBUrl is optional, default using urlLB from qiscus
201230

202231
public class func setupWithCustomServer(AppID: String, baseUrl: URL, brokerUrl: String, brokerLBUrl: String?) {
203-
232+
233+
if Thread.isMainThread {
234+
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "running in main thread with time \(QiscusLogger.getDateTime())")
235+
}else{
236+
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "running in background thread with time \(QiscusLogger.getDateTime())")
237+
}
238+
204239
if QiscusCore.hasSetupUser() == true {
205240
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "start with was login \(QiscusLogger.getDateTime())")
206241
}else{
207242
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "start with no login \(QiscusLogger.getDateTime())")
208243
}
209244

210245
config.appID = AppID
246+
config.eventdelegate = self.eventdelegate
247+
reconnectCounter = 0
211248

212249
if brokerLBUrl != nil{
213250
config.server = QiscusServer(url: baseUrl, realtimeURL: brokerUrl, realtimePort: 1885, brokerLBUrl: brokerLBUrl)
@@ -217,14 +254,20 @@ public class QiscusCore: NSObject {
217254
//realtime.setup(appName: AppID)
218255
}
219256

220-
if QiscusCore.isLogined{
221-
// Populate data from db
222-
QiscusCore.database.loadData()
223-
}
224-
225-
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "finish loadData() \(QiscusLogger.getDateTime())")
257+
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "start check QiscusCore.isLogined \(QiscusLogger.getDateTime())")
258+
self.fromSetupWithCustomServer = true
226259

227-
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "start load getAppConfig \(QiscusLogger.getDateTime())")
260+
QiscusThread.background {
261+
if QiscusCore.isLogined{
262+
// Populate data from db
263+
QiscusCore.database.loadData()
264+
}
265+
266+
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "finish loadData() \(QiscusLogger.getDateTime())")
267+
268+
self.eventdelegate?.onDebugEvent("InitQiscus-setupWithCustomServer", message: "start load getAppConfig \(QiscusLogger.getDateTime())")
269+
270+
}
228271

229272
getAppConfig()
230273
}
@@ -668,6 +711,12 @@ public class QiscusCore: NSObject {
668711
return false
669712
}
670713
}else{
714+
if self.fromSetupWithCustomServer == true {
715+
self.eventdelegate?.onDebugEvent("InitQiscus-isLogined()", message: "finish check QiscusCore.isLogined return false \(QiscusLogger.getDateTime())")
716+
717+
self.fromSetupWithCustomServer = false // just firstTime when call QiscusCoreWithCustomeServer()
718+
}
719+
671720
return false
672721
}
673722
}

0 commit comments

Comments
 (0)