Merge remote-tracking branch 'origin/main' into claude/fix-nests-audio-receiver-HCgOY

This commit is contained in:
Claude
2026-05-06 03:18:09 +00:00
13 changed files with 412 additions and 28 deletions
+16 -2
View File
@@ -12,10 +12,24 @@ echo "$JAVA_HOME"
echo "$(java -version)"
echo "Running test... "
# Single-variant pre-push tests. `./gradlew test` would compile six Android
# variants of :amethyst (play/fdroid × debug/release/benchmark) plus full
# native-libs merging per variant — ~6× the work of one variant. CI runs the
# multi-flavor matrix on push to main; pre-push only needs one happy path.
TASKS=(
:quartz:jvmTest
:commons:jvmTest
:nestsClient:jvmTest
:quic:jvmTest
:ammolite:testDebugUnitTest
:amethyst:testPlayDebugUnitTest
:cli:test
)
if [ "${CLAUDE_CODE_REMOTE:-}" = "true" ]; then
./gradlew test --quiet -x :desktopApp:test -x :desktopApp:upxDownload -x :desktopApp:vlcDownload
./gradlew "${TASKS[@]}" --quiet
else
./gradlew test --quiet
./gradlew "${TASKS[@]}" :desktopApp:test --quiet
fi
status=$?
+77 -12
View File
@@ -26,7 +26,17 @@ jobs:
with:
distribution: 'zulu'
java-version: 21
cache: gradle
# Remote Gradle build cache: writes on push to main, reads on PRs and
# other branches. Caches both `~/.gradle/caches/` and individual task
# outputs, so dependency-only changes hit the cache and skip recompiling
# downstream modules / re-merging native libs (~600MB of work on
# :amethyst alone). Replaces the narrower `cache: gradle` previously on
# actions/setup-java, which only cached `modules-2`.
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
- name: Linter (gradle)
run: ./gradlew spotlessCheck
@@ -63,10 +73,29 @@ jobs:
with:
distribution: 'zulu'
java-version: 21
cache: gradle
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
# Cache vlc-setup plugin downloads (VLC + UPX archives) keyed on the
# versions pinned in desktopApp/build.gradle.kts. Each OS gets its own
# cache namespace because the plugin downloads platform-specific archives.
# On a hit the vlcDownload / upxDownload tasks are up-to-date and we
# never touch get.videolan.org; on a miss (version bump or new runner)
# we fall back to fetching, which is what the in-build retry budget
# exists for.
- name: Cache vlc-setup downloads
uses: actions/cache@v4
with:
path: ~/.gradle/vlcSetup
key: vlcsetup-${{ runner.os }}-${{ hashFiles('desktopApp/build.gradle.kts') }}
restore-keys: |
vlcsetup-${{ runner.os }}-
- name: Test + Build Desktop (gradle)
run: ./gradlew :quartz:jvmTest :commons:jvmTest :nestsClient:jvmTest :cli:test :desktopApp:test :desktopApp:${{ matrix.desktop-task }} --no-daemon
run: ./gradlew :quartz:jvmTest :commons:jvmTest :nestsClient:jvmTest :cli:test :desktopApp:test :desktopApp:${{ matrix.desktop-task }}
# jpackage pins libicu to the build host's version (libicu74 on
# ubuntu-24.04). Rewrite the .deb so testers on other Debian/Ubuntu
@@ -97,10 +126,42 @@ jobs:
with:
distribution: 'zulu'
java-version: 21
cache: gradle
- name: Android Lint (gradle)
run: ./gradlew :amethyst:lintFdroidBenchmark :amethyst:lintPlayBenchmark --no-daemon
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
# Lint + focused unit tests + benchmark assembly in one Gradle invocation.
# Previously: one invocation for lint, one for `test` (which compiled all
# six amethyst variants × all flavors), one for `assembleBenchmark`
# (re-walking the same task graph). Combining them keeps the daemon hot
# across phases and lets task-level dedup (e.g. compileKotlin) only
# happen once.
#
# `-PdisableAbiSplits=true` produces a single non-split APK per
# (flavor, buildType) instead of 5 (4 ABIs + universal). The CI only
# uploads the universal-equivalent benchmark APK; per-ABI splits were
# being built and discarded, costing ~600MB of stripped_native_libs
# intermediates and several minutes per run.
#
# Test scope: only Debug unit tests for amethyst. The release/benchmark
# variants are compile-equivalent for unit-test purposes; running all six
# adds ~5× the kotlinc work without catching new defects on PRs. Push to
# main still gets the full test matrix via the production-build path.
- name: Test + Build Android (gradle)
run: |
./gradlew \
:amethyst:lintFdroidBenchmark \
:amethyst:lintPlayBenchmark \
:quartz:jvmTest \
:commons:jvmTest \
:nestsClient:jvmTest \
:ammolite:testDebugUnitTest \
:amethyst:testFdroidDebugUnitTest \
:amethyst:testPlayDebugUnitTest \
:amethyst:assembleBenchmark \
-PdisableAbiSplits=true
- name: Upload Android Lint Reports
uses: actions/upload-artifact@v7
@@ -109,31 +170,35 @@ jobs:
name: Android Lint Reports
path: amethyst/build/reports/lint-results-*.html
- name: Test + Build Android (gradle)
run: ./gradlew test assembleBenchmark --no-daemon
- name: Android Test Report
uses: asadmansr/android-test-report-action@v1.2.0
if: always()
- name: Upload Test Results
uses: actions/upload-artifact@v7
if: always()
if: failure()
with:
name: Test Reports
path: amethyst/build/reports
# With -PdisableAbiSplits=true the APK is named without the ABI/universal
# suffix: amethyst-<flavor>-benchmark.apk. Glob both forms so this still
# works if a contributor runs CI on a branch that doesn't pass the flag.
- name: Upload Play APK Benchmark
uses: actions/upload-artifact@v7
with:
name: Play Benchmark APK
path: amethyst/build/outputs/apk/play/benchmark/amethyst-play-universal-benchmark.apk
path: |
amethyst/build/outputs/apk/play/benchmark/amethyst-play-benchmark.apk
amethyst/build/outputs/apk/play/benchmark/amethyst-play-universal-benchmark.apk
- name: Upload FDroid APK Benchmark
uses: actions/upload-artifact@v7
with:
name: FDroid Benchmark APK
path: amethyst/build/outputs/apk/fdroid/benchmark/amethyst-fdroid-universal-benchmark.apk
path: |
amethyst/build/outputs/apk/fdroid/benchmark/amethyst-fdroid-benchmark.apk
amethyst/build/outputs/apk/fdroid/benchmark/amethyst-fdroid-universal-benchmark.apk
- name: Upload Compose Reports
uses: actions/upload-artifact@v7
+25 -3
View File
@@ -142,10 +142,32 @@ android {
]
}
// Opt-in fast-build flags. Default behavior is unchanged.
//
// -PdisableAbiSplits=true skip per-ABI APK splits; produces a single
// APK per (flavor, buildType) instead of 5.
// Cuts ~600 MB of intermediates and several
// minutes off CI.
// -PdisableUniversalApk=true when ABI splits are enabled, skip the
// extra universal APK output. (No effect
// when disableAbiSplits is also set, since
// there are no splits to add to.)
// -Pamethyst.skipMapping=true disable R8 minification on release and
// benchmark. APK is larger, but builds are
// much faster and outputs/mapping/ (~260MB)
// is not produced. Local-dev and PR-CI use
// only — release pipelines must not set it.
def disableAbiSplits = providers.gradleProperty("disableAbiSplits")
.map { it.toBoolean() }.getOrElse(false)
def disableUniversalApk = providers.gradleProperty("disableUniversalApk")
.map { it.toBoolean() }.getOrElse(false)
def skipMapping = providers.gradleProperty("amethyst.skipMapping")
.map { it.toBoolean() }.getOrElse(false)
buildTypes {
release {
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), 'proguard-rules.pro'
minifyEnabled = true
minifyEnabled = !skipMapping
}
debug {
applicationIdSuffix '.debug'
@@ -186,10 +208,10 @@ android {
splits {
abi {
enable = true
enable = !disableAbiSplits
reset()
include "x86", "x86_64", "arm64-v8a", "armeabi-v7a"
universalApk = true
universalApk = !disableUniversalApk
}
}
@@ -83,6 +83,7 @@ import com.vitorpamplona.quartz.nip71Video.VideoVerticalEvent
import com.vitorpamplona.quartz.nip84Highlights.HighlightEvent
import com.vitorpamplona.quartz.nip88Polls.poll.PollEvent
import com.vitorpamplona.quartz.nipACWebRtcCalls.events.CallOfferEvent
import com.vitorpamplona.quartz.nipC7Chats.ChatEvent
import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.TimeoutCancellationException
@@ -495,6 +496,67 @@ class EventNotificationConsumer(
)
}
/**
* Marmot kind:445 group messages have no `p` tag (recipients are routed
* by the `h` tag carrying the nostr_group_id), so the cache-observer path
* in [NotificationDispatcher] can't match them to an account. They're
* dispatched here directly from [com.vitorpamplona.amethyst.ui.screen.loggedIn.GroupEventHandler]
* once [com.vitorpamplona.quartz.marmot.MarmotInboundProcessor] has
* decrypted the outer ChaCha20-Poly1305 layer and verified the inner
* MLS-signed payload.
*
* Typed to [ChatEvent] so the caller has to narrow first — reactions,
* control messages, and deletions stay silent at the type level,
* mirroring how NIP-17 (kind:14) is the only DM kind we notify.
*/
suspend fun notifyGroupMessage(
innerEvent: ChatEvent,
nostrGroupId: String,
account: Account,
) = withWakeLock {
Log.d(TAG, "New Marmot Group Message to Notify")
if (!notificationManager().areNotificationsEnabled()) return@withWakeLock
if (MainActivity.isResumed) return@withWakeLock
// old event being re-broadcast
if (innerEvent.createdAt < TimeUtils.fifteenMinutesAgo()) return@withWakeLock
// a message we ourselves sent
if (innerEvent.pubKey == account.signer.pubKey) return@withWakeLock
val chatroom = account.marmotGroupList.getOrCreateGroup(nostrGroupId)
val groupName = chatroom.displayName.value?.takeIf { it.isNotBlank() } ?: "Private group"
val sender = LocalCache.getOrCreateUser(innerEvent.pubKey)
val senderName = sender.toBestDisplayName()
val senderPicture = sender.profilePicture()
// Defensive fallback for the rare empty-content ChatEvent so the
// popup is still actionable. Non-chat inner kinds were filtered
// out at the call site by the ChatEvent type narrowing.
val body = innerEvent.content.takeIf { it.isNotBlank() } ?: "New message"
val accountNpub =
account.signer.pubKey
.hexToByteArray()
.toNpub()
// marmot:<groupHex>?account=<npub> — same scheme as notifyWelcome,
// taps deep-link straight to the group's chatroom.
val noteUri = "marmot:$nostrGroupId$ACCOUNT_QUERY_PARAM$accountNpub"
notificationManager()
.sendDMNotification(
id = innerEvent.id,
messageBody = "$senderName: $body",
senderName = groupName,
time = innerEvent.createdAt,
pictureUrl = senderPicture,
uri = noteUri,
applicationContext = applicationContext,
accountNpub = accountNpub,
accountPictureUrl = account.userProfile().profilePicture(),
chatroomMembers = null,
)
}
suspend fun decryptZapContentAuthor(
event: LnZapRequestEvent,
signer: NostrSigner,
@@ -51,6 +51,7 @@ import com.vitorpamplona.quartz.nip71Video.VideoVerticalEvent
import com.vitorpamplona.quartz.nip84Highlights.HighlightEvent
import com.vitorpamplona.quartz.nip88Polls.poll.PollEvent
import com.vitorpamplona.quartz.nipACWebRtcCalls.events.CallOfferEvent
import com.vitorpamplona.quartz.nipC7Chats.ChatEvent
import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.coroutines.CancellationException
@@ -222,4 +223,24 @@ class NotificationDispatcher(
Log.e(TAG, "Failed to dispatch Welcome notification ${event.id}", e)
}
}
/**
* Direct-invocation entry point for Marmot kind:445 group messages.
* Bypasses the cache-observer path because GroupEvents are routed by
* the `h` tag (nostr_group_id), not by `p` tag. Called from
* [com.vitorpamplona.amethyst.ui.screen.loggedIn.GroupEventHandler]
* once the MLS-decrypted inner event has been parsed and indexed.
*/
suspend fun notifyGroupMessage(
innerEvent: ChatEvent,
nostrGroupId: String,
account: Account,
) {
try {
consumer.notifyGroupMessage(innerEvent, nostrGroupId, account)
} catch (e: Exception) {
if (e is CancellationException) throw e
Log.e(TAG, "Failed to dispatch Group Message notification ${innerEvent.id}", e)
}
}
}
@@ -49,6 +49,7 @@ import com.vitorpamplona.quartz.nipACWebRtcCalls.events.CallIceCandidateEvent
import com.vitorpamplona.quartz.nipACWebRtcCalls.events.CallOfferEvent
import com.vitorpamplona.quartz.nipACWebRtcCalls.events.CallRejectEvent
import com.vitorpamplona.quartz.nipACWebRtcCalls.events.CallRenegotiateEvent
import com.vitorpamplona.quartz.nipC7Chats.ChatEvent
import com.vitorpamplona.quartz.utils.Log
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.sync.Mutex
@@ -660,6 +661,21 @@ class GroupEventHandler(
// re-persist would silently grow the on-disk log).
if (isNew) {
manager.persistDecryptedMessage(result.groupId, result.innerEventJson)
// GroupEvents have no `p` tag, so the cache-observer
// notification path can't route them. Fire the popup
// directly here — only on first-time decryption, so
// a relay re-broadcast or persist-replay doesn't
// double-notify. Restrict to ChatEvent (kind:9) so
// reactions, deletions, and control messages stay
// silent.
if (innerEvent is ChatEvent) {
Amethyst.instance.notificationDispatcher.notifyGroupMessage(
innerEvent,
result.groupId,
account,
)
}
}
}
@@ -22,6 +22,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.rooms.twopane
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
@@ -73,6 +74,7 @@ fun MessagesTwoPane(
val displayFeatures = calculateDisplayFeatures(act)
Scaffold(
modifier = Modifier.imePadding(),
topBar = {
UserDrawerSearchTopBar(accountViewModel, nav) { AmethystClickableIcon() }
},
@@ -43,12 +43,16 @@
<string name="login_with_a_private_key_to_be_able_to_boost_posts">Вы используете публичный ключ, они - только для чтения. Войдите в систему приватным ключом, чтобы продвигать записи</string>
<string name="login_with_a_private_key_to_like_posts">Вы используете публичный ключ, они - только для чтения. Войдите с приватным ключом, чтобы лайкать посты</string>
<string name="no_zap_amount_setup_long_press_to_change">Не настроены запы. Нажмите и удерживайте для настройки</string>
<string name="chat_zap_anonymous">Анонимный</string>
<string name="chat_clip_created_a_clip">создал клип</string>
<string name="login_with_a_private_key_to_be_able_to_send_zaps">Войдите с приватным ключом чтобы запать</string>
<string name="login_with_a_private_key_to_be_able_to_follow">Вы используете публичный ключ, они - только для чтения. Войдите в систему приватным ключом, чтобы иметь возможность подписаться</string>
<string name="login_with_a_private_key_to_be_able_to_unfollow">Вы используете публичный ключ, они - только для чтения. Войдите в систему приватным ключом, чтобы иметь возможность отписаться</string>
<string name="login_with_a_private_key_to_be_able_to_hide_word">Вы используете публичный ключ, они - только для чтения. Войдите в систему приватным ключом, чтобы иметь возможность скрыть слово или предложение</string>
<string name="login_with_a_private_key_to_be_able_to_show_word">Вы используете публичный ключ, они - только для чтения. Войдите в систему приватным ключом, чтобы иметь возможность показать слово или предложение</string>
<string name="login_with_a_private_key_to_be_able_to_change_settings">Вы используете публичный ключ. Войдите приватным ключом, чтобы редактировать</string>
<string name="login_with_a_private_key_to_be_able_to_upload">Вы используете публичный ключ, они - только для чтения. Войдите в систему приватным ключом, чтобы иметь возможность загружать</string>
<string name="unauthorized_exception_description">Подписчик не авторизовал расшифровку, необходимую для выполнения этой операции. Активируйте расшифровки NIP-44 в приложении для подписчика и попробуйте еще раз</string>
<string name="signer_not_found_exception">Подпись не найдена</string>
<string name="zaps">Запы</string>
<string name="view_count">Просмотры</string>
@@ -146,10 +150,14 @@
<string name="upload_file">Загрузить файл</string>
<string name="take_a_picture">Сделать фото</string>
<string name="record_a_video">Снять видео</string>
<string name="record_a_message">Записать сообщение</string>
<string name="record_a_message_title">Записать сообщение</string>
<string name="record_a_message_description">Нажмите и удерживайте, чтобы записать сообщение</string>
<string name="re_record">Перезаписать</string>
<string name="recording_indicator_description">Запись</string>
<string name="uploading">Загрузка…</string>
<string name="upload_error_title">Ошибка загрузки</string>
<string name="upload_error_voice_message_failed">Неудалось загрузить голосовое сообщение</string>
<string name="voice_preset_none">Отсутствует</string>
<string name="voice_preset_deep">Глубокий</string>
<string name="voice_preset_high">Высокий</string>
@@ -230,6 +238,7 @@
<string name="unfollow">Отписаться</string>
<string name="channel_created">Канал создан</string>
<string name="channel_information_changed_to">"Информация о канале изменена на"</string>
<string name="ephemeral_relay_chat">Исчезающий чат</string>
<string name="public_chat">Публичный чат</string>
<string name="posts_received">записей получено</string>
<string name="remove">Удалить</string>
@@ -336,6 +345,14 @@
<string name="bookmark_list_creation_screen_title">Новый список закладок</string>
<string name="bookmark_list_delete_btn_label">Удалить список закладок</string>
<string name="private_articles_label">Приватные статьи</string>
<string name="bookmark_remove_action_desc">Удалить закладку из списка</string>
<string name="bookmark_add_action_desc">Добавить закладку в список</string>
<string name="public_bookmark_add_action_label">Добавить в Публичные закладки</string>
<string name="private_bookmark_add_action_label">Добавить в Личные закладки</string>
<string name="bookmark_remove_action_label">Удалить из списка закладок</string>
<string name="bookmark_list_explainer">Метаданные списков закладок могут быть видны любым пользователем Nostr. Только ваши частные участники зашифрованы.</string>
<string name="move_bookmark_to_public_label">Переместить в публчный</string>
<string name="move_bookmark_to_private_label">Переместить в личные</string>
<string name="wallet_connect_service">Служба Wallet Connect</string>
<string name="wallet_connect_service_explainer">Позволяет оплачивать запы с помощью секрета, не выходя из приложения. Храните секрет в безопасности и по возможности используйте приватный релей</string>
<string name="wallet_connect_service_pubkey">Публичный ключ Wallet Connect</string>
@@ -343,6 +360,8 @@
<string name="wallet_connect_service_secret">Секрет Wallet Connect</string>
<string name="wallet_connect_service_show_secret">Показать секрет</string>
<string name="wallet_connect_service_secret_placeholder">nsec / приватный ключ в hex</string>
<string name="wallet_connect_status_connected">Подключено</string>
<string name="wallet_connect_manual_config">Дополнительно: ввести детали соединения вручную</string>
<string name="zap_type_section_explainer">Определяет, как отображается ваша личность, когда вы отправляете зап.</string>
<string name="wallet_connect_connect_app">Подключить кошелек</string>
<string name="pledge_amount_in_sats">Сумма взноса в sat</string>
@@ -381,6 +400,8 @@
<string name="content_description_add_video">Добавить видео</string>
<string name="content_description_add_document">Добавить документ</string>
<string name="add_content">Добавить к сообщению</string>
<string name="add_caption_example">Мой дорогой друг</string>
<string name="use_direct_url">Использовать прямой URL-адрес</string>
<string name="content_description">Описание содержимого</string>
<string name="content_description_example">Компания весёлых молодых людей</string>
<string name="zap_type">Тип запа</string>
@@ -393,7 +414,10 @@
<string name="zap_type_anonymous_explainer">Никто не видит отправителя платежа</string>
<string name="zap_type_nonzap">Не-зап</string>
<string name="zap_type_nonzap_explainer">Без следа в Nostr, обычный Lightning платеж</string>
<string name="post_anonymously_explainer">Опубликовать в качестве одноразовой идентификации. Ваша учетная запись не будет связана с этим ответом.</string>
<string name="anonymous_reply_warning">Этот ответ будет опубликован от новой анонимной идентификации</string>
<string name="file_server">Сервер для загрузки</string>
<string name="file_server_description">Выберите сервер для загрузки этого файла</string>
<string name="zap_forward_lnAddress">LnAddress или @User</string>
<string name="built_in_servers_description">Список Amethyst. Вы можете добавить его индивидуально или добавить список.</string>
<string name="uploading_state_uploading">Загрузка</string>
@@ -39,6 +39,7 @@ import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onSubscription
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.flow.toList
@@ -189,6 +190,18 @@ class ReconnectingNestsListenerTest {
// before the test thread races into the first emit.
val consumerSubscribed = CompletableDeferred<Unit>()
// Counter for frames the consumer has actually observed.
// Needed to break the FRAME1-delivery race: emit() into
// first.frames is non-suspending and just enqueues into
// the pump's slot. If we trigger a session swap before
// the pump's collect lambda runs (`frames.emit(it)` to
// the wrapper), collectLatest cancels iteration 1 mid-
// resume and FRAME1 is lost — consumer ends with 1/2
// frames and the async's withTimeout fires. The
// collector is single-coroutine so a plain StateFlow
// update is safe; the test thread reads it via .first.
val consumerProgress = MutableStateFlow(0)
// The wrapper backs handle.objects with a SharedFlow
// (frames.asSharedFlow); the cast lets us use
// SharedFlow.onSubscription, which fires AFTER the
@@ -201,6 +214,7 @@ class ReconnectingNestsListenerTest {
objectsAsShared
.onSubscription { consumerSubscribed.complete(Unit) }
.take(2)
.onEach { consumerProgress.value += 1 }
.toList()
}
}
@@ -220,6 +234,19 @@ class ReconnectingNestsListenerTest {
first.frames.emit(frame(byteArrayOf(0x01)))
// Wait for FRAME1 to traverse pump → wrapper.frames →
// consumer collector. Without this sync the next
// `first.fail(...)` can race ahead and trigger
// collectLatest cancellation of pump-iteration-1 while
// FRAME1 is still queued in first.frames; the cancel
// interrupts the pump's resume before its lambda runs
// and FRAME1 never reaches the wrapper. Consumer then
// observes only FRAME2 (1 frame ≠ take(2)) and the
// async's withTimeout fires after 5 s.
withTimeout(5_000L) {
consumerProgress.first { it >= 1 }
}
// Force a reconnect: fail the first listener, the
// orchestrator opens the next one.
first.fail("scripted-disconnect")
@@ -26,6 +26,7 @@ import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.normalizeRelayUrl
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
import com.vitorpamplona.quartz.nip01Core.store.ObservableEventStore
import com.vitorpamplona.quartz.nip01Core.store.ObservableEventStore.StoreChange
import com.vitorpamplona.quartz.nip01Core.store.sqlite.EventStore
import com.vitorpamplona.quartz.nip01Core.tags.hashtags.hashtag
import com.vitorpamplona.quartz.nip09Deletions.DeletionEvent
@@ -393,29 +394,41 @@ class EventStoreProjectionTest {
/**
* NIP-40 expiration drops slots only when the application calls
* `deleteExpiredEvents()` on the observable store projections
* no longer run their own ticker.
* no longer run their own ticker. Driven through the projection
* directly with a controllable clock so the SQL trigger's wall-
* clock check (`<= unixepoch()`) doesn't race the inserts and we
* don't need a real-time delay to simulate expiration. The full
* SQL sweep path is covered by `ExpirationTest.testDeletingExpiredEvents`.
*/
@Test
fun nip40ExpirationDroppedOnStoreSweep() =
runBlocking {
val time = TimeUtils.now()
// Both expirations safely in the future so the SQL
// trigger accepts both inserts unconditionally.
val safe = signer.sign(TextNoteEvent.build("safe", createdAt = time) { expiration(time + 100) })
val short = signer.sign(TextNoteEvent.build("short", createdAt = time) { expiration(time + 50) })
observable.insert(safe)
val short = signer.sign(TextNoteEvent.build("short", createdAt = time) { expiration(time + 1) })
observable.insert(short)
var fakeNow = time
val projection =
projectionOf<Event>(Filter(kinds = listOf(TextNoteEvent.KIND)))
projection.awaitLoaded()
assertEquals(2, projection.items.size)
EventStoreProjection<Event>(
observable,
listOf(Filter(kinds = listOf(TextNoteEvent.KIND))),
nowProvider = { fakeNow },
)
projection.seed()
assertEquals(2, projection.snapshot().items.size)
// Let the short expiration lapse, then ask the store to
// sweep — the projection drops the expired slot in
// response to the resulting StoreChange.Delete(Expired).
delay(2000)
observable.deleteExpiredEvents()
// Jump the clock past `short`'s expiration and replay the
// StoreChange.DeleteExpired the observable would emit
// after a sweep at fakeNow.
fakeNow = time + 75
projection.apply(StoreChange.DeleteExpired(asOf = fakeNow))
val after = projection.awaitItems { it.size == 1 }
val after = projection.snapshot().items
assertEquals(1, after.size)
assertEquals(safe.id, after[0].value.id)
}
+56
View File
@@ -0,0 +1,56 @@
# Material Symbols Subset
The font shipped at
`commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf`
is a **subset** of Google's [Material Symbols
Outlined](https://github.com/google/material-design-icons) variable font,
trimmed to only the codepoints referenced from
`commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/icons/symbols/MaterialSymbols.kt`.
| | Full upstream | Subset |
|---|---|---|
| Size | ~11 MB | ~410 KB |
| Glyphs | ~3500 | ~210 |
The subset cuts >10 MB out of every commons build artifact, every Android APK,
and every Desktop app bundle.
## When to regenerate
Run `subset.sh` whenever you:
- add or remove a `MaterialSymbol("\uXXXX")` entry in `MaterialSymbols.kt`
- pin a newer upstream font version
## Prerequisites
```bash
pip install fonttools brotli
```
## Regenerating
From the repo root:
```bash
./tools/material-symbols-subset/subset.sh
```
That downloads the upstream variable font, intersects its codepoints with the
ones referenced from `MaterialSymbols.kt`, and overwrites the checked-in
`material_symbols_outlined.ttf`.
If you already have an upstream `.ttf` on disk:
```bash
./tools/material-symbols-subset/subset.sh /path/to/MaterialSymbolsOutlined-Regular.ttf
```
Commit the regenerated `.ttf` alongside the `MaterialSymbols.kt` change.
## How it works
`pyftsubset` (from `fonttools`) reads the codepoints we care about, drops every
glyph and OpenType feature not reachable from those codepoints, and rewrites
`name`, `cmap`, and `GSUB` tables accordingly. The Compose resource pipeline
treats the result as a normal TTF — no code changes needed.
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
#
# Subset commons/.../material_symbols_outlined.ttf to only the codepoints
# referenced from MaterialSymbols.kt. The full Google variable font is ~11 MB
# (≈3500 glyphs); the subset is ~410 KB.
#
# Run this whenever MaterialSymbols.kt gains or loses a codepoint, or when
# pulling a newer upstream font release.
#
# Inputs:
# $1 (optional) — path to a full upstream MaterialSymbolsOutlined-Regular.ttf
# to subset. If omitted, the script downloads the variable
# font from Google Fonts.
#
# Output:
# Overwrites commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
SYMBOLS_KT="$REPO_ROOT/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/icons/symbols/MaterialSymbols.kt"
TARGET="$REPO_ROOT/commons/src/commonMain/composeResources/font/material_symbols_outlined.ttf"
if ! command -v pyftsubset >/dev/null 2>&1; then
echo "pyftsubset not found. Install with: pip install fonttools brotli" >&2
exit 1
fi
if [ "${1:-}" ]; then
SOURCE_TTF="$1"
else
SOURCE_TTF="$(mktemp -t material_symbols.XXXXXX.ttf)"
trap 'rm -f "$SOURCE_TTF"' EXIT
echo "Downloading upstream Material Symbols Outlined variable font..."
curl -fsSL -o "$SOURCE_TTF" \
"https://github.com/google/material-design-icons/raw/master/variablefont/MaterialSymbolsOutlined%5BFILL%2CGRAD%2Copsz%2Cwght%5D.ttf"
fi
CODEPOINTS_FILE="$(mktemp -t material_symbols_cp.XXXXXX.txt)"
trap 'rm -f "$CODEPOINTS_FILE" ${SOURCE_TTF:+}' EXIT
# Pull every \uXXXX literal out of MaterialSymbols.kt as U+XXXX, deduplicated.
grep -oE '\\u[A-Fa-f0-9]{4}' "$SYMBOLS_KT" | sort -u | sed 's/\\u/U+/' > "$CODEPOINTS_FILE"
count=$(wc -l < "$CODEPOINTS_FILE")
echo "Subsetting to $count codepoints from MaterialSymbols.kt"
pyftsubset "$SOURCE_TTF" \
--unicodes-file="$CODEPOINTS_FILE" \
--output-file="$TARGET" \
--layout-features='*' \
--no-hinting \
--desubroutinize \
--notdef-outline \
--recommended-glyphs \
--name-IDs='*' \
--name-legacy \
--name-languages='*' \
--glyph-names \
--symbol-cmap
echo "Wrote $TARGET ($(du -h "$TARGET" | cut -f1))"