2018-03-03 13:24:03 +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>. */
|
|
|
|
|
|
|
|
package com.keylesspalace.tusky.entity
|
|
|
|
|
2019-08-28 19:54:46 +02:00
|
|
|
import android.text.SpannableStringBuilder
|
2018-03-03 13:24:03 +01:00
|
|
|
import android.text.Spanned
|
2019-08-28 19:54:46 +02:00
|
|
|
import android.text.style.URLSpan
|
2018-03-03 13:24:03 +01:00
|
|
|
import com.google.gson.annotations.SerializedName
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
data class Status(
|
|
|
|
var id: String,
|
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
|
|
|
var url: String?, // not present if it's reblog
|
2018-03-03 13:24:03 +01:00
|
|
|
val account: Account,
|
|
|
|
@SerializedName("in_reply_to_id") var inReplyToId: String?,
|
|
|
|
@SerializedName("in_reply_to_account_id") val inReplyToAccountId: String?,
|
|
|
|
val reblog: Status?,
|
|
|
|
val content: Spanned,
|
|
|
|
@SerializedName("created_at") val createdAt: Date,
|
|
|
|
val emojis: List<Emoji>,
|
|
|
|
@SerializedName("reblogs_count") val reblogsCount: Int,
|
|
|
|
@SerializedName("favourites_count") val favouritesCount: Int,
|
2019-06-02 21:23:18 +02:00
|
|
|
var reblogged: Boolean,
|
|
|
|
var favourited: Boolean,
|
2018-03-03 13:24:03 +01:00
|
|
|
var sensitive: Boolean,
|
|
|
|
@SerializedName("spoiler_text") val spoilerText: String,
|
|
|
|
val visibility: Visibility,
|
2019-04-21 15:16:39 +02:00
|
|
|
@SerializedName("media_attachments") var attachments: ArrayList<Attachment>,
|
2018-03-03 13:24:03 +01:00
|
|
|
val mentions: Array<Mention>,
|
2018-10-03 21:27:52 +02:00
|
|
|
val application: Application?,
|
2019-04-22 10:11:00 +02:00
|
|
|
var pinned: Boolean?,
|
2019-06-02 21:23:18 +02:00
|
|
|
val poll: Poll?,
|
2019-09-03 16:08:13 +02:00
|
|
|
val card: Card?,
|
|
|
|
val quote: Status?
|
2018-03-03 13:24:03 +01:00
|
|
|
) {
|
|
|
|
|
2019-02-12 19:22:37 +01:00
|
|
|
val actionableId: String
|
2018-03-03 13:24:03 +01:00
|
|
|
get() = reblog?.id ?: id
|
|
|
|
|
|
|
|
val actionableStatus: Status
|
|
|
|
get() = reblog ?: this
|
|
|
|
|
|
|
|
|
|
|
|
enum class Visibility(val num: Int) {
|
|
|
|
UNKNOWN(0),
|
|
|
|
@SerializedName("public")
|
|
|
|
PUBLIC(1),
|
|
|
|
@SerializedName("unlisted")
|
|
|
|
UNLISTED(2),
|
|
|
|
@SerializedName("private")
|
|
|
|
PRIVATE(3),
|
|
|
|
@SerializedName("direct")
|
2018-07-24 08:22:02 +02:00
|
|
|
DIRECT(4),
|
|
|
|
@SerializedName("unleakable")
|
|
|
|
UNLEAKABLE(5);
|
2018-03-03 13:24:03 +01:00
|
|
|
|
|
|
|
fun serverString(): String {
|
|
|
|
return when (this) {
|
|
|
|
PUBLIC -> "public"
|
|
|
|
UNLISTED -> "unlisted"
|
|
|
|
PRIVATE -> "private"
|
|
|
|
DIRECT -> "direct"
|
2018-07-24 08:22:02 +02:00
|
|
|
UNLEAKABLE -> "unleakable"
|
2018-03-03 13:24:03 +01:00
|
|
|
UNKNOWN -> "unknown"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun byNum(num: Int): Visibility {
|
|
|
|
return when (num) {
|
2018-07-24 08:22:02 +02:00
|
|
|
5 -> UNLEAKABLE
|
2018-03-03 13:24:03 +01:00
|
|
|
4 -> DIRECT
|
|
|
|
3 -> PRIVATE
|
|
|
|
2 -> UNLISTED
|
|
|
|
1 -> PUBLIC
|
|
|
|
0 -> UNKNOWN
|
|
|
|
else -> UNKNOWN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
fun byString(s: String): Visibility {
|
|
|
|
return when (s) {
|
|
|
|
"public" -> PUBLIC
|
|
|
|
"unlisted" -> UNLISTED
|
|
|
|
"private" -> PRIVATE
|
|
|
|
"direct" -> DIRECT
|
2018-07-24 08:22:02 +02:00
|
|
|
"unleakable" -> UNLEAKABLE
|
2018-03-03 13:24:03 +01:00
|
|
|
"unknown" -> UNKNOWN
|
|
|
|
else -> UNKNOWN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun rebloggingAllowed(): Boolean {
|
2018-05-28 21:29:06 +02:00
|
|
|
return (visibility != Visibility.DIRECT && visibility != Visibility.UNKNOWN)
|
2018-03-03 13:24:03 +01:00
|
|
|
}
|
|
|
|
|
2018-11-06 18:10:07 +01:00
|
|
|
fun isPinned(): Boolean {
|
|
|
|
return pinned ?: false
|
|
|
|
}
|
|
|
|
|
2019-08-28 19:54:46 +02:00
|
|
|
fun toDeletedStatus(): DeletedStatus {
|
|
|
|
return DeletedStatus(
|
|
|
|
text = getEditableText(),
|
|
|
|
inReplyToId = inReplyToId,
|
|
|
|
spoilerText = spoilerText,
|
|
|
|
visibility = visibility,
|
|
|
|
sensitive = sensitive,
|
|
|
|
attachments = attachments,
|
|
|
|
poll = poll,
|
|
|
|
createdAt = createdAt
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun getEditableText(): String {
|
|
|
|
val builder = SpannableStringBuilder(content)
|
|
|
|
for (span in content.getSpans(0, content.length, URLSpan::class.java)) {
|
|
|
|
val url = span.url
|
|
|
|
for ((_, url1, username) in mentions) {
|
|
|
|
if (url == url1) {
|
|
|
|
val start = builder.getSpanStart(span)
|
|
|
|
val end = builder.getSpanEnd(span)
|
|
|
|
builder.replace(start, end, "@$username")
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return builder.toString()
|
|
|
|
}
|
|
|
|
|
2018-03-03 13:24:03 +01:00
|
|
|
override fun equals(other: Any?): Boolean {
|
|
|
|
if (this === other) return true
|
|
|
|
if (other == null || javaClass != other.javaClass) return false
|
|
|
|
|
|
|
|
val status = other as Status?
|
|
|
|
return id == status?.id
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun hashCode(): Int {
|
|
|
|
return id.hashCode()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-02 21:23:18 +02:00
|
|
|
data class Mention (
|
|
|
|
val id: String,
|
|
|
|
val url: String,
|
|
|
|
@SerializedName("acct") val username: String,
|
|
|
|
@SerializedName("username") val localUsername: String
|
|
|
|
)
|
2018-03-03 13:24:03 +01:00
|
|
|
|
2019-06-02 21:23:18 +02:00
|
|
|
data class Application (
|
|
|
|
val name: String,
|
2019-06-22 08:05:55 +02:00
|
|
|
val website: String?
|
2019-06-02 21:23:18 +02:00
|
|
|
)
|
2018-03-03 13:24:03 +01:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val MAX_MEDIA_ATTACHMENTS = 4
|
2019-04-22 10:11:00 +02:00
|
|
|
const val MAX_POLL_OPTIONS = 4
|
2018-03-03 13:24:03 +01:00
|
|
|
}
|
|
|
|
}
|