This commit is contained in:
Eric85710 2026-05-28 15:20:22 +08:00
parent 557e9d3537
commit 7038188236

View file

@ -289,4 +289,22 @@ class ChatRoomsRepository @Inject constructor(
Result.failure(e) Result.failure(e)
} }
} }
// 刪除訊息
suspend fun deleteMessage(roomId: String, messageId: String): Result<Unit> {
return try {
val response = api.deleteMessage(roomId, messageId)
if (response.isSuccessful) {
// 後端回傳 204 No Content 成功時沒有 body,直接回傳 Unit 即可
Result.success(Unit)
} else {
val errorMsg = response.errorBody()?.string() ?: "未知錯誤"
Result.failure(Exception("刪除訊息失敗,錯誤碼: ${response.code()}, 訊息: $errorMsg"))
}
} catch (e: Exception) {
// 捕捉網路斷線等異常狀況
Result.failure(e)
}
}
} }