feat: show "Authored by" on posts when applicable

This commit is contained in:
Harsh Shandilya 2024-06-26 21:20:52 +05:30
parent 4ebb99bf7d
commit b132410282
6 changed files with 18 additions and 1 deletions

View file

@ -32,6 +32,11 @@ object SearchConverter : Converter<ResponseBody, List<LobstersPost>> {
val tags = elem.select("span.tags > a").map(Element::text)
val (commentCount, commentsUrl) = getCommentsData(elem.select("span.comments_label"))
val submitter = elem.select("div.byline > a.u-author").text()
val userIsAuthor =
(elem.select("div.byline > span").first()?.text() ?: "").contains(
"authored",
ignoreCase = true,
)
return LobstersPost(
shortId = shortId,
title = title,
@ -43,6 +48,7 @@ object SearchConverter : Converter<ResponseBody, List<LobstersPost>> {
// The value of these fields is irrelevant for our use case
createdAt = "",
description = "",
userIsAuthor = userIsAuthor,
)
}

View file

@ -40,6 +40,7 @@ class SearchApiTest {
submitter = "xenodium",
tags = listOf("ai", "emacs"),
description = "",
userIsAuthor = true,
),
LobstersPost(
shortId = "astcqf",
@ -52,6 +53,7 @@ class SearchApiTest {
submitter = "asteroid",
tags = listOf("ai"),
description = "",
userIsAuthor = false,
),
)
}