Use /sources/stats in the home #133

Merged
AmineB merged 9 commits from davidoskky/ReaderForSelfoss-multiplatform:sources into master 2023-03-13 16:26:57 +00:00
4 changed files with 82 additions and 7 deletions
Showing only changes of commit a286d0c5cf - Show all commits

View File

@ -63,8 +63,79 @@ class SelfossModel {
fun isPublicModeEnabled() = publicMode ?: false
}
@Serializable
data class Source(
AmineB marked this conversation as resolved
Review

Source data class should be changed to an interface

 public interface Source {
        val id: Int
        val title: String
        var unread: Int?
        val icon: String?
    }

SourceDetail and SourceStats should implement it.

`Source` data class should be changed to an interface ``` public interface Source { val id: Int val title: String var unread: Int? val icon: String? } ``` `SourceDetail` and `SourceStats` should implement it.
val id: Int,
val title: String,
var unread: Int?,
var tags: List<String>?,
var spout: String?,
var error: String?,
var icon: String?,
var params: SourceParams?
AmineB marked this conversation as resolved
Review

I don't understand why this is needed ?

I don't understand why this is needed ?
) {
constructor(sourceDetail: SourceDetail) : this(
AmineB marked this conversation as resolved
Review

This should be an extension function fun SourceDetail.toSource(): Source

This should be an extension function `fun SourceDetail.toSource(): Source`
Review

Ignore this.

Ignore this.
id = sourceDetail.id,
AmineB marked this conversation as resolved
Review

This should be an "abstract" method.

This should be an "abstract" method.
title = sourceDetail.title,
unread = null,
tags = sourceDetail.tags,
spout = sourceDetail.spout,
error = sourceDetail.error,
icon = sourceDetail.icon,
params = sourceDetail.params
AmineB marked this conversation as resolved
Review

This should not be here.

This should not be here.
)
AmineB marked this conversation as resolved
Review

This should not be here.

This should not be here.
constructor(sourceStat: SourceStats) : this(
AmineB marked this conversation as resolved
Review

This should be an extension function fun SourceStats.toSource(): Source

This should be an extension function `fun SourceStats.toSource(): Source`
Review

Ignore this.

Ignore this.
id = sourceStat.id,
title = sourceStat.title,
unread = sourceStat.unread,
AmineB marked this conversation as resolved
Review

What are these two methods ?

What are these two methods ?
tags = null,
spout = null,
error = null,
icon = null,
params = null
)
fun update(sourceStat: SourceStats) {
if (this.id != sourceStat.id || this.title != sourceStat.title) {
throw Exception()
}
this.unread = sourceStat.unread
}
fun update(sourceDetail: SourceDetail) {
if (this.id != sourceDetail.id || this.title != sourceDetail.title) {
throw Exception()
}
this.tags = sourceDetail.tags
this.spout = sourceDetail.spout
AmineB marked this conversation as resolved
Review

SourceStats class should not contain SourceDetail update.

`SourceStats` class should not contain `SourceDetail` update.
this.error = sourceDetail.error
this.icon = sourceDetail.icon
this.params = sourceDetail.params
}
fun update(source: Source) {
if (this.id != source.id || this.title != source.title) {
throw Exception()
}
this.unread = source.unread
this.tags = source.tags
this.spout = source.spout
this.error = source.error
this.icon = source.icon
this.params = source.params
}
}
@Serializable
data class SourceStats(
val id: Int,
val title: String,
val unread: Int
)
@Serializable
data class SourceDetail(
val id: Int,
val title: String,
@Serializable(with = TagsListSerializer::class)

View File

@ -16,7 +16,8 @@ fun SOURCE.toView(): SelfossModel.Source =
SelfossModel.Source(
this.id.toInt(),
this.title,
this.tags.split(","),
this.unread?.toInt(),
this.tags?.split(","),
this.spout,
this.error,
this.icon,
@ -27,7 +28,8 @@ fun SelfossModel.Source.toEntity(): SOURCE =
SOURCE(
this.id.toString(),
this.title.getHtmlDecoded(),
this.tags.joinToString(","),
this.unread?.toLong(),
this.tags?.joinToString(","),
this.spout,
this.error,
this.icon.orEmpty(),

View File

@ -0,0 +1 @@
ALTER TABLE SOURCE ADD COLUMN `unread` INTEGER;
AmineB marked this conversation as resolved
Review

As unread is only in the public mode, let's not change this.

As `unread` is only in the public mode, let's not change this.

View File

@ -1,10 +1,11 @@
CREATE TABLE SOURCE (
`id` TEXT NOT NULL,
`title` TEXT NOT NULL,
`tags` TEXT NOT NULL,
`spout` TEXT NOT NULL,
`error` TEXT NOT NULL,
`icon` TEXT NOT NULL,
`unread` INTEGER,
AmineB marked this conversation as resolved
Review

As unread is only in the public mode, let's not change this.

As `unread` is only in the public mode, let's not change this.
`tags` TEXT,
`spout` TEXT,
`error` TEXT,
AmineB marked this conversation as resolved
Review

Why was everything changed to nullable ?

Why was everything changed to nullable ?
`icon` TEXT,
`url` TEXT,
PRIMARY KEY(`id`)
);