Adds Immutable and Stable annotations to avoid recomposing

This commit is contained in:
Vitor Pamplona
2023-05-23 12:02:34 -04:00
parent 15621f16a2
commit 8898e5d10b
43 changed files with 101 additions and 1 deletions
@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.model package com.vitorpamplona.amethyst.model
import androidx.compose.runtime.Stable
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import com.vitorpamplona.amethyst.service.NostrSingleEventDataSource import com.vitorpamplona.amethyst.service.NostrSingleEventDataSource
import com.vitorpamplona.amethyst.service.lnurl.LnInvoiceUtil import com.vitorpamplona.amethyst.service.lnurl.LnInvoiceUtil
@@ -20,6 +21,7 @@ import java.util.regex.Pattern
val tagSearch = Pattern.compile("(?:\\s|\\A)\\#\\[([0-9]+)\\]") val tagSearch = Pattern.compile("(?:\\s|\\A)\\#\\[([0-9]+)\\]")
@Stable
class AddressableNote(val address: ATag) : Note(address.toTag()) { class AddressableNote(val address: ATag) : Note(address.toTag()) {
override fun idNote() = address.toNAddr() override fun idNote() = address.toNAddr()
override fun toNEvent() = address.toNAddr() override fun toNEvent() = address.toNAddr()
@@ -28,6 +30,7 @@ class AddressableNote(val address: ATag) : Note(address.toTag()) {
override fun createdAt() = (event as? LongTextNoteEvent)?.publishedAt() ?: event?.createdAt() override fun createdAt() = (event as? LongTextNoteEvent)?.publishedAt() ?: event?.createdAt()
} }
@Stable
open class Note(val idHex: String) { open class Note(val idHex: String) {
// These fields are only available after the Text Note event is received. // These fields are only available after the Text Note event is received.
// They are immutable after that. // They are immutable after that.
@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.model package com.vitorpamplona.amethyst.model
import androidx.compose.runtime.Stable
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import com.vitorpamplona.amethyst.service.NostrSingleUserDataSource import com.vitorpamplona.amethyst.service.NostrSingleUserDataSource
import com.vitorpamplona.amethyst.service.model.BookmarkListEvent import com.vitorpamplona.amethyst.service.model.BookmarkListEvent
@@ -20,6 +21,7 @@ import java.util.regex.Pattern
val lnurlpPattern = Pattern.compile("(?i:http|https):\\/\\/((.+)\\/)*\\.well-known\\/lnurlp\\/(.*)") val lnurlpPattern = Pattern.compile("(?i:http|https):\\/\\/((.+)\\/)*\\.well-known\\/lnurlp\\/(.*)")
@Stable
class User(val pubkeyHex: String) { class User(val pubkeyHex: String) {
var info: UserMetadata? = null var info: UserMetadata? = null
@@ -358,6 +360,7 @@ data class RelayInfo(
data class Chatroom(var roomMessages: Set<Note>) data class Chatroom(var roomMessages: Set<Note>)
@Stable
class UserMetadata { class UserMetadata {
var name: String? = null var name: String? = null
var username: String? = null var username: String? = null
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.hexToByteArray import com.vitorpamplona.amethyst.model.hexToByteArray
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import com.vitorpamplona.amethyst.service.nip19.Tlv import com.vitorpamplona.amethyst.service.nip19.Tlv
@@ -9,6 +10,7 @@ import nostr.postr.Bech32
import nostr.postr.bechToBytes import nostr.postr.bechToBytes
import nostr.postr.toByteArray import nostr.postr.toByteArray
@Immutable
data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val relay: String?) { data class ATag(val kind: Int, val pubKeyHex: String, val dTag: String, val relay: String?) {
fun toTag() = "$kind:$pubKeyHex:$dTag" fun toTag() = "$kind:$pubKeyHex:$dTag"
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class AudioTrackEvent( class AudioTrackEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,7 +1,9 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
@Immutable
class BadgeAwardEvent( class BadgeAwardEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,7 +1,9 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
@Immutable
class BadgeDefinitionEvent( class BadgeDefinitionEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,7 +1,9 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
@Immutable
class BadgeProfilesEvent( class BadgeProfilesEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,11 +1,13 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.tagSearch import com.vitorpamplona.amethyst.model.tagSearch
import com.vitorpamplona.amethyst.service.nip19.Nip19 import com.vitorpamplona.amethyst.service.nip19.Nip19
import com.vitorpamplona.amethyst.service.nip19.Nip19.nip19regex import com.vitorpamplona.amethyst.service.nip19.Nip19.nip19regex
@Immutable
open class BaseTextNoteEvent( open class BaseTextNoteEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class BookmarkListEvent( class BookmarkListEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,11 +1,13 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class ChannelCreateEvent( class ChannelCreateEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class ChannelHideMessageEvent( class ChannelHideMessageEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class ChannelMessageEvent( class ChannelMessageEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,11 +1,13 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class ChannelMetadataEvent( class ChannelMetadataEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class ChannelMuteUserEvent( class ChannelMuteUserEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.decodePublicKey import com.vitorpamplona.amethyst.model.decodePublicKey
@@ -8,6 +9,7 @@ import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
data class Contact(val pubKeyHex: String, val relayUri: String?) data class Contact(val pubKeyHex: String, val relayUri: String?)
class ContactListEvent( class ContactListEvent(
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class DeletionEvent( class DeletionEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.google.gson.* import com.google.gson.*
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
@@ -14,6 +15,7 @@ import java.math.BigDecimal
import java.security.MessageDigest import java.security.MessageDigest
import java.util.* import java.util.*
@Immutable
open class Event( open class Event(
val id: HexKey, val id: HexKey,
@SerializedName("pubkey") val pubKey: HexKey, @SerializedName("pubkey") val pubKey: HexKey,
@@ -285,6 +287,7 @@ open class Event(
} }
} }
@Immutable
interface AddressableEvent { interface AddressableEvent {
fun dTag(): String fun dTag(): String
fun address(): ATag fun address(): ATag
@@ -1,8 +1,10 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import java.math.BigDecimal import java.math.BigDecimal
@Immutable
interface EventInterface { interface EventInterface {
fun id(): HexKey fun id(): HexKey
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class FileHeaderEvent( class FileHeaderEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,12 +1,14 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Base64 import java.util.Base64
import java.util.Date import java.util.Date
@Immutable
class FileStorageEvent( class FileStorageEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class FileStorageHeaderEvent( class FileStorageHeaderEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,11 +1,13 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.hexToByteArray import com.vitorpamplona.amethyst.model.hexToByteArray
import nostr.postr.Utils import nostr.postr.Utils
@Immutable
abstract class GeneralListEvent( abstract class GeneralListEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class HighlightEvent( class HighlightEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.service.lnurl.LnInvoiceUtil import com.vitorpamplona.amethyst.service.lnurl.LnInvoiceUtil
import com.vitorpamplona.amethyst.service.relays.Client import com.vitorpamplona.amethyst.service.relays.Client
@Immutable
class LnZapEvent( class LnZapEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,7 +1,9 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import java.math.BigDecimal import java.math.BigDecimal
@Immutable
interface LnZapEventInterface : EventInterface { interface LnZapEventInterface : EventInterface {
fun zappedPost(): List<String> fun zappedPost(): List<String>
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.google.gson.JsonDeserializationContext import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement import com.google.gson.JsonElement
@@ -12,6 +13,7 @@ import nostr.postr.Utils
import java.lang.reflect.Type import java.lang.reflect.Type
import java.util.Date import java.util.Date
@Immutable
class LnZapPaymentRequestEvent( class LnZapPaymentRequestEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.google.gson.JsonDeserializationContext import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement import com.google.gson.JsonElement
@@ -10,6 +11,7 @@ import com.vitorpamplona.amethyst.model.HexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.lang.reflect.Type import java.lang.reflect.Type
@Immutable
class LnZapPaymentResponseEvent( class LnZapPaymentResponseEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.* import com.vitorpamplona.amethyst.model.*
import nostr.postr.Bech32 import nostr.postr.Bech32
import nostr.postr.Utils import nostr.postr.Utils
@@ -11,6 +12,7 @@ import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec import javax.crypto.spec.SecretKeySpec
@Immutable
class LnZapRequestEvent( class LnZapRequestEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class LongTextNoteEvent( class LongTextNoteEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.google.gson.Gson import com.google.gson.Gson
import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
@@ -8,6 +9,7 @@ import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
data class ContactMetaData( data class ContactMetaData(
val name: String, val name: String,
val picture: String, val picture: String,
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.hexToByteArray import com.vitorpamplona.amethyst.model.hexToByteArray
@@ -8,6 +9,7 @@ import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class MuteListEvent( class MuteListEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class PeopleListEvent( class PeopleListEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class PinListEvent( class PinListEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
@@ -11,6 +12,7 @@ const val VALUE_MINIMUM = "value_minimum"
const val CONSENSUS_THRESHOLD = "consensus_threshold" const val CONSENSUS_THRESHOLD = "consensus_threshold"
const val CLOSED_AT = "closed_at" const val CLOSED_AT = "closed_at"
@Immutable
class PollNoteEvent( class PollNoteEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import android.util.Log import android.util.Log
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import fr.acinq.secp256k1.Hex import fr.acinq.secp256k1.Hex
@@ -8,6 +9,7 @@ import nostr.postr.Utils
import nostr.postr.toHex import nostr.postr.toHex
import java.util.Date import java.util.Date
@Immutable
class PrivateDmEvent( class PrivateDmEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class ReactionEvent( class ReactionEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,11 +1,13 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.net.URI import java.net.URI
import java.util.Date import java.util.Date
@Immutable
class RecommendRelayEvent( class RecommendRelayEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,10 +1,12 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class RelayAuthEvent( class RelayAuthEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,13 +1,16 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
data class ReportedKey(val key: String, val reportType: ReportEvent.ReportType) data class ReportedKey(val key: String, val reportType: ReportEvent.ReportType)
// NIP 56 event. // NIP 56 event.
@Immutable
class ReportEvent( class ReportEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,11 +1,13 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
import com.vitorpamplona.amethyst.model.toHexKey import com.vitorpamplona.amethyst.model.toHexKey
import com.vitorpamplona.amethyst.service.relays.Client import com.vitorpamplona.amethyst.service.relays.Client
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class RepostEvent( class RepostEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.service.model package com.vitorpamplona.amethyst.service.model
import com.google.errorprone.annotations.Immutable
import com.linkedin.urls.detection.UrlDetector import com.linkedin.urls.detection.UrlDetector
import com.linkedin.urls.detection.UrlDetectorOptions import com.linkedin.urls.detection.UrlDetectorOptions
import com.vitorpamplona.amethyst.model.HexKey import com.vitorpamplona.amethyst.model.HexKey
@@ -8,6 +9,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.findHashtags
import nostr.postr.Utils import nostr.postr.Utils
import java.util.Date import java.util.Date
@Immutable
class TextNoteEvent( class TextNoteEvent(
id: HexKey, id: HexKey,
pubKey: HexKey, pubKey: HexKey,
@@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.ui.screen package com.vitorpamplona.amethyst.ui.screen
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
@@ -9,6 +10,7 @@ abstract class Card() {
abstract fun id(): String abstract fun id(): String
} }
@Immutable
class BadgeCard(val note: Note) : Card() { class BadgeCard(val note: Note) : Card() {
override fun createdAt(): Long { override fun createdAt(): Long {
return note.createdAt() ?: 0 return note.createdAt() ?: 0
@@ -17,6 +19,7 @@ class BadgeCard(val note: Note) : Card() {
override fun id() = note.idHex override fun id() = note.idHex
} }
@Immutable
class NoteCard(val note: Note) : Card() { class NoteCard(val note: Note) : Card() {
override fun createdAt(): Long { override fun createdAt(): Long {
return note.createdAt() ?: 0 return note.createdAt() ?: 0
@@ -25,6 +28,7 @@ class NoteCard(val note: Note) : Card() {
override fun id() = note.idHex override fun id() = note.idHex
} }
@Immutable
class LikeSetCard(val note: Note, val likeEvents: List<Note>) : Card() { class LikeSetCard(val note: Note, val likeEvents: List<Note>) : Card() {
val createdAt = likeEvents.maxOf { it.createdAt() ?: 0 } val createdAt = likeEvents.maxOf { it.createdAt() ?: 0 }
override fun createdAt(): Long { override fun createdAt(): Long {
@@ -33,6 +37,7 @@ class LikeSetCard(val note: Note, val likeEvents: List<Note>) : Card() {
override fun id() = note.idHex + "L" + createdAt override fun id() = note.idHex + "L" + createdAt
} }
@Immutable
class ZapSetCard(val note: Note, val zapEvents: Map<Note, Note>) : Card() { class ZapSetCard(val note: Note, val zapEvents: Map<Note, Note>) : Card() {
val createdAt = zapEvents.maxOf { it.value.createdAt() ?: 0 } val createdAt = zapEvents.maxOf { it.value.createdAt() ?: 0 }
override fun createdAt(): Long { override fun createdAt(): Long {
@@ -41,6 +46,7 @@ class ZapSetCard(val note: Note, val zapEvents: Map<Note, Note>) : Card() {
override fun id() = note.idHex + "Z" + createdAt override fun id() = note.idHex + "Z" + createdAt
} }
@Immutable
class ZapUserSetCard(val user: User, val zapEvents: Map<Note, Note>) : Card() { class ZapUserSetCard(val user: User, val zapEvents: Map<Note, Note>) : Card() {
val createdAt = zapEvents.maxOf { it.value.createdAt() ?: 0 } val createdAt = zapEvents.maxOf { it.value.createdAt() ?: 0 }
override fun createdAt(): Long { override fun createdAt(): Long {
@@ -49,6 +55,7 @@ class ZapUserSetCard(val user: User, val zapEvents: Map<Note, Note>) : Card() {
override fun id() = user.pubkeyHex + "U" + createdAt override fun id() = user.pubkeyHex + "U" + createdAt
} }
@Immutable
class MultiSetCard(val note: Note, val boostEvents: List<Note>, val likeEvents: List<Note>, val zapEvents: Map<Note, Note>) : Card() { class MultiSetCard(val note: Note, val boostEvents: List<Note>, val likeEvents: List<Note>, val zapEvents: Map<Note, Note>) : Card() {
val createdAt = maxOf( val createdAt = maxOf(
zapEvents.maxOfOrNull { it.value.createdAt() ?: 0 } ?: 0, zapEvents.maxOfOrNull { it.value.createdAt() ?: 0 } ?: 0,
@@ -62,6 +69,7 @@ class MultiSetCard(val note: Note, val boostEvents: List<Note>, val likeEvents:
override fun id() = note.idHex + "X" + createdAt override fun id() = note.idHex + "X" + createdAt
} }
@Immutable
class BoostSetCard(val note: Note, val boostEvents: List<Note>) : Card() { class BoostSetCard(val note: Note, val boostEvents: List<Note>) : Card() {
val createdAt = boostEvents.maxOf { it.createdAt() ?: 0 } val createdAt = boostEvents.maxOf { it.createdAt() ?: 0 }
@@ -72,6 +80,7 @@ class BoostSetCard(val note: Note, val boostEvents: List<Note>) : Card() {
override fun id() = note.idHex + "B" + createdAt override fun id() = note.idHex + "B" + createdAt
} }
@Immutable
class MessageSetCard(val note: Note) : Card() { class MessageSetCard(val note: Note) : Card() {
override fun createdAt(): Long { override fun createdAt(): Long {
return note.createdAt() ?: 0 return note.createdAt() ?: 0
@@ -124,6 +124,10 @@ private fun FeedLoaded(
} }
} }
val baseModifier = remember {
Modifier
}
LazyColumn( LazyColumn(
contentPadding = PaddingValues( contentPadding = PaddingValues(
top = 10.dp, top = 10.dp,
@@ -134,8 +138,9 @@ private fun FeedLoaded(
itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item -> itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item ->
NoteCompose( NoteCompose(
item, item,
isBoostedNote = false,
routeForLastRead = routeForLastRead, routeForLastRead = routeForLastRead,
modifier = baseModifier,
isBoostedNote = false,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
navController = navController navController = navController
) )