dm-47
This commit is contained in:
parent
ef57a7b440
commit
bb096e8531
3 changed files with 56 additions and 29 deletions
|
|
@ -110,4 +110,12 @@ interface TecnologiaApi {
|
|||
@Path("room_id") roomId: String,
|
||||
@Part file: MultipartBody.Part
|
||||
): Response<Message>
|
||||
|
||||
//get emoji reaction
|
||||
@GET("api/dm/{room_id}/messages/{msg_id}/reactions/{emoji}")
|
||||
suspend fun getMessageReactionUsers(
|
||||
@Path("room_id") roomId: String,
|
||||
@Path("msg_id") msgId: String,
|
||||
@Path("emoji") emoji: String
|
||||
): Response<MessageReactionUsersResponse>
|
||||
}
|
||||
|
|
@ -51,18 +51,6 @@ data class LastMessage(
|
|||
@Json(name = "forwarded_from_id") val forwardedFromId: String?,
|
||||
@Json(name = "forwarded_from_room_id") val forwardedFromRoomId: String?
|
||||
)
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Attachment(
|
||||
@Json(name = "filename") val filename: String,
|
||||
@Json(name = "mime_type") val mimeType: String,
|
||||
@Json(name = "size") val size: Long
|
||||
)
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Reaction(
|
||||
@Json(name = "emoji") val emoji: String = "",
|
||||
@Json(name = "count") val count: Int = 0,
|
||||
@Json(name = "me_reacted") val meReacted: Boolean = false
|
||||
)
|
||||
|
||||
val Partner.fullContactAvatarUrl: Any
|
||||
get() = if (avatarUrl.isNullOrBlank()) {
|
||||
|
|
@ -76,6 +64,22 @@ val Partner.fullContactAvatarUrl: Any
|
|||
|
||||
|
||||
//Message DM
|
||||
// 抽到最外層,讓 ChatRoom、LastMessage、Message 共同使用
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Attachment(
|
||||
@Json(name = "filename") val filename: String,
|
||||
@Json(name = "mime_type") val mimeType: String,
|
||||
@Json(name = "size") val size: Long
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Reaction(
|
||||
@Json(name = "emoji") val emoji: String = "",
|
||||
@Json(name = "count") val count: Int = 0,
|
||||
@Json(name = "me_reacted") val meReacted: Boolean = false
|
||||
)
|
||||
|
||||
// --- Message DM 相關 ---
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class MessageResponse(
|
||||
@Json(name = "has_more") val hasMore: Boolean,
|
||||
|
|
@ -97,27 +101,14 @@ data class Message(
|
|||
@Json(name = "is_edited") val isEdited: Boolean,
|
||||
@Json(name = "is_deleted") val isDeleted: Boolean,
|
||||
@Json(name = "reply_to_id") val replyToId: String? = null,
|
||||
@kotlin.jvm.Transient // 讓某些序列化工具忽略,Moshi 預設也會忽略沒有 @Json 的 var
|
||||
@kotlin.jvm.Transient
|
||||
var repliedMessage: Message? = null,
|
||||
|
||||
@Json(name = "forwarded_from_id") val forwardedFromId: String? = null,
|
||||
@Json(name = "forwarded_from_room_id") val forwardedFromRoomId: String? = null,
|
||||
@Json(name = "attachment") val attachment: Attachment? = null,
|
||||
@Json(name = "reactions") val reactions: List<Reaction>? = emptyList()
|
||||
){
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Attachment(
|
||||
@Json(name = "filename") val filename: String,
|
||||
@Json(name = "mime_type") val mimeType: String,
|
||||
@Json(name = "size") val size: Long
|
||||
)
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Reaction(
|
||||
@Json(name = "emoji") val emoji: String,
|
||||
@Json(name = "count") val count: Int,
|
||||
@Json(name = "me_reacted") val meReacted: Boolean
|
||||
)
|
||||
}
|
||||
@Json(name = "attachment") val attachment: Attachment? = null, // 直接使用外層的 Attachment
|
||||
@Json(name = "reactions") val reactions: List<Reaction>? = emptyList() // 直接使用外層的 Reaction
|
||||
)
|
||||
|
||||
//send message
|
||||
@JsonClass(generateAdapter = true)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.provider.OpenableColumns
|
|||
import com.example.login_v3.data.api.TecnologiaApi
|
||||
import com.example.login_v3.data.api.api_class.ChatRoom
|
||||
import com.example.login_v3.data.api.api_class.Message
|
||||
import com.example.login_v3.data.api.api_class.MessageReactionUsersResponse
|
||||
import com.example.login_v3.data.api.api_class.MessageResponse
|
||||
import com.example.login_v3.data.api.api_class.RoomListResponse
|
||||
import com.example.login_v3.data.api.api_class.SendMessageRequest
|
||||
|
|
@ -219,4 +220,31 @@ class ChatRoomsRepository @Inject constructor(
|
|||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
|
||||
// 取得點擊特定訊息中某個 Emoji 的使用者清單
|
||||
suspend fun getMessageReactionUsers(
|
||||
roomId: String,
|
||||
messageId: String,
|
||||
emoji: String
|
||||
): Result<MessageReactionUsersResponse> {
|
||||
return try {
|
||||
// 呼叫 API
|
||||
val response = api.getMessageReactionUsers(roomId, messageId, emoji)
|
||||
|
||||
if (response.isSuccessful) {
|
||||
val body = response.body()
|
||||
if (body != null) {
|
||||
Result.success(body)
|
||||
} else {
|
||||
Result.failure(Exception("回應成功但回應身體為空 (Empty response body)"))
|
||||
}
|
||||
} else {
|
||||
val errorMsg = response.errorBody()?.string() ?: "未知錯誤"
|
||||
Result.failure(Exception("取得反應使用者失敗,錯誤碼: ${response.code()}, 訊息: $errorMsg"))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// 捕捉網路斷線等異常狀況
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue