-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(read-state): rename persisted isUnread fields to isRead #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,8 @@ data class Article( | |
| var feedId: String, | ||
| @field:ColumnInfo(index = true) | ||
| var accountId: Int, | ||
| @field:ColumnInfo | ||
| var isUnread: Boolean = true, | ||
| @field:ColumnInfo(name = "isUnread") | ||
| var isRead: Boolean = false, | ||
|
Comment on lines
+44
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| @field:ColumnInfo | ||
| var isStarred: Boolean = false, | ||
| @field:ColumnInfo | ||
|
|
@@ -53,10 +53,4 @@ data class Article( | |
|
|
||
| @Ignore | ||
| var dateString: String? = null | ||
|
|
||
| var isRead: Boolean | ||
| get() = !isUnread | ||
| set(value) { | ||
| isUnread = !value | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,14 +10,8 @@ import androidx.room.PrimaryKey | |
| data class ArticleMeta( | ||
| @field:PrimaryKey | ||
| var id: String, | ||
| @field:ColumnInfo | ||
| var isUnread: Boolean = true, | ||
| @field:ColumnInfo(name = "isUnread") | ||
| var isRead: Boolean = false, | ||
|
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| @field:ColumnInfo | ||
| var isStarred: Boolean = false, | ||
| ) { | ||
| var isRead: Boolean | ||
| get() = !isUnread | ||
| set(value) { | ||
| isUnread = !value | ||
| } | ||
| } | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,8 @@ data class PendingReadStateOp( | |
| val accountId: Int, | ||
| @ColumnInfo | ||
| val feedId: String, | ||
| @ColumnInfo | ||
| val isUnread: Boolean, | ||
| @ColumnInfo(name = "isUnread") | ||
| val isRead: Boolean, | ||
|
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| @ColumnInfo | ||
| val updatedAt: Date = Date(), | ||
| ) { | ||
| val isRead: Boolean | ||
| get() = !isUnread | ||
| } | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,15 +36,15 @@ interface ArticleDao { | |
|
|
||
| @Query( | ||
| """ | ||
| UPDATE article SET isUnread = :storedUnread | ||
| UPDATE article SET isUnread = NOT :isRead | ||
| WHERE accountId = :accountId | ||
| AND id in (:ids) | ||
| """ | ||
| ) | ||
| fun markAsReadByIdSet( | ||
| accountId: Int, | ||
| ids: Set<String>, | ||
| storedUnread: Boolean, | ||
| isRead: Boolean, | ||
| ): Int | ||
|
|
||
| @Transaction | ||
|
|
@@ -92,7 +92,7 @@ interface ArticleDao { | |
| AND feedId IN ( | ||
| SELECT id FROM feed WHERE groupId = :groupId | ||
| ) | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| AND ( | ||
| title LIKE '%' || :text || '%' | ||
| OR shortDescription LIKE '%' || :text || '%' | ||
|
|
@@ -107,7 +107,7 @@ interface ArticleDao { | |
| accountId: Int, | ||
| text: String, | ||
| groupId: String, | ||
| isUnread: Boolean, | ||
| isRead: Boolean, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parameter has been renamed to |
||
| sortAscending: Boolean = false | ||
| ): PagingSource<Int, ArticleWithFeed> | ||
|
|
||
|
|
@@ -166,7 +166,7 @@ interface ArticleDao { | |
| SELECT * FROM article | ||
| WHERE accountId = :accountId | ||
| AND feedId = :feedId | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| AND ( | ||
| title LIKE '%' || :text || '%' | ||
| OR shortDescription LIKE '%' || :text || '%' | ||
|
|
@@ -181,7 +181,7 @@ interface ArticleDao { | |
| accountId: Int, | ||
| text: String, | ||
| feedId: String, | ||
| isUnread: Boolean, | ||
| isRead: Boolean, | ||
| sortAscending: Boolean = false | ||
| ): PagingSource<Int, ArticleWithFeed> | ||
|
|
||
|
|
@@ -235,7 +235,7 @@ interface ArticleDao { | |
| """ | ||
| SELECT * FROM article | ||
| WHERE accountId = :accountId | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| AND ( | ||
| title LIKE '%' || :text || '%' | ||
| OR shortDescription LIKE '%' || :text || '%' | ||
|
|
@@ -247,7 +247,7 @@ interface ArticleDao { | |
| """ | ||
| ) | ||
| fun searchArticleWhenIsUnread( | ||
| accountId: Int, text: String, isUnread: Boolean, sortAscending: Boolean = false | ||
| accountId: Int, text: String, isRead: Boolean, sortAscending: Boolean = false | ||
| ): PagingSource<Int, ArticleWithFeed> | ||
|
|
||
| @Transaction | ||
|
|
@@ -321,67 +321,67 @@ interface ArticleDao { | |
| @Transaction | ||
| @Query( | ||
| """ | ||
| UPDATE article SET isUnread = :storedUnread | ||
| UPDATE article SET isUnread = NOT :isRead | ||
| WHERE accountId = :accountId | ||
| AND date < :before | ||
| AND isUnread != :storedUnread | ||
| AND isUnread != NOT :isRead | ||
| """ | ||
| ) | ||
| suspend fun markAllAsRead( | ||
| accountId: Int, | ||
| storedUnread: Boolean, | ||
| isRead: Boolean, | ||
| before: Date, | ||
| ) | ||
|
|
||
| @Transaction | ||
| @Query( | ||
| """ | ||
| UPDATE article SET isUnread = :storedUnread | ||
| UPDATE article SET isUnread = NOT :isRead | ||
| WHERE feedId IN ( | ||
| SELECT id FROM feed | ||
| WHERE groupId = :groupId | ||
| ) | ||
| AND accountId = :accountId | ||
| AND isUnread != :storedUnread | ||
| AND isUnread != NOT :isRead | ||
| AND date < :before | ||
| """ | ||
| ) | ||
| suspend fun markAllAsReadByGroupId( | ||
| accountId: Int, | ||
| groupId: String, | ||
| storedUnread: Boolean, | ||
| isRead: Boolean, | ||
| before: Date, | ||
| ) | ||
|
|
||
| @Transaction | ||
| @Query( | ||
| """ | ||
| UPDATE article SET isUnread = :storedUnread | ||
| UPDATE article SET isUnread = NOT :isRead | ||
| WHERE feedId = :feedId | ||
| AND accountId = :accountId | ||
| AND isUnread != :storedUnread | ||
| AND isUnread != NOT :isRead | ||
| AND date < :before | ||
| """ | ||
| ) | ||
| suspend fun markAllAsReadByFeedId( | ||
| accountId: Int, | ||
| feedId: String, | ||
| storedUnread: Boolean, | ||
| isRead: Boolean, | ||
| before: Date, | ||
| ) | ||
|
|
||
| @Transaction | ||
| @Query( | ||
| """ | ||
| UPDATE article SET isUnread = :storedUnread | ||
| UPDATE article SET isUnread = NOT :isRead | ||
| WHERE id = :articleId | ||
| AND accountId = :accountId | ||
| """ | ||
| ) | ||
| suspend fun markAsReadByArticleId( | ||
| accountId: Int, | ||
| articleId: String, | ||
| storedUnread: Boolean, | ||
| isRead: Boolean, | ||
| ) | ||
|
|
||
| @Query( | ||
|
|
@@ -436,14 +436,14 @@ interface ArticleDao { | |
| """ | ||
| SELECT feedId, COUNT(*) AS important | ||
| FROM article | ||
| WHERE isUnread = :isUnread | ||
| WHERE isUnread = NOT :isRead | ||
| AND accountId = :accountId | ||
| GROUP BY feedId | ||
| """ | ||
| ) | ||
| fun queryImportantCountWhenIsUnread( | ||
| accountId: Int, | ||
| isUnread: Boolean, | ||
| isRead: Boolean, | ||
| ): Flow<Map<@MapColumn("feedId") String, @MapColumn("important") Int>> | ||
|
|
||
| @Transaction | ||
|
|
@@ -507,15 +507,15 @@ interface ArticleDao { | |
| @Query( | ||
| """ | ||
| SELECT * FROM article | ||
| WHERE isUnread = :isUnread | ||
| WHERE isUnread = NOT :isRead | ||
| AND accountId = :accountId | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN date END ASC, | ||
| CASE WHEN :sortAscending = 0 THEN date END DESC | ||
| """ | ||
| ) | ||
| fun queryArticleWithFeedWhenIsUnread( | ||
| accountId: Int, isUnread: Boolean, sortAscending: Boolean = false | ||
| accountId: Int, isRead: Boolean, sortAscending: Boolean = false | ||
| ): PagingSource<Int, ArticleWithFeed> | ||
|
|
||
| @Transaction | ||
|
|
@@ -572,15 +572,15 @@ interface ArticleDao { | |
| LEFT JOIN feed AS b ON b.id = a.feedId | ||
| LEFT JOIN `group` AS c ON c.id = b.groupId | ||
| WHERE c.id = :groupId | ||
| AND a.isUnread = :isUnread | ||
| AND a.isUnread = NOT :isRead | ||
| AND a.accountId = :accountId | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN a.date END ASC, | ||
| CASE WHEN :sortAscending = 0 THEN a.date END DESC | ||
| """ | ||
| ) | ||
| fun queryArticleWithFeedByGroupIdWhenIsUnread( | ||
| accountId: Int, groupId: String, isUnread: Boolean, sortAscending: Boolean = false | ||
| accountId: Int, groupId: String, isRead: Boolean, sortAscending: Boolean = false | ||
| ): PagingSource<Int, ArticleWithFeed> | ||
|
|
||
| @Transaction | ||
|
|
@@ -619,15 +619,15 @@ interface ArticleDao { | |
| """ | ||
| SELECT * FROM article | ||
| WHERE feedId = :feedId | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| AND accountId = :accountId | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN date END ASC, | ||
| CASE WHEN :sortAscending = 0 THEN date END DESC | ||
| """ | ||
| ) | ||
| fun queryArticleWithFeedByFeedIdWhenIsUnread( | ||
| accountId: Int, feedId: String, isUnread: Boolean, sortAscending: Boolean = false | ||
| accountId: Int, feedId: String, isRead: Boolean, sortAscending: Boolean = false | ||
| ): PagingSource<Int, ArticleWithFeed> | ||
|
|
||
|
|
||
|
|
@@ -704,14 +704,14 @@ interface ArticleDao { | |
| """ | ||
| SELECT id, isUnread, isStarred FROM article | ||
| WHERE accountId = :accountId | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN date END ASC, | ||
| CASE WHEN :sortAscending = 0 THEN date END DESC | ||
| """ | ||
| ) | ||
| fun queryMetadataAll( | ||
| accountId: Int, isUnread: Boolean, sortAscending: Boolean = false | ||
| accountId: Int, isRead: Boolean, sortAscending: Boolean = false | ||
| ): List<ArticleMeta> | ||
|
|
||
| @Transaction | ||
|
|
@@ -734,15 +734,15 @@ interface ArticleDao { | |
| """ | ||
| SELECT id, isUnread, isStarred FROM article | ||
| WHERE accountId = :accountId | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| AND date < :before | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN date END ASC, | ||
| CASE WHEN :sortAscending = 0 THEN date END DESC | ||
| """ | ||
| ) | ||
| fun queryMetadataAll( | ||
| accountId: Int, isUnread: Boolean, before: Date, sortAscending: Boolean = false | ||
| accountId: Int, isRead: Boolean, before: Date, sortAscending: Boolean = false | ||
| ): List<ArticleMeta> | ||
|
|
||
| @Transaction | ||
|
|
@@ -751,14 +751,14 @@ interface ArticleDao { | |
| SELECT id, isUnread, isStarred FROM article | ||
| WHERE accountId = :accountId | ||
| AND feedId = :feedId | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN date END ASC, | ||
| CASE WHEN :sortAscending = 0 THEN date END DESC | ||
| """ | ||
| ) | ||
| fun queryMetadataByFeedId( | ||
| accountId: Int, feedId: String, isUnread: Boolean, sortAscending: Boolean = false | ||
| accountId: Int, feedId: String, isRead: Boolean, sortAscending: Boolean = false | ||
| ): List<ArticleMeta> | ||
|
|
||
| @Transaction | ||
|
|
@@ -767,7 +767,7 @@ interface ArticleDao { | |
| SELECT id, isUnread, isStarred FROM article | ||
| WHERE accountId = :accountId | ||
| AND feedId = :feedId | ||
| AND isUnread = :isUnread | ||
| AND isUnread = NOT :isRead | ||
| AND date < :before | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN date END ASC, | ||
|
|
@@ -777,7 +777,7 @@ interface ArticleDao { | |
| fun queryMetadataByFeedId( | ||
| accountId: Int, | ||
| feedId: String, | ||
| isUnread: Boolean, | ||
| isRead: Boolean, | ||
| before: Date, | ||
| sortAscending: Boolean = false | ||
| ): List<ArticleMeta> | ||
|
|
@@ -791,14 +791,14 @@ interface ArticleDao { | |
| LEFT JOIN `group` AS c ON c.id = b.groupId | ||
| WHERE c.id = :groupId | ||
| AND a.accountId = :accountId | ||
| AND a.isUnread = :isUnread | ||
| AND a.isUnread = NOT :isRead | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN a.date END ASC, | ||
| CASE WHEN :sortAscending = 0 THEN a.date END DESC | ||
| """ | ||
| ) | ||
| fun queryMetadataByGroupIdWhenIsUnread( | ||
| accountId: Int, groupId: String, isUnread: Boolean, sortAscending: Boolean = false | ||
| accountId: Int, groupId: String, isRead: Boolean, sortAscending: Boolean = false | ||
| ): List<ArticleMeta> | ||
|
|
||
| @Transaction | ||
|
|
@@ -810,7 +810,7 @@ interface ArticleDao { | |
| LEFT JOIN `group` AS c ON c.id = b.groupId | ||
| WHERE c.id = :groupId | ||
| AND a.accountId = :accountId | ||
| AND a.isUnread = :isUnread | ||
| AND a.isUnread = NOT :isRead | ||
| AND a.date < :before | ||
| ORDER BY | ||
| CASE WHEN :sortAscending = 1 THEN a.date END ASC, | ||
|
|
@@ -820,7 +820,7 @@ interface ArticleDao { | |
| fun queryMetadataByGroupIdWhenIsUnread( | ||
| accountId: Int, | ||
| groupId: String, | ||
| isUnread: Boolean, | ||
| isRead: Boolean, | ||
| before: Date, | ||
| sortAscending: Boolean = false | ||
| ): List<ArticleMeta> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces a logic inversion bug. By renaming the field to
isReadbut mapping it to the existingisUnreaddatabase column via@ColumnInfo(name = "isUnread"), the boolean logic is flipped upon persistence.In the database,
isUnread = 1(true) represents an unread article. When Room loads this value into the newisReadfield, it will setisRead = true, meaning the application will treat unread articles as read.To fix this while avoiding database migrations, you should keep the underlying field named
isUnread(matching the database semantics) and use a computed property forisRead(reverting the changes in lines 57-61). If you truly want to rename the persisted field, you must provide a database migration to rename the column and invert all existing boolean values (isRead = NOT isUnread).