From fab571d6808c8246b5ae965366bbe327d3d5b31d Mon Sep 17 00:00:00 2001 From: Emanuel Hiebeler Date: Fri, 24 Jan 2025 19:50:19 +0100 Subject: [PATCH] #136 change route to get posts by account, status if contentText not set confirm contentHtml to text --- .../pfpixelix/data/remote/PixelfedApi.kt | 4 ++-- .../pfpixelix/data/remote/dto/PostDto.kt | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/daniebeler/pfpixelix/data/remote/PixelfedApi.kt b/app/src/main/java/com/daniebeler/pfpixelix/data/remote/PixelfedApi.kt index 2c2f951d..9c032973 100644 --- a/app/src/main/java/com/daniebeler/pfpixelix/data/remote/PixelfedApi.kt +++ b/app/src/main/java/com/daniebeler/pfpixelix/data/remote/PixelfedApi.kt @@ -146,12 +146,12 @@ interface PixelfedApi { @Body body: RequestBody ): Call - @GET("api/v1/accounts/{accountid}/statuses?pe=1") + @GET("api/pixelfed/v1/accounts/{accountid}/statuses?pe=1") fun getPostsByAccountId( @Path("accountid") accountId: String, @Query("limit") limit: Int ): Call> - @GET("api/v1/accounts/{accountid}/statuses?pe=1") + @GET("api/pixelfed/v1/accounts/{accountid}/statuses?pe=1") fun getPostsByAccountId( @Path("accountid") accountId: String, @Query("max_id") maxId: String, diff --git a/app/src/main/java/com/daniebeler/pfpixelix/data/remote/dto/PostDto.kt b/app/src/main/java/com/daniebeler/pfpixelix/data/remote/dto/PostDto.kt index 5c1c70f7..99937cad 100644 --- a/app/src/main/java/com/daniebeler/pfpixelix/data/remote/dto/PostDto.kt +++ b/app/src/main/java/com/daniebeler/pfpixelix/data/remote/dto/PostDto.kt @@ -1,8 +1,11 @@ package com.daniebeler.pfpixelix.data.remote.dto +import android.util.Log import com.daniebeler.pfpixelix.domain.model.Post import com.google.gson.annotations.SerializedName +import org.jsoup.Jsoup +import org.jsoup.nodes.Document data class PostDto( @SerializedName("account") val account: AccountDto, @@ -53,7 +56,7 @@ data class PostDto( account = account.toModel(), tags = tags.map { it.toModel() }, favouritesCount = favouritesCount, - content = contentText ?: "", + content = contentText ?: htmlToText(content), replyCount = replyCount, createdAt = createdAt, url = url, @@ -69,4 +72,17 @@ data class PostDto( inReplyToId = inReplyToId ) } -} \ No newline at end of file +} + +private fun htmlToText(html: String): String { + val document = Jsoup.parse(html) + document.outputSettings(Document.OutputSettings().prettyPrint(false)) // Prevent auto formatting + document.select("br").append("\\n") // Replace
with newlines + document.select("p").prepend("\\n\\n") // Add double newline for paragraphs + + val text = document.text().replace("\\n", "\n") + val cleanedText = text.lines().joinToString("\n") { it.trimStart() } // Trim leading spaces + + Log.d("htmlToText", cleanedText) + return cleanedText.trim() +}