Skip to content

Commit

Permalink
#136 change route to get posts by account, status if contentText not …
Browse files Browse the repository at this point in the history
…set confirm contentHtml to text
  • Loading branch information
Hiebeler committed Jan 24, 2025
1 parent 3ab6646 commit fab571d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ interface PixelfedApi {
@Body body: RequestBody
): Call<AccountDto>

@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<List<PostDto>>

@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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -69,4 +72,17 @@ data class PostDto(
inReplyToId = inReplyToId
)
}
}
}

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 <br> 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()
}

0 comments on commit fab571d

Please sign in to comment.