2021-06-17 18:54:56 +02:00
|
|
|
/* Copyright 2021 Tusky Contributors
|
2019-02-12 19:22:37 +01:00
|
|
|
*
|
|
|
|
* 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.components.conversation
|
|
|
|
|
|
|
|
import android.text.Spanned
|
|
|
|
import androidx.room.Embedded
|
|
|
|
import androidx.room.Entity
|
|
|
|
import androidx.room.TypeConverters
|
|
|
|
import com.keylesspalace.tusky.db.Converters
|
2021-06-17 18:54:56 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Attachment
|
|
|
|
import com.keylesspalace.tusky.entity.Conversation
|
|
|
|
import com.keylesspalace.tusky.entity.Emoji
|
2022-02-25 18:56:21 +01:00
|
|
|
import com.keylesspalace.tusky.entity.HashTag
|
2021-06-17 18:54:56 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Poll
|
|
|
|
import com.keylesspalace.tusky.entity.Status
|
2022-03-15 21:34:57 +01:00
|
|
|
import com.keylesspalace.tusky.entity.TimelineAccount
|
2019-07-19 20:47:30 +02:00
|
|
|
import com.keylesspalace.tusky.util.shouldTrimStatus
|
2021-06-17 18:54:56 +02:00
|
|
|
import java.util.Date
|
2019-02-12 19:22:37 +01:00
|
|
|
|
2021-06-28 21:13:24 +02:00
|
|
|
@Entity(primaryKeys = ["id", "accountId"])
|
2019-02-12 19:22:37 +01:00
|
|
|
@TypeConverters(Converters::class)
|
|
|
|
data class ConversationEntity(
|
2021-06-17 18:54:56 +02:00
|
|
|
val accountId: Long,
|
|
|
|
val id: String,
|
|
|
|
val accounts: List<ConversationAccountEntity>,
|
|
|
|
val unread: Boolean,
|
|
|
|
@Embedded(prefix = "s_") val lastStatus: ConversationStatusEntity
|
2019-02-12 19:22:37 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
data class ConversationAccountEntity(
|
2021-06-17 18:54:56 +02:00
|
|
|
val id: String,
|
|
|
|
val username: String,
|
|
|
|
val displayName: String,
|
|
|
|
val avatar: String,
|
|
|
|
val emojis: List<Emoji>
|
2019-02-12 19:22:37 +01:00
|
|
|
) {
|
2022-03-15 21:34:57 +01:00
|
|
|
fun toAccount(): TimelineAccount {
|
|
|
|
return TimelineAccount(
|
2021-06-17 18:54:56 +02:00
|
|
|
id = id,
|
|
|
|
username = username,
|
|
|
|
displayName = displayName,
|
2022-03-15 21:34:57 +01:00
|
|
|
url = "",
|
2021-06-17 18:54:56 +02:00
|
|
|
avatar = avatar,
|
|
|
|
emojis = emojis,
|
|
|
|
localUsername = "",
|
2019-02-12 19:22:37 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@TypeConverters(Converters::class)
|
|
|
|
data class ConversationStatusEntity(
|
2021-06-17 18:54:56 +02:00
|
|
|
val id: String,
|
|
|
|
val url: String?,
|
|
|
|
val inReplyToId: String?,
|
|
|
|
val inReplyToAccountId: String?,
|
|
|
|
val account: ConversationAccountEntity,
|
|
|
|
val content: Spanned,
|
|
|
|
val createdAt: Date,
|
|
|
|
val emojis: List<Emoji>,
|
|
|
|
val favouritesCount: Int,
|
|
|
|
val favourited: Boolean,
|
|
|
|
val bookmarked: Boolean,
|
|
|
|
val sensitive: Boolean,
|
|
|
|
val spoilerText: String,
|
|
|
|
val attachments: ArrayList<Attachment>,
|
|
|
|
val mentions: List<Status.Mention>,
|
2022-02-27 20:16:41 +01:00
|
|
|
val tags: List<HashTag>?,
|
2021-06-17 18:54:56 +02:00
|
|
|
val showingHiddenContent: Boolean,
|
|
|
|
val expanded: Boolean,
|
|
|
|
val collapsible: Boolean,
|
|
|
|
val collapsed: Boolean,
|
|
|
|
val muted: Boolean,
|
|
|
|
val poll: Poll?
|
2019-02-12 19:22:37 +01:00
|
|
|
) {
|
|
|
|
/** its necessary to override this because Spanned.equals does not work as expected */
|
|
|
|
override fun equals(other: Any?): Boolean {
|
|
|
|
if (this === other) return true
|
|
|
|
if (javaClass != other?.javaClass) return false
|
|
|
|
|
|
|
|
other as ConversationStatusEntity
|
|
|
|
|
|
|
|
if (id != other.id) return false
|
|
|
|
if (url != other.url) return false
|
|
|
|
if (inReplyToId != other.inReplyToId) return false
|
|
|
|
if (inReplyToAccountId != other.inReplyToAccountId) return false
|
|
|
|
if (account != other.account) return false
|
2022-03-15 21:34:57 +01:00
|
|
|
if (content.toString() != other.content.toString()) return false
|
2019-02-12 19:22:37 +01:00
|
|
|
if (createdAt != other.createdAt) return false
|
|
|
|
if (emojis != other.emojis) return false
|
|
|
|
if (favouritesCount != other.favouritesCount) return false
|
|
|
|
if (favourited != other.favourited) return false
|
|
|
|
if (sensitive != other.sensitive) return false
|
|
|
|
if (spoilerText != other.spoilerText) return false
|
|
|
|
if (attachments != other.attachments) return false
|
2021-06-11 20:15:40 +02:00
|
|
|
if (mentions != other.mentions) return false
|
2022-02-25 18:56:21 +01:00
|
|
|
if (tags != other.tags) return false
|
2019-02-12 19:22:37 +01:00
|
|
|
if (showingHiddenContent != other.showingHiddenContent) return false
|
|
|
|
if (expanded != other.expanded) return false
|
|
|
|
if (collapsible != other.collapsible) return false
|
|
|
|
if (collapsed != other.collapsed) return false
|
2021-06-17 18:54:56 +02:00
|
|
|
if (muted != other.muted) return false
|
2019-04-22 10:11:00 +02:00
|
|
|
if (poll != other.poll) return false
|
2019-02-12 19:22:37 +01:00
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun hashCode(): Int {
|
|
|
|
var result = id.hashCode()
|
|
|
|
result = 31 * result + (url?.hashCode() ?: 0)
|
|
|
|
result = 31 * result + (inReplyToId?.hashCode() ?: 0)
|
|
|
|
result = 31 * result + (inReplyToAccountId?.hashCode() ?: 0)
|
|
|
|
result = 31 * result + account.hashCode()
|
2022-03-15 21:34:57 +01:00
|
|
|
result = 31 * result + content.toString().hashCode()
|
2019-02-12 19:22:37 +01:00
|
|
|
result = 31 * result + createdAt.hashCode()
|
|
|
|
result = 31 * result + emojis.hashCode()
|
|
|
|
result = 31 * result + favouritesCount
|
|
|
|
result = 31 * result + favourited.hashCode()
|
|
|
|
result = 31 * result + sensitive.hashCode()
|
|
|
|
result = 31 * result + spoilerText.hashCode()
|
|
|
|
result = 31 * result + attachments.hashCode()
|
2021-06-11 20:15:40 +02:00
|
|
|
result = 31 * result + mentions.hashCode()
|
2022-02-25 18:56:21 +01:00
|
|
|
result = 31 * result + tags.hashCode()
|
2019-02-12 19:22:37 +01:00
|
|
|
result = 31 * result + showingHiddenContent.hashCode()
|
|
|
|
result = 31 * result + expanded.hashCode()
|
|
|
|
result = 31 * result + collapsible.hashCode()
|
|
|
|
result = 31 * result + collapsed.hashCode()
|
2021-06-17 18:54:56 +02:00
|
|
|
result = 31 * result + muted.hashCode()
|
2019-04-22 10:11:00 +02:00
|
|
|
result = 31 * result + poll.hashCode()
|
2019-02-12 19:22:37 +01:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
fun toStatus(): Status {
|
|
|
|
return Status(
|
2021-06-17 18:54:56 +02:00
|
|
|
id = id,
|
|
|
|
url = url,
|
|
|
|
account = account.toAccount(),
|
|
|
|
inReplyToId = inReplyToId,
|
|
|
|
inReplyToAccountId = inReplyToAccountId,
|
|
|
|
content = content,
|
|
|
|
reblog = null,
|
|
|
|
createdAt = createdAt,
|
|
|
|
emojis = emojis,
|
|
|
|
reblogsCount = 0,
|
|
|
|
favouritesCount = favouritesCount,
|
|
|
|
reblogged = false,
|
|
|
|
favourited = favourited,
|
|
|
|
bookmarked = bookmarked,
|
2021-06-28 21:13:24 +02:00
|
|
|
sensitive = sensitive,
|
2021-06-17 18:54:56 +02:00
|
|
|
spoilerText = spoilerText,
|
|
|
|
visibility = Status.Visibility.DIRECT,
|
|
|
|
attachments = attachments,
|
|
|
|
mentions = mentions,
|
2022-02-25 18:56:21 +01:00
|
|
|
tags = tags,
|
2021-06-17 18:54:56 +02:00
|
|
|
application = null,
|
|
|
|
pinned = false,
|
|
|
|
muted = muted,
|
|
|
|
poll = poll,
|
2021-06-28 21:13:24 +02:00
|
|
|
card = null
|
|
|
|
)
|
2019-02-12 19:22:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-15 21:34:57 +01:00
|
|
|
fun TimelineAccount.toEntity() =
|
2021-06-17 18:54:56 +02:00
|
|
|
ConversationAccountEntity(
|
|
|
|
id = id,
|
|
|
|
username = username,
|
|
|
|
displayName = name,
|
|
|
|
avatar = avatar,
|
|
|
|
emojis = emojis ?: emptyList()
|
|
|
|
)
|
2019-02-12 19:22:37 +01:00
|
|
|
|
|
|
|
fun Status.toEntity() =
|
2021-06-17 18:54:56 +02:00
|
|
|
ConversationStatusEntity(
|
|
|
|
id = id,
|
|
|
|
url = url,
|
|
|
|
inReplyToId = inReplyToId,
|
|
|
|
inReplyToAccountId = inReplyToAccountId,
|
|
|
|
account = account.toEntity(),
|
|
|
|
content = content,
|
|
|
|
createdAt = createdAt,
|
|
|
|
emojis = emojis,
|
|
|
|
favouritesCount = favouritesCount,
|
|
|
|
favourited = favourited,
|
|
|
|
bookmarked = bookmarked,
|
|
|
|
sensitive = sensitive,
|
|
|
|
spoilerText = spoilerText,
|
|
|
|
attachments = attachments,
|
|
|
|
mentions = mentions,
|
2022-02-25 18:56:21 +01:00
|
|
|
tags = tags,
|
2021-06-17 18:54:56 +02:00
|
|
|
showingHiddenContent = false,
|
|
|
|
expanded = false,
|
|
|
|
collapsible = shouldTrimStatus(content),
|
|
|
|
collapsed = true,
|
|
|
|
muted = muted ?: false,
|
|
|
|
poll = poll
|
|
|
|
)
|
2019-02-12 19:22:37 +01:00
|
|
|
|
|
|
|
fun Conversation.toEntity(accountId: Long) =
|
2021-06-17 18:54:56 +02:00
|
|
|
ConversationEntity(
|
|
|
|
accountId = accountId,
|
|
|
|
id = id,
|
|
|
|
accounts = accounts.map { it.toEntity() },
|
|
|
|
unread = unread,
|
|
|
|
lastStatus = lastStatus!!.toEntity()
|
|
|
|
)
|