From 82bba7c028e6df51e598f031bed11f0740a4c412 Mon Sep 17 00:00:00 2001 From: Zetra Date: Fri, 16 Jun 2017 17:12:03 +0700 Subject: [PATCH] Refine handle event --- .../sdk/presenter/QiscusChatPresenter.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/chat/src/main/java/com/qiscus/sdk/presenter/QiscusChatPresenter.java b/chat/src/main/java/com/qiscus/sdk/presenter/QiscusChatPresenter.java index 5c36eb3df..b3f7a38ba 100644 --- a/chat/src/main/java/com/qiscus/sdk/presenter/QiscusChatPresenter.java +++ b/chat/src/main/java/com/qiscus/sdk/presenter/QiscusChatPresenter.java @@ -63,6 +63,9 @@ public class QiscusChatPresenter extends QiscusPresenter view.onUserTyping(event.getUser(), event.isTyping())); break; case DELIVERED: QiscusComment deliveredComment = Qiscus.getDataStore() @@ -544,15 +544,13 @@ private void handleEvent(QiscusChatRoomEvent event) { if (deliveredComment != null) { deliveredComment.setId(event.getCommentId()); updateLastDeliveredComment(deliveredComment); - doInIo(() -> { - if (QiscusComment.STATE_DELIVERED > deliveredComment.getState()) { - deliveredComment.setState(QiscusComment.STATE_DELIVERED); - Qiscus.getDataStore().update(deliveredComment); - } - }); + if (QiscusComment.STATE_DELIVERED > deliveredComment.getState()) { + deliveredComment.setState(QiscusComment.STATE_DELIVERED); + Qiscus.getDataStore().update(deliveredComment); + } } else { lastDeliveredCommentId.set(event.getCommentId()); - view.updateLastDeliveredComment(lastDeliveredCommentId.get()); + QiscusAndroidUtil.runOnUIThread(() -> view.updateLastDeliveredComment(lastDeliveredCommentId.get())); } break; case READ: @@ -561,16 +559,14 @@ private void handleEvent(QiscusChatRoomEvent event) { if (readComment != null) { readComment.setId(event.getCommentId()); updateLastReadComment(readComment); - doInIo(() -> { - if (QiscusComment.STATE_READ > readComment.getState()) { - readComment.setState(QiscusComment.STATE_READ); - Qiscus.getDataStore().update(readComment); - } - }); + if (QiscusComment.STATE_READ > readComment.getState()) { + readComment.setState(QiscusComment.STATE_READ); + Qiscus.getDataStore().update(readComment); + } } else { lastReadCommentId.set(event.getCommentId()); lastDeliveredCommentId.set(lastReadCommentId.get()); - view.updateLastReadComment(lastReadCommentId.get()); + QiscusAndroidUtil.runOnUIThread(() -> view.updateLastReadComment(lastReadCommentId.get())); } break; }