Timeline paging (#2238)
* first setup * network timeline paging / improvements * rename classes / move to correct package * remove unused class TimelineAdapter * some code cleanup * remove TimelineRepository, put mapper functions in TimelineTypeMappers.kt * add db migration * cleanup unused code * bugfix * make default timeline settings work again * fix pinning statuses from timeline * fix network timeline * respect account settings in NetworkTimelineRemoteMediator * respect account settings in NetworkTimelineRemoteMediator * update license headers * show error view when an error occurs * cleanup some todos * fix db migration * fix changing mediaPreviewEnabled setting * fix "load more" button appearing on top of timeline * fix filtering and other bugs * cleanup cache after 14 days * fix TimelineDAOTest * fix code formatting * add NetworkTimeline unit tests * add CachedTimeline unit tests * fix code formatting * move TimelineDaoTest to unit tests * implement removeAllByInstance for CachedTimelineViewModel * fix code formatting * fix bug in TimelineDao.deleteAllFromInstance * improve loading more statuses in NetworkTimelineViewModel * improve loading more statuses in NetworkTimelineViewModel * fix bug where empty state was shown too soon * reload top of cached timeline on app start * improve CachedTimelineRemoteMediator and Tests * improve cached timeline tests * fix some more todos * implement TimelineFragment.removeItem * fix ListStatusAccessibilityDelegate * fix crash in NetworkTimelineViewModel.loadMore * fix default state of collapsible statuses * fix default state of collapsible statuses -tests * fix showing/hiding media in the timeline * get rid of some not-null assertion operators in TimelineTypeMappers * fix tests * error handling in CachedTimelineViewModel.loadMore * keep local status state when refreshing cached statuses * keep local status state when refreshing network timeline statuses * show placeholder loading state in cached timeline * better comments, some code cleanup * add TimelineViewModelTest, improve code, fix bug * fix ktlint * fix voting in boosted polls * code improvement
This commit is contained in:
parent
224161caf1
commit
643e012b11
41 changed files with 4019 additions and 3146 deletions
|
|
@ -32,7 +32,7 @@ import java.io.File;
|
|||
|
||||
@Database(entities = { DraftEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class,
|
||||
TimelineAccountEntity.class, ConversationEntity.class
|
||||
}, version = 27)
|
||||
}, version = 28)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
|
||||
public abstract AccountDao accountDao();
|
||||
|
|
@ -400,4 +400,61 @@ public abstract class AppDatabase extends RoomDatabase {
|
|||
database.execSQL("ALTER TABLE `ConversationEntity` ADD COLUMN `s_muted` INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
};
|
||||
|
||||
public static final Migration MIGRATION_27_28 = new Migration(27, 28) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
|
||||
database.execSQL("DROP TABLE IF EXISTS `TimelineAccountEntity`");
|
||||
database.execSQL("DROP TABLE IF EXISTS `TimelineStatusEntity`");
|
||||
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS `TimelineAccountEntity` (" +
|
||||
"`serverId` TEXT NOT NULL," +
|
||||
"`timelineUserId` INTEGER NOT NULL," +
|
||||
"`localUsername` TEXT NOT NULL," +
|
||||
"`username` TEXT NOT NULL," +
|
||||
"`displayName` TEXT NOT NULL," +
|
||||
"`url` TEXT NOT NULL," +
|
||||
"`avatar` TEXT NOT NULL," +
|
||||
"`emojis` TEXT NOT NULL," +
|
||||
"`bot` INTEGER NOT NULL," +
|
||||
"PRIMARY KEY(`serverId`, `timelineUserId`) )");
|
||||
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS `TimelineStatusEntity` (" +
|
||||
"`serverId` TEXT NOT NULL," +
|
||||
"`url` TEXT," +
|
||||
"`timelineUserId` INTEGER NOT NULL," +
|
||||
"`authorServerId` TEXT," +
|
||||
"`inReplyToId` TEXT," +
|
||||
"`inReplyToAccountId` TEXT," +
|
||||
"`content` TEXT," +
|
||||
"`createdAt` INTEGER NOT NULL," +
|
||||
"`emojis` TEXT," +
|
||||
"`reblogsCount` INTEGER NOT NULL," +
|
||||
"`favouritesCount` INTEGER NOT NULL," +
|
||||
"`reblogged` INTEGER NOT NULL," +
|
||||
"`bookmarked` INTEGER NOT NULL," +
|
||||
"`favourited` INTEGER NOT NULL," +
|
||||
"`sensitive` INTEGER NOT NULL," +
|
||||
"`spoilerText` TEXT NOT NULL," +
|
||||
"`visibility` INTEGER NOT NULL," +
|
||||
"`attachments` TEXT," +
|
||||
"`mentions` TEXT," +
|
||||
"`application` TEXT," +
|
||||
"`reblogServerId` TEXT," +
|
||||
"`reblogAccountId` TEXT," +
|
||||
"`poll` TEXT," +
|
||||
"`muted` INTEGER," +
|
||||
"`expanded` INTEGER NOT NULL," +
|
||||
"`contentCollapsed` INTEGER NOT NULL," +
|
||||
"`contentShowing` INTEGER NOT NULL," +
|
||||
"`pinned` INTEGER NOT NULL," +
|
||||
"PRIMARY KEY(`serverId`, `timelineUserId`)," +
|
||||
"FOREIGN KEY(`authorServerId`, `timelineUserId`) REFERENCES `TimelineAccountEntity`(`serverId`, `timelineUserId`)" +
|
||||
"ON UPDATE NO ACTION ON DELETE NO ACTION )");
|
||||
|
||||
database.execSQL("CREATE INDEX IF NOT EXISTS `index_TimelineStatusEntity_authorServerId_timelineUserId`" +
|
||||
"ON `TimelineStatusEntity` (`authorServerId`, `timelineUserId`)");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,34 @@
|
|||
/* Copyright 2021 Tusky Contributors
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.db
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy.IGNORE
|
||||
import androidx.room.OnConflictStrategy.REPLACE
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import io.reactivex.rxjava3.core.Single
|
||||
|
||||
@Dao
|
||||
abstract class TimelineDao {
|
||||
|
||||
@Insert(onConflict = REPLACE)
|
||||
abstract fun insertAccount(timelineAccountEntity: TimelineAccountEntity): Long
|
||||
abstract suspend fun insertAccount(timelineAccountEntity: TimelineAccountEntity): Long
|
||||
|
||||
@Insert(onConflict = REPLACE)
|
||||
abstract fun insertStatus(timelineAccountEntity: TimelineStatusEntity): Long
|
||||
|
||||
@Insert(onConflict = IGNORE)
|
||||
abstract fun insertStatusIfNotThere(timelineAccountEntity: TimelineStatusEntity): Long
|
||||
abstract suspend fun insertStatus(timelineStatusEntity: TimelineStatusEntity): Long
|
||||
|
||||
@Query(
|
||||
"""
|
||||
|
|
@ -26,7 +36,7 @@ SELECT s.serverId, s.url, s.timelineUserId,
|
|||
s.authorServerId, s.inReplyToId, s.inReplyToAccountId, s.createdAt,
|
||||
s.emojis, s.reblogsCount, s.favouritesCount, s.reblogged, s.favourited, s.bookmarked, s.sensitive,
|
||||
s.spoilerText, s.visibility, s.mentions, s.application, s.reblogServerId,s.reblogAccountId,
|
||||
s.content, s.attachments, s.poll, s.muted,
|
||||
s.content, s.attachments, s.poll, s.muted, s.expanded, s.contentShowing, s.contentCollapsed, s.pinned,
|
||||
a.serverId as 'a_serverId', a.timelineUserId as 'a_timelineUserId',
|
||||
a.localUsername as 'a_localUsername', a.username as 'a_username',
|
||||
a.displayName as 'a_displayName', a.url as 'a_url', a.avatar as 'a_avatar',
|
||||
|
|
@ -34,51 +44,23 @@ a.emojis as 'a_emojis', a.bot as 'a_bot',
|
|||
rb.serverId as 'rb_serverId', rb.timelineUserId 'rb_timelineUserId',
|
||||
rb.localUsername as 'rb_localUsername', rb.username as 'rb_username',
|
||||
rb.displayName as 'rb_displayName', rb.url as 'rb_url', rb.avatar as 'rb_avatar',
|
||||
rb.emojis as'rb_emojis', rb.bot as 'rb_bot'
|
||||
rb.emojis as 'rb_emojis', rb.bot as 'rb_bot'
|
||||
FROM TimelineStatusEntity s
|
||||
LEFT JOIN TimelineAccountEntity a ON (s.timelineUserId = a.timelineUserId AND s.authorServerId = a.serverId)
|
||||
LEFT JOIN TimelineAccountEntity rb ON (s.timelineUserId = rb.timelineUserId AND s.reblogAccountId = rb.serverId)
|
||||
WHERE s.timelineUserId = :account
|
||||
AND (CASE WHEN :maxId IS NOT NULL THEN
|
||||
(LENGTH(s.serverId) < LENGTH(:maxId) OR LENGTH(s.serverId) == LENGTH(:maxId) AND s.serverId < :maxId)
|
||||
ELSE 1 END)
|
||||
AND (CASE WHEN :sinceId IS NOT NULL THEN
|
||||
(LENGTH(s.serverId) > LENGTH(:sinceId) OR LENGTH(s.serverId) == LENGTH(:sinceId) AND s.serverId > :sinceId)
|
||||
ELSE 1 END)
|
||||
ORDER BY LENGTH(s.serverId) DESC, s.serverId DESC
|
||||
LIMIT :limit"""
|
||||
ORDER BY LENGTH(s.serverId) DESC, s.serverId DESC"""
|
||||
)
|
||||
abstract fun getStatusesForAccount(account: Long, maxId: String?, sinceId: String?, limit: Int): Single<List<TimelineStatusWithAccount>>
|
||||
|
||||
@Transaction
|
||||
open fun insertInTransaction(
|
||||
status: TimelineStatusEntity,
|
||||
account: TimelineAccountEntity,
|
||||
reblogAccount: TimelineAccountEntity?
|
||||
) {
|
||||
insertAccount(account)
|
||||
reblogAccount?.let(this::insertAccount)
|
||||
insertStatus(status)
|
||||
}
|
||||
abstract fun getStatusesForAccount(account: Long): PagingSource<Int, TimelineStatusWithAccount>
|
||||
|
||||
@Query(
|
||||
"""DELETE FROM TimelineStatusEntity WHERE timelineUserId = :accountId AND
|
||||
(LENGTH(serverId) < LENGTH(:maxId) OR LENGTH(serverId) == LENGTH(:maxId) AND serverId < :maxId)
|
||||
(LENGTH(serverId) < LENGTH(:maxId) OR LENGTH(serverId) == LENGTH(:maxId) AND serverId <= :maxId)
|
||||
AND
|
||||
(LENGTH(serverId) > LENGTH(:minId) OR LENGTH(serverId) == LENGTH(:minId) AND serverId > :minId)
|
||||
(LENGTH(serverId) > LENGTH(:minId) OR LENGTH(serverId) == LENGTH(:minId) AND serverId >= :minId)
|
||||
"""
|
||||
)
|
||||
abstract fun deleteRange(accountId: Long, minId: String, maxId: String)
|
||||
|
||||
@Query(
|
||||
"""DELETE FROM TimelineStatusEntity WHERE authorServerId = null
|
||||
AND timelineUserId = :account AND
|
||||
(LENGTH(serverId) < LENGTH(:maxId) OR LENGTH(serverId) == LENGTH(:maxId) AND serverId < :maxId)
|
||||
AND
|
||||
(LENGTH(serverId) > LENGTH(:sinceId) OR LENGTH(serverId) == LENGTH(:sinceId) AND serverId > :sinceId)
|
||||
"""
|
||||
)
|
||||
abstract fun removeAllPlaceholdersBetween(account: Long, maxId: String, sinceId: String)
|
||||
abstract suspend fun deleteRange(accountId: Long, minId: String, maxId: String): Int
|
||||
|
||||
@Query(
|
||||
"""UPDATE TimelineStatusEntity SET favourited = :favourited
|
||||
|
|
@ -124,4 +106,40 @@ AND serverId = :statusId"""
|
|||
WHERE timelineUserId = :accountId AND (serverId = :statusId OR reblogServerId = :statusId)"""
|
||||
)
|
||||
abstract fun setVoted(accountId: Long, statusId: String, poll: String)
|
||||
|
||||
@Query(
|
||||
"""UPDATE TimelineStatusEntity SET expanded = :expanded
|
||||
WHERE timelineUserId = :accountId AND (serverId = :statusId OR reblogServerId = :statusId)"""
|
||||
)
|
||||
abstract fun setExpanded(accountId: Long, statusId: String, expanded: Boolean)
|
||||
|
||||
@Query(
|
||||
"""UPDATE TimelineStatusEntity SET contentShowing = :contentShowing
|
||||
WHERE timelineUserId = :accountId AND (serverId = :statusId OR reblogServerId = :statusId)"""
|
||||
)
|
||||
abstract fun setContentShowing(accountId: Long, statusId: String, contentShowing: Boolean)
|
||||
|
||||
@Query(
|
||||
"""UPDATE TimelineStatusEntity SET contentCollapsed = :contentCollapsed
|
||||
WHERE timelineUserId = :accountId AND (serverId = :statusId OR reblogServerId = :statusId)"""
|
||||
)
|
||||
abstract fun setContentCollapsed(accountId: Long, statusId: String, contentCollapsed: Boolean)
|
||||
|
||||
@Query(
|
||||
"""UPDATE TimelineStatusEntity SET pinned = :pinned
|
||||
WHERE timelineUserId = :accountId AND (serverId = :statusId OR reblogServerId = :statusId)"""
|
||||
)
|
||||
abstract fun setPinned(accountId: Long, statusId: String, pinned: Boolean)
|
||||
|
||||
@Query(
|
||||
"""DELETE FROM TimelineStatusEntity
|
||||
WHERE timelineUserId = :accountId AND authorServerId IN (
|
||||
SELECT serverId FROM TimelineAccountEntity WHERE username LIKE '%@' || :instanceDomain
|
||||
AND timelineUserId = :accountId
|
||||
)"""
|
||||
)
|
||||
abstract suspend fun deleteAllFromInstance(accountId: Long, instanceDomain: String)
|
||||
|
||||
@Query("SELECT serverId FROM TimelineStatusEntity WHERE timelineUserId = :accountId ORDER BY LENGTH(serverId) DESC, serverId DESC LIMIT 1")
|
||||
abstract suspend fun getTopId(accountId: Long): String?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
/* Copyright 2021 Tusky Contributors
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.db
|
||||
|
||||
import androidx.room.Embedded
|
||||
|
|
@ -50,15 +65,19 @@ data class TimelineStatusEntity(
|
|||
val bookmarked: Boolean,
|
||||
val favourited: Boolean,
|
||||
val sensitive: Boolean,
|
||||
val spoilerText: String?,
|
||||
val visibility: Status.Visibility?,
|
||||
val spoilerText: String,
|
||||
val visibility: Status.Visibility,
|
||||
val attachments: String?,
|
||||
val mentions: String?,
|
||||
val application: String?,
|
||||
val reblogServerId: String?, // if it has a reblogged status, it's id is stored here
|
||||
val reblogAccountId: String?,
|
||||
val poll: String?,
|
||||
val muted: Boolean?
|
||||
val muted: Boolean?,
|
||||
val expanded: Boolean, // used as the "loading" attribute when this TimelineStatusEntity is a placeholder
|
||||
val contentCollapsed: Boolean,
|
||||
val contentShowing: Boolean,
|
||||
val pinned: Boolean
|
||||
)
|
||||
|
||||
@Entity(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue