ChatDbDbEntity.kt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package com.sikey.commonservice.model.database
  2. import com.google.gson.annotations.SerializedName
  3. import com.sikey.commonservice.model.http.xplora.chat.MsgListInfo
  4. import com.sikey.commonservice.modules.WatchStateChangeImpl
  5. /**
  6. * Chat Message Type Attributes
  7. * Voice msgId, type, fileUrl, dur, state, create, update
  8. * Text msgId, type, text, state, create, update
  9. * Emoji msgId, type, emojiId, state, create, update
  10. * Photo msgId, type, fileUrl, state, create, update
  11. * Short video msgId, type, dur, coverUrl, videoUrl, state, create, update
  12. * Mp3 msgId, type, fileUrl, dur, state, create, update
  13. */
  14. data class ChatDbDbEntity(
  15. @SerializedName("_id")
  16. var _id: Long? = null,
  17. @SerializedName("msgId")
  18. var msgId: String? = null,
  19. /**
  20. * - 100 : Emoji
  21. * - 101 : Text
  22. * - 102 : Photo
  23. * - 103 : Voice
  24. * - 104 : Mp3
  25. * - 105 : Short video
  26. */
  27. @SerializedName("type")
  28. var type: String? = null,
  29. @SerializedName("text")
  30. var text: String? = null,
  31. @SerializedName("emojiId")
  32. var emojiId: String? = null,
  33. /**
  34. * -image
  35. * -audio
  36. * -cover
  37. */
  38. @SerializedName("fileUrl")
  39. var fileUrl: String? = null,
  40. /**
  41. * file name of music file, empty string if no name or not a music
  42. */
  43. @SerializedName("fileName")
  44. var fileName: String? = null,
  45. /**
  46. * -image
  47. * -audio
  48. * -cover
  49. *
  50. * MESSAGE_STATE_UNDOWNLOAD = 0;
  51. * MESSAGE_STATE_DOWNLOAD_ING = 1;
  52. * MESSAGE_STATE_NEED_DOWNLOAD = 2
  53. * MESSAGE_STATE_DOWNLOAD_DONE = uri;
  54. */
  55. @SerializedName("filePath")
  56. var filePath: String? = null,
  57. /**
  58. * -audio
  59. * -video
  60. */
  61. @SerializedName("dur")
  62. var dur: String? = null,
  63. /**
  64. * -video
  65. */
  66. @SerializedName("videoUrl")
  67. var videoUrl: String? = null,
  68. /**
  69. * MESSAGE_STATE_UNDOWNLOAD = 0;
  70. * MESSAGE_STATE_DOWNLOAD_ING = 1;
  71. * MESSAGE_STATE_NEED_DOWNLOAD = 2
  72. * MESSAGE_STATE_DOWNLOAD_DONE = uri;
  73. */
  74. @SerializedName("videoPath")
  75. var videoPath: String? = null,
  76. /**
  77. * Message status
  78. * - 0 : Unknown
  79. * - 1 : Delivered
  80. * - 2 : Read
  81. * - 3 : Failed
  82. */
  83. @SerializedName("state")
  84. var state: String? = null,
  85. /**
  86. * MESSAGE_STATE_UNREAD = 0;
  87. * MESSAGE_STATE_READ = 1;
  88. * MESSAGE_STATE_SEND_ING = 2;
  89. * MESSAGE_STATE_SEND_SUCCESS = 3;e
  90. * MESSAGE_STATE_SEND_FAIL = 4;
  91. * MESSAGE_STATE_DELETE = 5;
  92. * MESSAGE_STATE_UNKNOWN = 99;
  93. */
  94. @SerializedName("localState")
  95. var localState: String = "0",
  96. @SerializedName("senderUserId")
  97. var senderUserId: String? = null,
  98. @SerializedName("receiverId")
  99. var receiverId: String? = null,
  100. @SerializedName("create")
  101. var create: String? = null,
  102. @SerializedName("update")
  103. var update: String? = null,
  104. @SerializedName("fid")
  105. var fid: String? = null
  106. ) : BaseDbEntity() {
  107. fun from(info: com.sikey.commonservice.model.http.xplora.chat.BaseMsgInfo<*>): ChatDbDbEntity {
  108. msgId = info.msgId
  109. type = info.type
  110. text = info.text
  111. emojiId = info.emojiId
  112. fileUrl = if (info.type == "105") info.coverUrl else info.fileUrl
  113. dur = info.dur
  114. videoUrl = info.videoUrl
  115. state = info.state
  116. create = info.create
  117. update = info.update
  118. when (info) {
  119. is com.sikey.commonservice.model.http.xplora.chat.MsgInfo -> {
  120. senderUserId = info.senderUserId
  121. receiverId = WatchStateChangeImpl.watchBaseInfo.userId
  122. }
  123. is MsgListInfo -> {
  124. if (!info.incomming) {
  125. senderUserId = WatchStateChangeImpl.watchBaseInfo.userId
  126. }
  127. }
  128. }
  129. return this
  130. }
  131. }