Handling author field.
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is failing

This commit is contained in:
aminecmi
2022-12-26 21:49:55 +01:00
parent a5e86bfb77
commit fe2410f719
9 changed files with 34 additions and 15 deletions

View File

@ -57,7 +57,6 @@ class SelfossModel {
val error: String,
val icon: String?
)
@Serializable
data class Item(
val id: Int,
@ -73,7 +72,8 @@ class SelfossModel {
val link: String,
val sourcetitle: String,
@Serializable(with = TagsListSerializer::class)
val tags: List<String>
val tags: List<String>,
val author: String
) {
// TODO: maybe find a better way to handle these kind of urls
fun getLinkDecoded(): String {
@ -102,8 +102,14 @@ class SelfossModel {
return stringUrl
}
fun sourceAndDateText(): String =
this.sourcetitle.getHtmlDecoded() + DateUtils.parseRelativeDate(this.datetime)
fun sourceAuthorAndDate(): String {
var txt = this.sourcetitle.getHtmlDecoded()
if (this.author.isNotEmpty()) {
txt += " (by ${this.author}) "
}
txt += DateUtils.parseRelativeDate(this.datetime)
return txt
}
fun toggleStar(): Item {
this.starred = !this.starred
@ -111,6 +117,7 @@ class SelfossModel {
}
}
// TODO: this seems to be super slow.
object TagsListSerializer : KSerializer<List<String>> {
override fun deserialize(decoder: Decoder): List<String> {

View File

@ -51,7 +51,8 @@ fun ITEM.toView(): SelfossModel.Item =
this.icon,
this.link,
this.sourcetitle,
this.tags.split(",")
this.tags.split(","),
this.author
)
fun SelfossModel.Item.toEntity(): ITEM =
@ -66,5 +67,6 @@ fun SelfossModel.Item.toEntity(): ITEM =
this.icon,
this.link,
this.sourcetitle.getHtmlDecoded(),
this.tags.joinToString(",")
this.tags.joinToString(","),
this.author
)

View File

@ -0,0 +1 @@
ALTER TABLE ITEM ADD COLUMN `author` TEXT NOT NULL;

View File

@ -10,6 +10,7 @@ CREATE TABLE ITEM (
`link` TEXT NOT NULL,
`sourcetitle` TEXT NOT NULL,
`tags` TEXT NOT NULL,
`author` TEXT NOT NULL,
PRIMARY KEY(`id`)
);