Merge remote-tracking branch 'origin/main' into claude/loving-hopper-rn553t

This commit is contained in:
Claude
2026-06-22 14:53:23 +00:00
15 changed files with 380 additions and 103 deletions
@@ -425,6 +425,8 @@ class Account(
scope = scope,
assembler = cashuWalletFilterAssembler(),
outboxRelaysFlow = outboxRelays.flow,
inboxRelaysFlow = notificationRelays.flow,
dmRelaysFlow = dmRelays.flow,
settings = settings,
okHttpClient = okHttpClientForMoney,
)
@@ -103,6 +103,8 @@ class CashuWalletState(
private val scope: CoroutineScope,
private val assembler: CashuWalletFilterAssembler,
private val outboxRelaysFlow: StateFlow<Set<NormalizedRelayUrl>>,
private val inboxRelaysFlow: StateFlow<Set<NormalizedRelayUrl>>,
private val dmRelaysFlow: StateFlow<Set<NormalizedRelayUrl>>,
private val settings: AccountSettings,
okHttpClient: (String) -> OkHttpClient,
) {
@@ -442,12 +444,31 @@ class CashuWalletState(
triggerAutoRedeem()
}
// Keep the relay subscription in sync with the outbox set.
// Keep the wallet subscription in sync with the relay sets it reads
// from. Following the NIP-65 outbox model, the two halves of the
// subscription read from different places:
// - our own NIP-60 events (wallet/token/history) are read back from
// our OUTBOX relays, where we published them;
// - inbound kind:9321 nutzaps are read from our INBOX set, since
// that is where other people deliver them. Per NIP-61 the source
// of truth for "where to send me nutzaps" is the `relay` tags in
// our own kind:10019 — and another client may have published that
// with relays unrelated to our NIP-65 lists — so we listen on the
// union of those plus our NIP-65 inbox + DM relays.
jobs +=
scope.launch(Dispatchers.IO) {
outboxRelaysFlow.collect { relays ->
syncSubscription(relays)
}
combine(
outboxRelaysFlow,
inboxRelaysFlow,
dmRelaysFlow,
_nutzapInfoEvent,
) { outbox, inbox, dm, info ->
CashuWalletQueryState(
pubkey = pubKey,
ownEventRelays = outbox,
inboxRelays = inbox + dm + (info?.relays() ?: emptyList()),
)
}.collect { syncSubscription(it) }
}
// Reactive incremental update: any new event arrival that matches our
@@ -510,17 +531,16 @@ class CashuWalletState(
// ============================================================
// Subscription management
// ============================================================
private fun syncSubscription(relays: Set<NormalizedRelayUrl>) {
private fun syncSubscription(next: CashuWalletQueryState) {
val previous = currentSubscription
if (relays.isEmpty()) {
if (next.ownEventRelays.isEmpty() && next.inboxRelays.isEmpty()) {
previous?.let { runCatching { assembler.unsubscribe(it) } }
currentSubscription = null
return
}
if (previous != null && previous.relays == relays) return // unchanged
if (previous == next) return // unchanged
previous?.let { runCatching { assembler.unsubscribe(it) } }
val next = CashuWalletQueryState(pubKey, relays)
currentSubscription = next
assembler.subscribe(next)
}
@@ -850,7 +870,11 @@ class CashuWalletState(
ops.publishWalletEvents(
mints = currentMints,
p2pkPrivkeyHex = manualPrivkeyHex?.takeIf { it.isNotBlank() },
nutzapRelays = outboxRelaysFlow.value.toList(),
// Advertise our NIP-65 inbox relays as the nutzap relays (NIP-65
// outbox model): senders publish kind:9321 where we read inbound
// events. We listen on a wider set (inbox + DM + these tags), but
// the kind:10019 default copies the inbox relay list, not outbox.
nutzapRelays = inboxRelaysFlow.value.toList(),
)
// The NUT-13 seed (derived from the P2PK key) is invalidated by
// applyEvents when the new kind:17375 round-trips in, so it re-derives
@@ -150,9 +150,15 @@ fun observeUserBanner(
fun observeUserPicture(
user: User,
accountViewModel: AccountViewModel,
subscribe: Boolean = true,
): State<String?> {
// Subscribe in the relay for changes in the metadata of this user.
UserFinderFilterAssemblerSubscription(user, accountViewModel)
// Callers that already hold a single shared subscription for the same user
// (e.g. an author avatar that also observes the contact-card score) can pass
// subscribe = false to avoid setting up a redundant relay subscription.
if (subscribe) {
UserFinderFilterAssemblerSubscription(user, accountViewModel)
}
// Subscribe in the LocalCache for changes that arrive in the device
val flow =
@@ -476,9 +482,14 @@ fun observeUserIsFollowingChannel(
fun observeUserContactCardsScore(
user: User,
accountViewModel: AccountViewModel,
subscribe: Boolean = true,
): State<Int?> {
// Subscribe in the relay for changes in the metadata of this user.
UserFinderFilterAssemblerSubscription(user, accountViewModel)
// See observeUserPicture: pass subscribe = false when a shared subscription
// for the same user already exists.
if (subscribe) {
UserFinderFilterAssemblerSubscription(user, accountViewModel)
}
// Subscribe in the LocalCache for changes that arrive in the device
val flow = remember(user) { user.cards().rankFlow(accountViewModel.account.trustProviderList) }
@@ -24,6 +24,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.unit.Velocity
import kotlin.math.abs
/**
* Scroll-linked connection that hides/reveals the top and bottom bars together.
@@ -43,10 +44,16 @@ import androidx.compose.ui.unit.Velocity
* - onPostFling snaps a mid-way bar to the nearest edge, using the fling's remaining
* velocity as the spring's initial velocity so the settle feels continuous. No velocity
* is returned upward to avoid phantom scrolls on parent containers.
* - Hiding tracks the finger 1:1, but revealing is damped by [REVEAL_SENSITIVITY]. Once the
* bars are hidden, the small reverse drag a finger naturally makes when it catches/stops a
* fast scroll would otherwise be enough to snap the chrome (and the OS status bar) back.
* Damping the reveal direction makes bringing the bars back a more deliberate gesture.
* - Both hiding and revealing track the finger 1:1. The bar offset must equal the content's
* scroll offset so the bar's bottom edge stays glued to the first item's top edge; any
* asymmetry (e.g. a damped reveal) leaves the bar lagging behind the content and opens a
* blank band between the bar and the first item when the list returns to the top.
*
* Making the reveal a *deliberate* gesture so the tiny reverse drag a finger makes when it
* catches/stops a fast scroll doesn't pop the chrome back is handled without breaking that
* 1:1 invariant: a partial reveal that doesn't cross the halfway point is snapped back to the
* hidden edge by [DisappearingBarState.settleToNearestEdge] on fling/lift, and the binary OS
* status bar is debounced by the show/hide hysteresis in the scaffold.
*/
class DisappearingBarNestedScroll(
private val state: DisappearingBarState,
@@ -60,7 +67,10 @@ class DisappearingBarNestedScroll(
): Offset {
if (!canScroll()) return Offset.Zero
val totalY = consumed.y + available.y
if (totalY == 0f) return Offset.Zero
// Dead-zone: ignore sub-pixel jitter so the bars (and the binary status-bar toggle that
// tracks their collapse fraction) don't twitch on scroll noise. Kept symmetric and tiny so
// it never makes the reveal lag the content enough to open a visible gap.
if (abs(totalY) < MIN_SCROLL_DELTA) return Offset.Zero
// If the list did not consume any scroll and the bars are fully visible, treat
// this as a non-scrollable list and keep the bars in place. Without this, a tiny
@@ -90,19 +100,18 @@ class DisappearingBarNestedScroll(
private fun applyDelta(deltaY: Float) {
val topLimit = state.topHeightLimit
val bottomLimit = state.bottomHeightLimit
// Positive delta reveals the bars; negative delta hides them. Hiding stays 1:1 with the
// finger, while revealing is damped so a stray reverse drag doesn't bring the chrome back.
val effectiveDelta = if (deltaY > 0f) deltaY * REVEAL_SENSITIVITY else deltaY
state.topHeightOffset = (state.topHeightOffset + effectiveDelta).coerceIn(-topLimit, 0f)
state.bottomHeightOffset = (state.bottomHeightOffset + effectiveDelta).coerceIn(-bottomLimit, 0f)
// 1:1 in both directions: the bar offset mirrors the content scroll so the bar stays glued
// to the first item. Deliberate reveal is enforced on settle, not by damping the delta here.
state.topHeightOffset = (state.topHeightOffset + deltaY).coerceIn(-topLimit, 0f)
state.bottomHeightOffset = (state.bottomHeightOffset + deltaY).coerceIn(-bottomLimit, 0f)
}
companion object {
/**
* Fraction of scroll distance applied when revealing the bars (1.0 = same rate as hiding).
* Lower values require a more deliberate downward scroll to bring the chrome back, so the
* tiny reverse movement of a finger stopping a fast scroll no longer pops the bars open.
* Sub-pixel dead-zone: scroll attempts smaller than this are ignored so jitter doesn't nudge
* the bars. Tiny on purpose large enough to swallow fractional noise, small enough that the
* bar offset never measurably lags the content scroll.
*/
const val REVEAL_SENSITIVITY = 0.5f
const val MIN_SCROLL_DELTA = 0.5f
}
}
@@ -46,8 +46,46 @@ class DisappearingBarState(
initialTopHeightOffset: Float = 0f,
initialBottomHeightOffset: Float = 0f,
) {
var topHeightOffset by mutableFloatStateOf(initialTopHeightOffset)
var bottomHeightOffset by mutableFloatStateOf(initialBottomHeightOffset)
private var _topHeightOffset by mutableFloatStateOf(initialTopHeightOffset)
private var _bottomHeightOffset by mutableFloatStateOf(initialBottomHeightOffset)
/**
* Latches that record whether each bar has been driven all the way to its hidden edge by real
* scrolling since it was last fully in view. The settle reads them to tell a deliberate hide
* where the content has scrolled at least a full bar height, so snapping the bar fully hidden
* leaves content (not a blank band) in the slot it vacates apart from a small near-top
* collapse, where snapping hidden would expose the background because the content hasn't
* scrolled far enough to fill the bar's slot.
*/
private var topReachedHiddenEdge = false
private var bottomReachedHiddenEdge = false
var topHeightOffset: Float
get() = _topHeightOffset
set(value) {
_topHeightOffset = value
updateLatch(value, topHeightLimit) { topReachedHiddenEdge = it }
}
var bottomHeightOffset: Float
get() = _bottomHeightOffset
set(value) {
_bottomHeightOffset = value
updateLatch(value, bottomHeightLimit) { bottomReachedHiddenEdge = it }
}
private inline fun updateLatch(
offset: Float,
limit: Float,
set: (Boolean) -> Unit,
) {
if (limit <= 0f) return
if (offset >= 0f) {
set(false)
} else if (offset <= -limit) {
set(true)
}
}
var topHeightLimit: Float = 0f
set(value) {
@@ -76,8 +114,8 @@ class DisappearingBarState(
*/
suspend fun settleToNearestEdge(initialVelocityY: Float = 0f) {
coroutineScope {
launch { settleOne({ topHeightOffset }, topHeightLimit, initialVelocityY) { topHeightOffset = it } }
launch { settleOne({ bottomHeightOffset }, bottomHeightLimit, initialVelocityY) { bottomHeightOffset = it } }
launch { settleOne({ topHeightOffset }, topHeightLimit, topReachedHiddenEdge, initialVelocityY) { topHeightOffset = it } }
launch { settleOne({ bottomHeightOffset }, bottomHeightLimit, bottomReachedHiddenEdge, initialVelocityY) { bottomHeightOffset = it } }
}
}
@@ -94,6 +132,7 @@ class DisappearingBarState(
private suspend fun settleOne(
get: () -> Float,
limit: Float,
canFullyHide: Boolean,
initialVelocityY: Float,
set: (Float) -> Unit,
) {
@@ -105,6 +144,11 @@ class DisappearingBarState(
val positionBiasToHide = -current > limit / 2f
val target =
when {
// Snapping to the hidden edge is only safe once the bar has actually been scrolled
// there (canFullyHide): the content has then moved at least a full bar height and
// fills the slot the bar vacates. From a small near-top collapse it hasn't, so
// snapping hidden would open a blank band — settle back into view instead.
!canFullyHide -> 0f
initialVelocityY < -VELOCITY_BIAS_THRESHOLD -> -limit
initialVelocityY > VELOCITY_BIAS_THRESHOLD -> 0f
positionBiasToHide -> -limit
@@ -142,10 +186,14 @@ class DisappearingBarState(
companion object {
private const val VELOCITY_BIAS_THRESHOLD = 200f
// Bounce-free so the chrome never wobbles past its edge, but stiff enough to feel like a
// quick native snap rather than a slow float once the finger lifts. Overshoot from a strong
// initial velocity is still caught by the bounds in animateOne, so a higher stiffness here
// only affects how briskly the bar resolves to its edge.
private val SETTLE_SPRING =
spring<Float>(
dampingRatio = Spring.DampingRatioNoBouncy,
stiffness = Spring.StiffnessMediumLow,
stiffness = Spring.StiffnessMedium,
)
val Saver: Saver<DisappearingBarState, *> =
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.amethyst.ui.note
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
/**
* The notification galleries (reactions, zaps, nutzaps, boosts) render up to 30
* author avatars each. A couple of the inputs to every avatar are *account-global*
* the auto-play-gif setting and the logged-in user's follow set yet the avatar
* code used to collect each of them **once per author**. With dozens of authors per
* card that produced dozens of redundant Flow collectors / coroutine launches every
* time a card scrolled into view, a measurable chunk of the per-card composition cost.
*
* Hoisting those reads to a single collection per gallery and handing the snapshot
* down through [LocalAuthorGalleryRenderContext] lets each avatar read plain values
* and stay skippable. When the local is absent the avatar falls back to its old
* per-author behaviour, so callers that don't provide a context keep working.
*/
@Immutable
class AuthorGalleryRenderContext(
val autoPlayGif: Boolean,
val follows: Set<String>,
)
val LocalAuthorGalleryRenderContext = compositionLocalOf<AuthorGalleryRenderContext?> { null }
/**
* Collects the account-global render inputs a single time. Provide the result via
* [LocalAuthorGalleryRenderContext] around a gallery's author list.
*/
@Composable
fun rememberAuthorGalleryRenderContext(accountViewModel: AccountViewModel): AuthorGalleryRenderContext {
val autoPlayGif by accountViewModel.settings.autoPlayVideosFlow.collectAsStateWithLifecycle()
val follows by accountViewModel.account.allFollows.flow
.collectAsStateWithLifecycle()
val followAuthors = follows.authors
return remember(autoPlayGif, followAuthors) {
AuthorGalleryRenderContext(autoPlayGif, followAuthors)
}
}
@@ -40,6 +40,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
@@ -72,6 +73,7 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.NoteState
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.CachedRichTextParser
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.UserFinderFilterAssemblerSubscription
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.observeUserContactCardsScore
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.observeUserPicture
import com.vitorpamplona.amethyst.ui.components.AnimatedBorderTextCornerRadius
@@ -463,8 +465,12 @@ fun AuthorGalleryZaps(
nav: INav,
accountViewModel: AccountViewModel,
) {
Column(modifier = StdStartPadding) {
FlowRow { authorNotes.forEach { RenderState(it, backgroundColor, accountViewModel, nav) } }
CompositionLocalProvider(
LocalAuthorGalleryRenderContext provides rememberAuthorGalleryRenderContext(accountViewModel),
) {
Column(modifier = StdStartPadding) {
FlowRow { authorNotes.forEach { RenderState(it, backgroundColor, accountViewModel, nav) } }
}
}
}
@@ -631,8 +637,12 @@ fun AuthorGallery(
accountViewModel: AccountViewModel,
clickRoute: (Note) -> Route? = ::authorRouteFor,
) {
Column(modifier = StdStartPadding) {
FlowRow { authorNotes.forEach { note -> BoxedAuthor(note, nav, accountViewModel, clickRoute) } }
CompositionLocalProvider(
LocalAuthorGalleryRenderContext provides rememberAuthorGalleryRenderContext(accountViewModel),
) {
Column(modifier = StdStartPadding) {
FlowRow { authorNotes.forEach { note -> BoxedAuthor(note, nav, accountViewModel, clickRoute) } }
}
}
}
@@ -643,9 +653,13 @@ fun AuthorGallery(
nav: INav,
accountViewModel: AccountViewModel,
) {
Column(modifier = StdStartPadding) {
FlowRow {
noteToGetBoostEvents.note.boosts.forEach { note -> BoxedAuthor(note, nav, accountViewModel) }
CompositionLocalProvider(
LocalAuthorGalleryRenderContext provides rememberAuthorGalleryRenderContext(accountViewModel),
) {
Column(modifier = StdStartPadding) {
FlowRow {
noteToGetBoostEvents.note.boosts.forEach { note -> BoxedAuthor(note, nav, accountViewModel) }
}
}
}
}
@@ -684,7 +698,27 @@ fun WatchUserMetadataAndFollowsAndRenderUserProfilePicture(
author: User,
accountViewModel: AccountViewModel,
) {
WatchUserMetadata(author, accountViewModel) { baseUserPicture ->
// When rendered inside a gallery, the account-global auto-play and follow-set
// reads are hoisted to a single collection for the whole gallery (see
// [rememberAuthorGalleryRenderContext]). Falls back to per-author collection
// for callers that don't provide a context.
val galleryContext = LocalAuthorGalleryRenderContext.current
// One shared relay subscription per author. The profile picture and the
// contact-card score below both fetch the same kind-0 metadata, so we
// subscribe once here and let them skip their own (formerly duplicate) one.
UserFinderFilterAssemblerSubscription(author, accountViewModel)
WatchUserMetadata(author, accountViewModel, subscribe = false) { baseUserPicture ->
val autoPlayGif =
if (galleryContext != null) {
galleryContext.autoPlayGif
} else {
accountViewModel.settings.autoPlayVideosFlow
.collectAsStateWithLifecycle()
.value
}
RobohashFallbackAsyncImage(
robot = author.pubkeyHex,
model = baseUserPicture,
@@ -693,30 +727,39 @@ fun WatchUserMetadataAndFollowsAndRenderUserProfilePicture(
contentScale = ContentScale.Crop,
loadProfilePicture = accountViewModel.settings.showProfilePictures(),
loadRobohash = accountViewModel.settings.isNotPerformanceMode(),
autoPlayGif =
accountViewModel.settings.autoPlayVideosFlow
.collectAsStateWithLifecycle()
.value,
autoPlayGif = autoPlayGif,
)
}
WatchUserFollows(author.pubkeyHex, accountViewModel) { isFollowing ->
if (galleryContext != null) {
val isFollowing =
accountViewModel.isLoggedUser(author.pubkeyHex) ||
author.pubkeyHex in galleryContext.follows
if (isFollowing) {
Box(modifier = Size35Modifier, contentAlignment = Alignment.TopEnd) {
FollowingIcon(Size10Modifier)
}
}
} else {
WatchUserFollows(author.pubkeyHex, accountViewModel) { isFollowing ->
if (isFollowing) {
Box(modifier = Size35Modifier, contentAlignment = Alignment.TopEnd) {
FollowingIcon(Size10Modifier)
}
}
}
}
ObserveAndRenderBoxedUserCards(author, accountViewModel)
ObserveAndRenderBoxedUserCards(author, accountViewModel, subscribe = false)
}
@Composable
fun ObserveAndRenderBoxedUserCards(
user: User,
accountViewModel: AccountViewModel,
subscribe: Boolean = true,
) {
val score by observeUserContactCardsScore(user, accountViewModel)
val score by observeUserContactCardsScore(user, accountViewModel, subscribe)
score?.let {
Box(modifier = Size35Modifier, contentAlignment = Alignment.BottomCenter) {
@@ -729,9 +772,10 @@ fun ObserveAndRenderBoxedUserCards(
private fun WatchUserMetadata(
author: User,
accountViewModel: AccountViewModel,
subscribe: Boolean = true,
onNewMetadata: @Composable (String?) -> Unit,
) {
val userProfile by observeUserPicture(author, accountViewModel)
val userProfile by observeUserPicture(author, accountViewModel, subscribe)
onNewMetadata(userProfile)
}
@@ -63,7 +63,6 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
@Stable
class CardFeedContentState(
@@ -266,7 +265,19 @@ class CardFeedContentState(
}
}
val sdf = DateTimeFormatter.ofPattern("yyyy-MM-dd") // SimpleDateFormat()
// Notifications are bucketed per calendar day. Computing the day key as a
// raw epoch-day Long (instead of formatting a "yyyy-MM-dd" String per event)
// gives identical buckets and chronological ordering while avoiding a
// DateTimeFormatter + ZonedDateTime + String allocation for every single
// reaction/zap/repost — a meaningful GC saving on full feed conversions.
val zone = ZoneId.systemDefault()
fun epochDay(createdAt: Long?): Long =
Instant
.ofEpochSecond(createdAt ?: 0L)
.atZone(zone)
.toLocalDate()
.toEpochDay()
val allBaseNotes = zapsPerEvent.keys + boostsPerEvent.keys + reactionsPerEvent.keys + nutzapsPerEvent.keys
val multiCards =
@@ -278,21 +289,16 @@ class CardFeedContentState(
val singleList =
(boostsInCard + zapsInCard.map { it.response } + reactionsInCard + nutzapsInCard).groupBy {
sdf.format(
Instant
.ofEpochSecond(it.createdAt() ?: 0L)
.atZone(ZoneId.systemDefault())
.toLocalDateTime(),
)
epochDay(it.createdAt())
}
val days = singleList.keys.sortedBy { it }
days
.mapNotNull { string ->
.mapNotNull { day ->
val sortedList =
singleList
.get(string)
.get(day)
?.sortedWith(compareByDescending<Note> { it.createdAt() }.thenBy { it.idHex })
sortedList?.chunked(30)?.map { chunk ->
@@ -312,12 +318,7 @@ class CardFeedContentState(
.map { user ->
val byDay =
user.value.groupBy {
sdf.format(
Instant
.ofEpochSecond(it.createdAt() ?: 0L)
.atZone(ZoneId.systemDefault())
.toLocalDateTime(),
)
epochDay(it.createdAt())
}
byDay.values.map { zaps ->
@@ -338,12 +339,7 @@ class CardFeedContentState(
.map { user ->
val byDay =
user.value.groupBy {
sdf.format(
Instant
.ofEpochSecond(it.createdAt() ?: 0L)
.atZone(ZoneId.systemDefault())
.toLocalDateTime(),
)
epochDay(it.createdAt())
}
byDay.values.map { nutzaps ->
@@ -500,8 +500,13 @@ class CashuWalletViewModel : ViewModel() {
ops.publishWalletEvents(
mints = mints,
p2pkPrivkeyHex = privkey,
// Advertise our NIP-65 inbox relays as the nutzap relays,
// so senders publish kind:9321 where we read incoming
// events (NIP-65 outbox model). The kind:10019 default
// copies the inbox relay list, not outbox; the wallet
// still subscribes to a wider inbox + DM + tags set.
nutzapRelays =
acc.outboxRelays.flow.value
acc.notificationRelays.flow.value
.toList(),
)
_createState.value = CashuWalletCreateState.Success
@@ -566,6 +566,9 @@
<string name="profile_app_recommendations_title">推荐的应用</string>
<string name="profile_app_recommendations_description">选择您公开推荐的Nostr应用。建议显示在您的个人资料上,并帮助他人发现此客户端无法打开的内容。</string>
<string name="profile_app_recommendations_empty">尚未找到应用。应用在您的中继上被发现时会出现在这里。</string>
<string name="profile_app_recommendations_search">按名称搜索应用</string>
<string name="profile_app_recommendations_search_empty">没有匹配您搜索的应用。</string>
<string name="profile_app_recommendations_filter_empty">没有推荐应用匹配此过滤器。</string>
<string name="app_definition_untitled">未命名应用</string>
<string name="app_definition_no_supported_kinds">不宣布它处理的内容</string>
<string name="app_definition_recommend">推荐</string>
@@ -594,6 +597,8 @@
<string name="workout_sets"></string>
<string name="workout_reps">重复</string>
<string name="workout_weight">体重</string>
<string name="workout_exercises">练习</string>
<string name="workout_volume"></string>
<string name="workout_notes">备注</string>
<string name="workout_hours">小时</string>
<string name="workout_minutes">分钟</string>
@@ -614,6 +619,9 @@
<string name="exercise_meditation">冥想</string>
<string name="exercise_diet">饮食</string>
<string name="exercise_fasting">节食</string>
<string name="exercise_circuit">循环训练</string>
<string name="exercise_emom">EMOM</string>
<string name="exercise_amrap">AMRAP</string>
<string name="software_apps">应用</string>
<string name="nip82_repository_label">来源: %1$s</string>
<string name="nip82_version_label">v%1$s</string>
@@ -79,17 +79,17 @@ class DisappearingBarNestedScrollTest {
}
@Test
fun `scrolling content down reveals both bars from a hidden state, damped`() {
fun `scrolling content down reveals both bars from a hidden state`() {
val state = state(topLimit = 100f, bottomLimit = 50f)
state.topHeightOffset = -100f
state.bottomHeightOffset = -50f
val connection = nsc(state)
// Reveal is damped by REVEAL_SENSITIVITY (0.5), so a 30px drag only reveals 15px.
// Reveal tracks the finger 1:1, so a 30px drag reveals 30px.
connection.onPostScroll(Offset(0f, 30f), Offset(0f, 0f), NestedScrollSource.UserInput)
assertEquals(-85f, state.topHeightOffset)
assertEquals(-35f, state.bottomHeightOffset)
assertEquals(-70f, state.topHeightOffset)
assertEquals(-20f, state.bottomHeightOffset)
}
@Test
@@ -100,26 +100,27 @@ class DisappearingBarNestedScrollTest {
val connection = nsc(state)
// The list consumed 20px of a 40px reveal drag; 20 more was left as overscroll.
// The bars should move by the total 40 (damped to 20 on reveal), not just one half.
// The bars should move by the total 40, not just one of the halves.
connection.onPostScroll(Offset(0f, 20f), Offset(0f, 20f), NestedScrollSource.UserInput)
assertEquals(-30f, state.topHeightOffset)
assertEquals(-30f, state.bottomHeightOffset)
assertEquals(-10f, state.topHeightOffset)
assertEquals(-10f, state.bottomHeightOffset)
}
@Test
fun `revealing is less sensitive than hiding for the same drag distance`() {
fun `revealing tracks the finger 1 to 1, matching the hide rate so the bar stays glued to content`() {
// Hiding a 40px drag moves the bars the full 40px...
val hiding = state(topLimit = 100f, bottomLimit = 100f)
nsc(hiding).onPostScroll(Offset(0f, -40f), Offset(0f, 0f), NestedScrollSource.UserInput)
assertEquals(-40f, hiding.topHeightOffset)
// ...while revealing the same 40px from fully hidden only brings back 20px.
// ...and revealing the same 40px from fully hidden brings back the full 40px, so when the
// list returns to the top the bar is fully revealed with no blank band beneath it.
val revealing = state(topLimit = 100f, bottomLimit = 100f)
revealing.topHeightOffset = -100f
revealing.bottomHeightOffset = -100f
nsc(revealing).onPostScroll(Offset(0f, 40f), Offset(0f, 0f), NestedScrollSource.UserInput)
assertEquals(-80f, revealing.topHeightOffset)
assertEquals(-60f, revealing.topHeightOffset)
}
@Test
@@ -93,4 +93,49 @@ class DisappearingBarStateTest {
assertTrue("top bar overshot to $peakTop", peakTop <= 0.5f)
assertTrue("bottom bar overshot to $peakBottom", peakBottom <= 0.5f)
}
@Test
fun `a partial collapse that never reached the hidden edge settles back into view`() =
runTest {
// The bar is past the halfway point but was only ever scrolled here from the top — it
// never reached -limit, so the content hasn't moved a full bar height. Snapping it fully
// hidden would expose a blank band, so it must settle back to visible instead.
val state = state(topLimit = 100f, bottomLimit = 50f)
state.topHeightOffset = -80f
peakOffsetsDuring(state) { state.settleToNearestEdge() }
assertEquals(0f, state.topHeightOffset, 0.01f)
}
@Test
fun `a small reveal after fully hiding settles back to hidden, not into view`() =
runTest {
// Drive the bar to its hidden edge first (content has now scrolled a full bar height),
// then nudge it back a little — the small reverse drag a finger makes catching a scroll.
// Because it genuinely reached the hidden edge, snapping back hidden leaves no gap, so a
// sub-halfway reveal must not pop the chrome back open.
val state = state(topLimit = 100f, bottomLimit = 50f)
state.topHeightOffset = -100f
state.topHeightOffset = -90f
peakOffsetsDuring(state) { state.settleToNearestEdge() }
assertEquals(-100f, state.topHeightOffset, 0.01f)
}
@Test
fun `returning fully into view re-arms the gap guard so the next near-top collapse settles open`() =
runTest {
// Hide fully (arms the latch), come all the way back to visible (disarms it), then do a
// small near-top collapse again. It must settle open, proving the latch resets at 0.
val state = state(topLimit = 100f, bottomLimit = 50f)
state.topHeightOffset = -100f
state.topHeightOffset = 0f
state.topHeightOffset = -80f
peakOffsetsDuring(state) { state.settleToNearestEdge() }
assertEquals(0f, state.topHeightOffset, 0.01f)
}
}
@@ -42,13 +42,23 @@ import com.vitorpamplona.quartz.nip87Ecash.recommendation.MintRecommendationEven
* Query state for the NIP-60 / NIP-61 wallet subscription.
*
* `pubkey` is the wallet owner used both as `authors=` for their own
* NIP-60 events and as the `#p` tag value for inbound nutzaps. `relays` is
* the union of relays to subscribe on (NIP-65 outbox + DM relays at minimum).
* NIP-60 events and as the `#p` tag value for inbound nutzaps.
*
* The two filters read from different relay sets, following the NIP-65
* outbox model:
* - [ownEventRelays] the user's own write/outbox relays, where they
* published their NIP-60 wallet/token/history events. Restoring those
* means reading from where they were written.
* - [inboxRelays] where *other* people deliver kind:9321 nutzaps to this
* user. Per NIP-61 the source of truth is the `relay` tags in the user's
* own kind:10019; in practice we listen on the union of those plus the
* user's NIP-65 inbox + DM relays so a nutzap can't slip past us.
*/
@Immutable
data class CashuWalletQueryState(
val pubkey: HexKey,
val relays: Set<NormalizedRelayUrl>,
val ownEventRelays: Set<NormalizedRelayUrl>,
val inboxRelays: Set<NormalizedRelayUrl>,
)
/**
@@ -91,11 +101,9 @@ private class CashuWalletSubAssembler(
if (keys.isEmpty()) return null
val pubkey = keys.first().pubkey
val relays =
keys
.flatMap { it.relays }
.toSet()
.ifEmpty { return null }
val ownEventRelays = keys.flatMap { it.ownEventRelays }.toSet()
val inboxRelays = keys.flatMap { it.inboxRelays }.toSet()
if (ownEventRelays.isEmpty() && inboxRelays.isEmpty()) return null
val ownedFilter =
Filter(
@@ -121,18 +129,26 @@ private class CashuWalletSubAssembler(
tags = mapOf("p" to listOf(pubkey)),
)
return relays.flatMap { relay ->
val sinceTime = since?.get(relay)?.time
listOf(
// Own NIP-60 events are read from the user's outbox; inbound nutzaps
// from the user's inbox set. A relay that appears in both gets both
// filters.
val ownedSubs =
ownEventRelays.map { relay ->
val sinceTime = since?.get(relay)?.time
RelayBasedFilter(
relay,
if (sinceTime != null) ownedFilter.copy(since = sinceTime) else ownedFilter,
),
)
}
val inboundSubs =
inboxRelays.map { relay ->
val sinceTime = since?.get(relay)?.time
RelayBasedFilter(
relay,
if (sinceTime != null) inboundNutzapsFilter.copy(since = sinceTime) else inboundNutzapsFilter,
),
)
}
)
}
return ownedSubs + inboundSubs
}
}
@@ -153,9 +153,11 @@ class CashuWalletOps(
val walletEvent = signer.sign(walletTemplate)
publish(walletEvent)
// Populate `relay` tags so senders know where to publish nutzaps
// without these, they fall back to NIP-65 outbox and may miss our
// subscription scope on relays we don't read from.
// Populate `relay` tags so senders know where to publish nutzaps.
// Per NIP-61 these are the relays where the recipient reads incoming
// token events, so callers pass our inbox-side relays here (NIP-65
// outbox model). Without them, senders fall back to NIP-65 and may
// publish where we don't subscribe for inbound nutzaps.
val nutzapInfoTemplate =
NutzapInfoEvent.build(
mints = mints.map { NutzapMintTag(it, listOf("sat")) },
+6 -6
View File
@@ -94,18 +94,18 @@
"Slovenian"
]
},
{
"user": "summoner001",
"languages": [
"Hungarian"
]
},
{
"user": "hypnotichemionus4",
"languages": [
"Chinese Simplified"
]
},
{
"user": "summoner001",
"languages": [
"Hungarian"
]
},
{
"user": "vitorpamplona",
"languages": []