Skip to content

Commit

Permalink
implement appConfig sync and syncEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Arief Nur Putranto committed Jul 14, 2022
1 parent 19d1d35 commit 7286c71
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion QiscusCore.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "QiscusCore"
s.version = "1.6.0"
s.version = "1.6.1"
s.summary = "Qiscus Core SDK for iOS"
s.description = <<-DESC
Qiscus SDK for iOS contains Qiscus public Model.
Expand Down
4 changes: 4 additions & 0 deletions Source/QiscusCore/Model/AppConfigModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class AppConfigModel {
public var syncInterval : Double = 0
public var syncOnConnect : Double = 0
public var extras : String = ""
public var enableSync : Bool = true
public var enableSyncEvent : Bool = false

init(json: JSON) {
self.baseURL = json["base_url"].string ?? ""
Expand All @@ -28,5 +30,7 @@ public class AppConfigModel {
self.syncInterval = json["sync_interval"].double ?? 5000
self.syncOnConnect = json["sync_on_connect"].double ?? 30000
self.extras = json["extras"].string ?? ""
self.enableSync = json["enable_sync"].bool ?? true
self.enableSyncEvent = json["enable_sync_event"].bool ?? false
}
}
4 changes: 4 additions & 0 deletions Source/QiscusCore/QiscusCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class QiscusCore: NSObject {

public static var enableEventReport : Bool = false
public static var enableRealtime : Bool = true
public static var enableSync : Bool = true
public static var enableSyncEvent : Bool = false

@available(*, deprecated, message: "will soon become unavailable.")
public static var enableDebugPrint: Bool = false
Expand Down Expand Up @@ -186,6 +188,8 @@ public class QiscusCore: NSObject {
network.getAppConfig(onSuccess: { (appConfig) in
QiscusCore.enableEventReport = appConfig.enableEventReport
QiscusCore.enableRealtime = appConfig.enableRealtime
QiscusCore.enableSync = appConfig.enableSync
QiscusCore.enableSyncEvent = appConfig.enableSyncEvent

//check old and new appServer
if let oldConfig = config.server {
Expand Down
16 changes: 12 additions & 4 deletions Source/QiscusCore/QiscusWorkerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class QiscusWorkerManager {
// MARK : Improve realtime state acurate disconnected
if QiscusCore.isLogined {
if ConfigManager.shared.isEnableDisableRealtimeManually == true{
self.sync()
if QiscusCore.enableSync == true {
self.sync()
}

self.pending()
DispatchQueue.main.sync {
let state = UIApplication.shared.applicationState
Expand Down Expand Up @@ -48,7 +51,7 @@ class QiscusWorkerManager {
}

private func syncEvent() {
if QiscusCore.isLogined{
if QiscusCore.isLogined && QiscusCore.enableSyncEvent == true{
//sync event
let id = ConfigManager.shared.syncEventId
QiscusCore.network.synchronizeEvent(lastEventId: id, onSuccess: { (events) in
Expand Down Expand Up @@ -131,10 +134,15 @@ class QiscusWorkerManager {
private func syncAuto() {
DispatchQueue.global(qos: .background).async {
if ConfigManager.shared.isEnableDisableRealtimeManually == false {
self.synchronize()
if QiscusCore.enableSync == true {
self.synchronize()
}

} else {
if ConfigManager.shared.isConnectedMqtt == true {
self.synchronize()
if QiscusCore.enableSync == true {
self.synchronize()
}
}
}
}
Expand Down

0 comments on commit 7286c71

Please sign in to comment.