2017-11-16 19:18:11 +01:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
|
|
|
* 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>. */
|
|
|
|
|
2017-06-28 19:33:20 +02:00
|
|
|
package com.keylesspalace.tusky.db;
|
|
|
|
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
2018-12-17 15:25:35 +01:00
|
|
|
import androidx.room.ColumnInfo;
|
|
|
|
import androidx.room.Entity;
|
|
|
|
import androidx.room.PrimaryKey;
|
|
|
|
import androidx.room.TypeConverter;
|
|
|
|
import androidx.room.TypeConverters;
|
2017-06-28 19:33:20 +02:00
|
|
|
|
|
|
|
/**
|
2017-11-16 19:18:11 +01:00
|
|
|
* Toot model.
|
2017-06-28 19:33:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
@Entity
|
2017-11-16 19:18:11 +01:00
|
|
|
@TypeConverters(TootEntity.Converters.class)
|
2017-06-28 19:33:20 +02:00
|
|
|
public class TootEntity {
|
|
|
|
@PrimaryKey(autoGenerate = true)
|
2017-11-16 19:18:11 +01:00
|
|
|
private final int uid;
|
2017-06-28 19:33:20 +02:00
|
|
|
|
|
|
|
@ColumnInfo(name = "text")
|
2017-11-16 19:18:11 +01:00
|
|
|
private final String text;
|
2017-06-28 19:33:20 +02:00
|
|
|
|
2017-07-05 16:36:14 +02:00
|
|
|
@ColumnInfo(name = "urls")
|
2017-11-16 19:18:11 +01:00
|
|
|
private final String urls;
|
2017-07-05 16:36:14 +02:00
|
|
|
|
2018-11-11 19:25:45 +01:00
|
|
|
@ColumnInfo(name = "descriptions")
|
|
|
|
private final String descriptions;
|
|
|
|
|
2017-07-08 04:56:07 +02:00
|
|
|
@ColumnInfo(name = "contentWarning")
|
2017-11-16 19:18:11 +01:00
|
|
|
private final String contentWarning;
|
2017-07-08 04:56:07 +02:00
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
@ColumnInfo(name = "inReplyToId")
|
|
|
|
private final String inReplyToId;
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@ColumnInfo(name = "inReplyToText")
|
|
|
|
private final String inReplyToText;
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@ColumnInfo(name = "inReplyToUsername")
|
|
|
|
private final String inReplyToUsername;
|
|
|
|
|
|
|
|
@ColumnInfo(name = "visibility")
|
|
|
|
private final Status.Visibility visibility;
|
2017-06-28 19:33:20 +02:00
|
|
|
|
2018-11-11 19:25:45 +01:00
|
|
|
public TootEntity(int uid, String text, String urls, String descriptions, String contentWarning, String inReplyToId,
|
2017-11-16 19:18:11 +01:00
|
|
|
@Nullable String inReplyToText, @Nullable String inReplyToUsername,
|
|
|
|
Status.Visibility visibility) {
|
|
|
|
this.uid = uid;
|
2017-06-28 19:33:20 +02:00
|
|
|
this.text = text;
|
2017-11-16 19:18:11 +01:00
|
|
|
this.urls = urls;
|
2018-11-11 19:25:45 +01:00
|
|
|
this.descriptions = descriptions;
|
2017-11-16 19:18:11 +01:00
|
|
|
this.contentWarning = contentWarning;
|
|
|
|
this.inReplyToId = inReplyToId;
|
|
|
|
this.inReplyToText = inReplyToText;
|
|
|
|
this.inReplyToUsername = inReplyToUsername;
|
|
|
|
this.visibility = visibility;
|
2017-06-28 19:33:20 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
public String getText() {
|
|
|
|
return text;
|
2017-07-08 04:56:07 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
public String getContentWarning() {
|
|
|
|
return contentWarning;
|
2017-07-08 04:56:07 +02:00
|
|
|
}
|
|
|
|
|
2017-06-28 19:33:20 +02:00
|
|
|
public int getUid() {
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
2017-07-05 16:36:14 +02:00
|
|
|
public String getUrls() {
|
|
|
|
return urls;
|
|
|
|
}
|
|
|
|
|
2018-11-11 19:25:45 +01:00
|
|
|
public String getDescriptions() {
|
|
|
|
return descriptions;
|
|
|
|
}
|
|
|
|
|
2017-11-16 19:18:11 +01:00
|
|
|
public String getInReplyToId() {
|
|
|
|
return inReplyToId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public String getInReplyToText() {
|
|
|
|
return inReplyToText;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public String getInReplyToUsername() {
|
|
|
|
return inReplyToUsername;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Status.Visibility getVisibility() {
|
|
|
|
return visibility;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final class Converters {
|
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
public Status.Visibility visibilityFromInt(int number) {
|
|
|
|
return Status.Visibility.byNum(number);
|
|
|
|
}
|
|
|
|
|
|
|
|
@TypeConverter
|
Caching toots (#809)
* Initial timeline cache implementation
* Fix build/DI errors for caching
* Rename timeline entities tables. Add migration. Add DB scheme file.
* Fix uniqueness problem, change offline strategy, improve mapping
* Try to merge in new statuses, fix bottom loading, fix saving spans.
* Fix reblogs IDs, fix inserting elements from top
* Send one more request to get latest timeline statuses
* Give Timeline placeholders string id. Rewrite Either in Kotlin
* Initial placeholder implementation for caching
* Fix crash on removing overlap statuses
* Migrate counters to long
* Remove unused counters. Add minimal TimelineDAOTest
* Fix bug with placeholder ID
* Update cache in response to events. Refactor TimelineCases
* Fix crash, reduce number of placeholders
* Fix crash, fix filtering, improve placeholder handling
* Fix migration, add 8-9 migration test
* Fix initial timeline update, remove more placeholders
* Add cleanup for old statuses
* Fix cleanup
* Delete ExampleInstrumentedTest
* Improve timeline UX regarding caching
* Fix typos
* Fix initial timeline update
* Cleanup/fix initial timeline update
* Workaround for weird behavior of first post on initial tl update.
* Change counter types back to int
* Clear timeline cache on logout
* Fix loading when timeline is completely empty
* Fix androidx migration issues
* Fix tests
* Apply caching feedback
* Save account emojis to cache
* Fix warnings and bugs
2019-01-14 22:05:08 +01:00
|
|
|
public int intFromVisibility(Status.Visibility visibility) {
|
|
|
|
return visibility == null ? Status.Visibility.UNKNOWN.getNum() : visibility.getNum();
|
2017-11-16 19:18:11 +01:00
|
|
|
}
|
2017-07-05 16:36:14 +02:00
|
|
|
}
|
2017-06-28 19:33:20 +02:00
|
|
|
}
|