Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.00 KB | None | 0 0
  1. socket.on(EVENT_NOTIFICATION_CHAT, { args ->
  2.                     var jsonObject = JSONObject(args[0].toString())
  3.                     var type: String = jsonObject.getString("type")
  4.                     when (type) {
  5.                         TYPE_CHAT_NEW_MESSAGE -> {
  6.                             var responseWrapper: SocketNotificationResponseWrapper<ChatMessage>
  7.                                     = SocketNotificationResponseWrapper()
  8.                             try {
  9.                                 responseWrapper = objectMapper.readValue(args[0].toString())
  10.                             } catch (throwable: IOException) {
  11.                                 socketPublishSubject?.onError(throwable)
  12.                                 throwable.printStackTrace()
  13.                             }
  14.                             responseWrapper.data?.let {
  15.                                 roomStore.chatDao().storeChatMessage(it)
  16.                                 chatSocketService.get().refreshMyChats()
  17.  
  18.                             }
  19.                         }
  20.                         TYPE_CHAT_IS_SEEN -> {
  21.                             var responseWrapper: SocketNotificationResponseWrapper<ChatMessage>
  22.                                     = SocketNotificationResponseWrapper()
  23.                             try {
  24.                                 responseWrapper = objectMapper.readValue(args[0].toString())
  25.                             } catch (throwable: IOException) {
  26.                                 socketPublishSubject?.onError(throwable)
  27.                                 throwable.printStackTrace()
  28.                             }
  29.                             responseWrapper.data?.let {
  30.                                 roomStore.chatDao().storeChatMessage(it)
  31.                             }
  32.                         }
  33.                         TYPE_CHAT_IS_TYPING -> {
  34.                             socketPublishSubject?.onNext(SocketEvent("Typing", args))
  35.                         }
  36.  
  37.                     }
  38.  
  39.                 })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement