Skip to content

Commit 803fe9c

Browse files
committed
Change delivered/read message to call rest api
1 parent 42c5985 commit 803fe9c

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

chat/src/main/java/com/qiscus/sdk/data/remote/QiscusApi.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ public Observable<QiscusChatRoom> updateChatRoom(int roomId, String name, String
600600
.doOnNext(qiscusChatRoom1 -> Qiscus.getDataStore().addOrUpdate(qiscusChatRoom1));
601601
}
602602

603+
public Observable<Void> updateCommentStatus(int roomId, int lastReadId, int lastReceivedId) {
604+
return api.updateCommentStatus(Qiscus.getToken(), roomId, lastReadId, lastReceivedId)
605+
.map(jsonElement -> null);
606+
}
607+
608+
603609
private interface Api {
604610

605611
@FormUrlEncoded
@@ -651,6 +657,13 @@ Observable<JsonElement> updateChatRoom(@Field("token") String token,
651657
@Field("room_name") String name,
652658
@Field("avatar_url") String avatarUrl,
653659
@Field("options") String options);
660+
661+
@FormUrlEncoded
662+
@POST("/api/v2/mobile/update_comment_status")
663+
Observable<JsonElement> updateCommentStatus(@Field("token") String token,
664+
@Field("room_id") int roomId,
665+
@Field("last_comment_read_id") int lastReadId,
666+
@Field("last_comment_received_id") int lastReceivedId);
654667
}
655668

656669
private static class CountingFileRequestBody extends RequestBody {

chat/src/main/java/com/qiscus/sdk/data/remote/QiscusPusherApi.java

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
import java.util.Timer;
5353
import java.util.TimerTask;
5454

55+
import rx.android.schedulers.AndroidSchedulers;
56+
import rx.schedulers.Schedulers;
57+
5558
public enum QiscusPusherApi implements MqttCallback, IMqttActionListener {
5659

5760
INSTANCE;
@@ -272,35 +275,19 @@ public void setUserTyping(int roomId, int topicId, boolean typing) {
272275

273276

274277
public void setUserRead(int roomId, int topicId, int commentId, String commentUniqueId) {
275-
if (!mqttAndroidClient.isConnected()) {
276-
connect();
277-
}
278-
try {
279-
MqttMessage message = new MqttMessage();
280-
message.setPayload((commentId + ":" + commentUniqueId).getBytes());
281-
message.setQos(1);
282-
message.setRetained(true);
283-
pendingTokens.add(mqttAndroidClient.publish("r/" + roomId + "/" + topicId + "/"
284-
+ qiscusAccount.getEmail() + "/r", message));
285-
} catch (MqttException | NullPointerException e) {
286-
e.printStackTrace();
287-
}
278+
QiscusApi.getInstance().updateCommentStatus(roomId, commentId, 0)
279+
.subscribeOn(Schedulers.io())
280+
.observeOn(AndroidSchedulers.mainThread())
281+
.subscribe(aVoid -> {
282+
}, Throwable::printStackTrace);
288283
}
289284

290285
public void setUserDelivery(int roomId, int topicId, int commentId, String commentUniqueId) {
291-
if (!mqttAndroidClient.isConnected()) {
292-
connect();
293-
}
294-
try {
295-
MqttMessage message = new MqttMessage();
296-
message.setPayload((commentId + ":" + commentUniqueId).getBytes());
297-
message.setQos(1);
298-
message.setRetained(true);
299-
pendingTokens.add(mqttAndroidClient.publish("r/" + roomId + "/" + topicId + "/"
300-
+ qiscusAccount.getEmail() + "/d", message));
301-
} catch (MqttException | NullPointerException e) {
302-
e.printStackTrace();
303-
}
286+
QiscusApi.getInstance().updateCommentStatus(roomId, 0, commentId)
287+
.subscribeOn(Schedulers.io())
288+
.observeOn(AndroidSchedulers.mainThread())
289+
.subscribe(aVoid -> {
290+
}, Throwable::printStackTrace);
304291
}
305292

306293
@Override

0 commit comments

Comments
 (0)