Skip to content

Commit 3703f7e

Browse files
author
Arief Nur Putranto
committed
fix issue refresh token and update unreadCount using int64
1 parent 8a3e86f commit 3703f7e

File tree

8 files changed

+65
-11
lines changed

8 files changed

+65
-11
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.14.4"
3+
s.version = "1.14.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/QiscusDatabase/Model/Room+CoreDataProperties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension Room {
2424
@NSManaged var uniqueId: String?
2525
@NSManaged var avatarUrl: String?
2626
@NSManaged var options: String?
27-
@NSManaged var unreadCount: Int16
27+
@NSManaged var unreadCount: Int
2828
@NSManaged var localData: String?
2929
@NSManaged public var members: NSSet?
3030

Source/QiscusCore/Database/QiscusDatabase/Qiscus.xcdatamodeld/Qiscus.xcdatamodel/contents

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="16119" systemVersion="19E266" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="1.0">
2+
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24D60" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="1.0">
33
<entity name="Comment" representedClassName="QiscusCore.Comment" syncable="YES">
44
<attribute name="commentBeforeId" optional="YES" attributeType="String"/>
55
<attribute name="extras" optional="YES" attributeType="String"/>
@@ -50,17 +50,12 @@
5050
<attribute name="options" optional="YES" attributeType="String"/>
5151
<attribute name="type" optional="YES" attributeType="String"/>
5252
<attribute name="uniqueId" optional="YES" attributeType="String"/>
53-
<attribute name="unreadCount" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
53+
<attribute name="unreadCount" optional="YES" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
5454
<relationship name="members" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Member" inverseName="rooms" inverseEntity="Member"/>
5555
<uniquenessConstraints>
5656
<uniquenessConstraint>
5757
<constraint value="id"/>
5858
</uniquenessConstraint>
5959
</uniquenessConstraints>
6060
</entity>
61-
<elements>
62-
<element name="Comment" positionX="-164" positionY="132" width="128" height="313"/>
63-
<element name="Member" positionX="243" positionY="108" width="128" height="178"/>
64-
<element name="Room" positionX="9" positionY="306" width="128" height="195"/>
65-
</elements>
6661
</model>

Source/QiscusCore/Database/RoomStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ extension RoomStorage {
254254
}
255255
result.id = core.id
256256
result.uniqueId = core.uniqueId
257-
result.unreadCount = Int16(core.unreadCount)
257+
result.unreadCount = core.unreadCount
258258
result.name = core.name
259259
result.avatarUrl = core.avatarUrl?.absoluteString ?? ""
260260
result.options = core.options

Source/QiscusCore/Model/CommentModel.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ open class CommentModel {
9191
if let _payload = self.payload {
9292
self.payload?.removeAll()
9393
self.payload = getPayload(fromPayload: _payload)
94+
95+
if payload == nil {
96+
self.payload?.removeAll()
97+
self.payload = getPayloadCustom(fromPayload: _payload)
98+
}
9499
}
95100
}
96101

@@ -135,6 +140,18 @@ extension CommentModel {
135140
}
136141
}
137142

143+
private func getPayloadCustom(fromPayload data: [String:Any]) -> [String:Any]? {
144+
if let payload = data as? [String:Any]{
145+
if !payload.isEmpty {
146+
return payload
147+
}else {
148+
return nil
149+
}
150+
}else {
151+
return nil
152+
}
153+
}
154+
138155
func getDate() -> Date {
139156
//let timezone = TimeZone.current.identifier
140157
let formatter = DateFormatter()

Source/QiscusCore/QiscusCore.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010
import UIKit
1111

1212
public class QiscusCore: NSObject {
13-
public static let qiscusCoreVersionNumber:String = "1.14.4"
13+
public static let qiscusCoreVersionNumber:String = "1.14.5"
1414
class var bundle:Bundle{
1515
get{
1616
let podBundle = Bundle(for: QiscusCore.self)
@@ -1439,7 +1439,9 @@ public class QiscusCore: NSObject {
14391439
if userID.isEmpty == true || refreshUserToken.isEmpty == true {
14401440
onError(QError(message: "Please force logout and setUser first"))
14411441
}else{
1442+
QiscusCore.realtime.unsubcribeCommentUpdateComemntNotification()
14421443
QiscusCore.network.refreshUserToken(userId: userID, refreshToken: refreshUserToken) { success in
1444+
QiscusCore.realtime.subcribeCommentUpdateComemntNotification()
14431445
onSuccess(success)
14441446
} onError: { error in
14451447
onError(error)

Source/QiscusCore/Realtime/RealtimeManager.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,46 @@ class RealtimeManager {
8181

8282
}
8383

84+
func unsubcribeCommentUpdateComemntNotification(){
85+
guard let c = client else {
86+
return
87+
}
88+
89+
if let user = QiscusCore.getUserData() {
90+
if ConfigManager.shared.isEnableDisableRealtimeManually == true {
91+
c.unsubscribe(endpoint: .comment(token: user.token))
92+
c.unsubscribe(endpoint: .updateComment(token: user.token))
93+
c.unsubscribe(endpoint: .notification(token: user.token))
94+
}
95+
}
96+
97+
print("today check unsubcribeCommentUpdateComemntNotification")
98+
}
99+
100+
func subcribeCommentUpdateComemntNotification(){
101+
guard let c = client else {
102+
return
103+
}
104+
105+
if let user = QiscusCore.getUserData() {
106+
if ConfigManager.shared.isEnableDisableRealtimeManually == true {
107+
if !c.subscribe(endpoint: .comment(token: user.token)){
108+
self.pendingSubscribeTopic.append(.comment(token: user.token))
109+
}
110+
111+
if !c.subscribe(endpoint: .updateComment(token: user.token)){
112+
self.pendingSubscribeTopic.append(.updateComment(token: user.token))
113+
}
114+
115+
if !c.subscribe(endpoint: .notification(token: user.token)){
116+
self.pendingSubscribeTopic.append(.notification(token: user.token))
117+
}
118+
}
119+
}
120+
121+
print("today check subcribeCommentUpdateComemntNotification")
122+
}
123+
84124
/// Subscribe comment(deliverd and read), typing by member in the room, and online status
85125
///
86126
/// - Parameter rooms: array of rooms

0 commit comments

Comments
 (0)