Skip to content

Commit

Permalink
prevent a crash in mqtt when connecting and fix issue refresh token i…
Browse files Browse the repository at this point in the history
…n some case
  • Loading branch information
Arief Nur Putranto committed Jun 6, 2023
1 parent 050084b commit 856fcc0
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Second, you need to add SDK dependencies inside your app .gradle. Then, you need
```
dependencies {
...
implementation 'com.qiscus.sdk:chat-core:1.6.5'
implementation 'com.qiscus.sdk:chat-core:1.6.6'
}
```

Expand Down
11 changes: 11 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@
-keep class com.qiscus.sdk.chat.core.data.model.** {
*;
}

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response

# R8 full mode strips generic signatures from return types if not kept.
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
4 changes: 2 additions & 2 deletions app/src/main/java/com/qiscus/dragonfly/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ public void publishEvent(View view) {
protected void onResume() {
super.onResume();
EventBus.getDefault().register(this);
QiscusPusherApi.getInstance().subsribeCustomEvent(1353686);
//QiscusPusherApi.getInstance().subsribeCustomEvent(1353686);
}

@Override
protected void onPause() {
QiscusPusherApi.getInstance().unsubsribeCustomEvent(1353686);
//QiscusPusherApi.getInstance().unsubsribeCustomEvent(1353686);
EventBus.getDefault().unregister(this);
super.onPause();
}
Expand Down
11 changes: 11 additions & 0 deletions chat-core/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# With R8 full mode generic signatures are stripped for classes that are not
# kept. Suspend functions are wrapped in continuations where the type argument
# is used.
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response

# R8 full mode strips generic signatures from return types if not kept.
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
12 changes: 8 additions & 4 deletions chat-core/src/main/java/com/qiscus/sdk/chat/core/QiscusCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1131,10 +1131,14 @@ public void onError(Throwable throwable) {
}

private static boolean isValidToRefreshToken(QiscusAccount account) {
Date expiredAt = QiscusDateUtil.getDateTimeSdf(account.getTokenExpiresAt());
return DateUtils.isToday(expiredAt.getTime())
|| QiscusDateUtil.isBeforeADaySdf(expiredAt.getTime())
|| QiscusDateUtil.isPassingDateTimeSdf(expiredAt.getTime());
if (account.getTokenExpiresAt().isEmpty()) {
return false;
}else{
Date expiredAt = QiscusDateUtil.getDateTimeSdf(account.getTokenExpiresAt());
return DateUtils.isToday(expiredAt.getTime())
|| QiscusDateUtil.isBeforeADaySdf(expiredAt.getTime())
|| QiscusDateUtil.isPassingDateTimeSdf(expiredAt.getTime());
}
}

public static void clearUser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,12 @@ public void connect() {
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setAutomaticReconnect(false);
mqttConnectOptions.setCleanSession(false);
mqttConnectOptions.setWill("u/" + qiscusAccount.getEmail()
+ "/s", ("0:" + Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis())
.getBytes(), 2, true);
EventBus.getDefault().post(QiscusMqttStatusEvent.RECONNETING);

try {
mqttConnectOptions.setWill("u/" + qiscusAccount.getEmail()
+ "/s", ("0:" + Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis())
.getBytes(), 2, true);
EventBus.getDefault().post(QiscusMqttStatusEvent.RECONNETING);
mqttAndroidClient.connect(mqttConnectOptions, null, this);
QiscusLogger.print(TAG, "Connecting...");
} catch (MqttException | IllegalStateException e) {
Expand Down Expand Up @@ -480,6 +481,8 @@ public void restartConnection() {
} catch (MqttException | NullPointerException | IllegalArgumentException e) {
//Do nothing
connecting = false;
} catch (RuntimeException e) {
connecting = false;
}

clearTasks();
Expand Down
5 changes: 2 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ext {
firebaseCore : "21.1.1",
firebaseMessaging: "23.1.2",
okHttp : "3.12.5",
retrofit : "2.10.0-SNAPSHOT",
retrofit : "2.9.0",

nirmana : "1.3.0",
manggil : "1.0.1",
Expand Down Expand Up @@ -92,8 +92,7 @@ ext {
retrofitDeps = [
retrofit : "com.squareup.retrofit2:retrofit:${versions.retrofit}",
retrofitGson: "com.squareup.retrofit2:converter-gson:${versions.retrofit}",
retrofitRx : "com.squareup.retrofit2:adapter-rxjava:${versions.retrofit}",
scalars : "com.squareup.retrofit2:converter-scalars:2.1.0",
retrofitRx : "com.squareup.retrofit2:adapter-rxjava:${versions.retrofit}"
]

rxDebs = [
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Secondly, you need to add SDK dependencies inside your app .gradle. Then, you ne
```
dependencies {
...
implementation 'com.qiscus.sdk:chat-core:1.6.5'
implementation 'com.qiscus.sdk:chat-core:1.6.6'
}
```

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ chatVersionPatch=0
# === qiscus chat-core library version ===
chatCoreVersionMajor=1
chatCoreVersionMinor=6
chatCoreVersionPatch=5
chatCoreVersionPatch=6

# === qiscus default base url
BASE_URL_SERVER="https://api.qiscus.com/"
Expand All @@ -59,7 +59,7 @@ android.enableJetifier=true

libraryGroupId=com.qiscus.sdk
libraryArtifactId=chat-core
libraryVersion=1.6.5
libraryVersion=1.6.6

libraryGroupIdChat=com.qiscus.sdk
libraryArtifactIdChat=chat
Expand Down

0 comments on commit 856fcc0

Please sign in to comment.