Merge branch 'vitorpamplona:main' into profiles-list-management
This commit is contained in:
@@ -2632,7 +2632,7 @@ object LocalCache : ILocalCache {
|
||||
// updates relay with a new event.
|
||||
getAddressableNoteIfExists(event.address())?.let { note ->
|
||||
note.event?.let { existingEvent ->
|
||||
if (existingEvent.createdAt > event.createdAt && !note.hasRelay(relay.url) && !deletionIndex.hasBeenDeleted(event)) {
|
||||
if (existingEvent.createdAt > event.createdAt && !note.hasRelay(relay.url) && !deletionIndex.hasBeenDeleted(event) && !event.isExpired()) {
|
||||
if (isDebug) {
|
||||
Log.d("LocalCache", "Updating ${relay.url.url} with a new version of ${event.kind} ${event.id} to ${existingEvent.id}")
|
||||
}
|
||||
|
||||
+16
-4
@@ -57,10 +57,11 @@ class SearchRelayListState(
|
||||
|
||||
fun getSearchRelayList(): SearchRelayListEvent? = getSearchRelayListNote().event as? SearchRelayListEvent
|
||||
|
||||
suspend fun normalizeSearchRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||
val event = note.event as? SearchRelayListEvent ?: settings.backupSearchRelayList
|
||||
return event?.let { decryptionCache.relays(it) } ?: DefaultSearchRelayList
|
||||
}
|
||||
fun searchListEvent(note: Note) = note.event as? SearchRelayListEvent ?: settings.backupSearchRelayList
|
||||
|
||||
suspend fun normalizeSearchRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> = searchListEvent(note)?.let { decryptionCache.relays(it) }?.ifEmpty { null } ?: DefaultSearchRelayList
|
||||
|
||||
suspend fun normalizeSearchRelayListWithBackupNoDefaults(note: Note): Set<NormalizedRelayUrl> = searchListEvent(note)?.let { decryptionCache.relays(it) } ?: emptySet()
|
||||
|
||||
val flow =
|
||||
getSearchRelayListFlow()
|
||||
@@ -73,6 +74,17 @@ class SearchRelayListState(
|
||||
emptySet(),
|
||||
)
|
||||
|
||||
val flowNoDefaults =
|
||||
getSearchRelayListFlow()
|
||||
.map { normalizeSearchRelayListWithBackupNoDefaults(it.note) }
|
||||
.onStart { emit(normalizeSearchRelayListWithBackupNoDefaults(getSearchRelayListNote())) }
|
||||
.flowOn(Dispatchers.Default)
|
||||
.stateIn(
|
||||
scope,
|
||||
SharingStarted.Companion.Eagerly,
|
||||
emptySet(),
|
||||
)
|
||||
|
||||
suspend fun saveRelayList(searchRelays: List<NormalizedRelayUrl>): SearchRelayListEvent {
|
||||
val relayListForSearch = getSearchRelayList()
|
||||
|
||||
|
||||
+18
-12
@@ -57,20 +57,15 @@ class Nip65RelayListState(
|
||||
|
||||
fun getNIP65RelayList(): AdvertisedRelayListEvent? = getNIP65RelayListNote().event as? AdvertisedRelayListEvent
|
||||
|
||||
fun normalizeNIP65WriteRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||
val event = note.event as? AdvertisedRelayListEvent ?: settings.backupNIP65RelayList
|
||||
return event?.writeRelaysNorm()?.toSet() ?: Constants.eventFinderRelays
|
||||
}
|
||||
fun nip65Event(note: Note) = note.event as? AdvertisedRelayListEvent ?: settings.backupNIP65RelayList
|
||||
|
||||
fun normalizeNIP65ReadRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||
val event = note.event as? AdvertisedRelayListEvent ?: settings.backupNIP65RelayList
|
||||
return event?.readRelaysNorm()?.toSet() ?: Constants.eventFinderRelays
|
||||
}
|
||||
fun normalizeNIP65WriteRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> = nip65Event(note)?.writeRelaysNorm()?.toSet() ?: Constants.eventFinderRelays
|
||||
|
||||
fun normalizeNIP65AllRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> {
|
||||
val event = note.event as? AdvertisedRelayListEvent ?: settings.backupNIP65RelayList
|
||||
return event?.relays()?.map { it.relayUrl }?.toSet() ?: Constants.eventFinderRelays
|
||||
}
|
||||
fun normalizeNIP65ReadRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> = nip65Event(note)?.readRelaysNorm()?.toSet() ?: Constants.eventFinderRelays
|
||||
|
||||
fun normalizeNIP65AllRelayListWithBackup(note: Note): Set<NormalizedRelayUrl> = nip65Event(note)?.relays()?.map { it.relayUrl }?.toSet() ?: Constants.eventFinderRelays
|
||||
|
||||
fun normalizeNIP65AllRelayListWithBackupNoDefaults(note: Note): Set<NormalizedRelayUrl> = nip65Event(note)?.relays()?.map { it.relayUrl }?.toSet() ?: emptySet()
|
||||
|
||||
val outboxFlow =
|
||||
getNIP65RelayListFlow()
|
||||
@@ -105,6 +100,17 @@ class Nip65RelayListState(
|
||||
emptySet(),
|
||||
)
|
||||
|
||||
val allFlowNoDefaults =
|
||||
getNIP65RelayListFlow()
|
||||
.map { normalizeNIP65AllRelayListWithBackupNoDefaults(it.note) }
|
||||
.onStart { emit(normalizeNIP65AllRelayListWithBackupNoDefaults(getNIP65RelayListNote())) }
|
||||
.flowOn(Dispatchers.Default)
|
||||
.stateIn(
|
||||
scope,
|
||||
SharingStarted.Eagerly,
|
||||
emptySet(),
|
||||
)
|
||||
|
||||
suspend fun saveRelayList(relays: List<AdvertisedRelayInfo>): AdvertisedRelayListEvent {
|
||||
val nip65RelayList = getNIP65RelayList()
|
||||
|
||||
|
||||
+2
-2
@@ -52,11 +52,11 @@ class TrustedRelayListsState(
|
||||
val flow: StateFlow<Set<NormalizedRelayUrl>> =
|
||||
combine(
|
||||
listOf(
|
||||
nip65RelayList.allFlow,
|
||||
nip65RelayList.allFlowNoDefaults,
|
||||
privateOutboxRelayList.flow,
|
||||
localRelayList.flow,
|
||||
dmRelayList.flow,
|
||||
searchRelayListState.flow,
|
||||
searchRelayListState.flowNoDefaults,
|
||||
trustedRelayList.flow,
|
||||
broadcastRelayList.flow,
|
||||
),
|
||||
|
||||
+1
-1
@@ -167,7 +167,7 @@ class EventNotificationConsumer(
|
||||
|
||||
// this is not verifiable
|
||||
if (LocalCache.justConsume(inner, null, true)) {
|
||||
event
|
||||
inner
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
+29
-10
@@ -20,9 +20,11 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@@ -30,11 +32,13 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.lifecycle.compose.LifecycleResumeEffect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||
import com.google.accompanist.permissions.isGranted
|
||||
import com.google.accompanist.permissions.rememberPermissionState
|
||||
import com.vitorpamplona.amethyst.Amethyst
|
||||
import com.vitorpamplona.amethyst.LocalPreferences
|
||||
import com.vitorpamplona.amethyst.R
|
||||
@@ -43,6 +47,7 @@ import com.vitorpamplona.amethyst.service.notifications.PushNotificationUtils
|
||||
import com.vitorpamplona.amethyst.service.relayClient.authCommand.compose.RelayAuthSubscription
|
||||
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.account.AccountFilterAssemblerSubscription
|
||||
import com.vitorpamplona.amethyst.ui.navigation.AppNavigation
|
||||
import com.vitorpamplona.amethyst.ui.navigation.navs.EmptyNav.scope
|
||||
import com.vitorpamplona.amethyst.ui.navigation.routes.Route
|
||||
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.SharedPreferencesViewModel
|
||||
@@ -51,7 +56,6 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.discover.datasource.Discove
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.home.datasource.HomeFilterAssemblerSubscription
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.video.datasource.VideoFilterAssemblerSubscription
|
||||
import com.vitorpamplona.quartz.nip55AndroidSigner.client.IActivityLauncher
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
@@ -140,15 +144,31 @@ fun ManageRelayServices(accountViewModel: AccountViewModel) {
|
||||
.collectAsStateWithLifecycle()
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class)
|
||||
@Composable
|
||||
fun NotificationRegistration(accountViewModel: AccountViewModel) {
|
||||
val scope = rememberCoroutineScope()
|
||||
var job = remember<Job?> { null }
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
LifecycleResumeEffect(key1 = accountViewModel) {
|
||||
Log.d("RegisterAccounts", "Registering for push notifications")
|
||||
job?.cancel()
|
||||
job =
|
||||
val notificationPermissionState = rememberPermissionState(Manifest.permission.POST_NOTIFICATIONS)
|
||||
|
||||
if (notificationPermissionState.status.isGranted) {
|
||||
LifecycleResumeEffect(key1 = accountViewModel, notificationPermissionState.status.isGranted) {
|
||||
Log.d("RegisterAccounts", "Registering for push notifications $notificationPermissionState")
|
||||
scope.launch {
|
||||
PushNotificationUtils.checkAndInit(
|
||||
LocalPreferences.allSavedAccounts(),
|
||||
accountViewModel::okHttpClientForTrustedRelays,
|
||||
)
|
||||
}
|
||||
|
||||
onPauseOrDispose {}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no need for push permissions before 33
|
||||
LifecycleResumeEffect(key1 = accountViewModel) {
|
||||
Log.d("RegisterAccounts", "Registering for push notifications")
|
||||
scope.launch {
|
||||
PushNotificationUtils.checkAndInit(
|
||||
LocalPreferences.allSavedAccounts(),
|
||||
@@ -156,8 +176,7 @@ fun NotificationRegistration(accountViewModel: AccountViewModel) {
|
||||
)
|
||||
}
|
||||
|
||||
onPauseOrDispose {
|
||||
job.cancel()
|
||||
onPauseOrDispose {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -68,11 +68,8 @@ class ChatMessageRelayListEvent(
|
||||
val tags =
|
||||
earlierVersion.tags
|
||||
.filter(RelayTag::notMatch)
|
||||
.plus(
|
||||
relays.map {
|
||||
RelayTag.assemble(it)
|
||||
},
|
||||
).toTypedArray()
|
||||
.plus(relays.map { RelayTag.assemble(it) })
|
||||
.toTypedArray()
|
||||
|
||||
return signer.sign(createdAt, KIND, tags, earlierVersion.content)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class RelayTag {
|
||||
fun match(tag: Array<String>) = tag.has(1) && tag[0] == TAG_NAME && tag[1].isNotEmpty()
|
||||
|
||||
@JvmStatic
|
||||
fun notMatch(tag: Array<String>) = tag.has(0) && tag[0] == TAG_NAME
|
||||
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
||||
|
||||
@JvmStatic
|
||||
fun parse(tag: Array<String>): NormalizedRelayUrl? {
|
||||
|
||||
@@ -33,7 +33,7 @@ class RelayTag {
|
||||
fun match(tag: Array<String>) = tag.has(1) && tag[0] == TAG_NAME && tag[1].isNotEmpty()
|
||||
|
||||
@JvmStatic
|
||||
fun notMatch(tag: Array<String>) = tag.has(0) && tag[0] == TAG_NAME
|
||||
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
||||
|
||||
@JvmStatic
|
||||
fun parse(tag: Array<String>): NormalizedRelayUrl? {
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ class RelayTag {
|
||||
fun match(tag: Array<String>) = tag.has(1) && tag[0] == TAG_NAME && tag[1].isNotEmpty()
|
||||
|
||||
@JvmStatic
|
||||
fun notMatch(tag: Array<String>) = tag.has(0) && tag[0] == TAG_NAME
|
||||
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
||||
|
||||
@JvmStatic
|
||||
fun parse(tag: Array<String>): NormalizedRelayUrl? {
|
||||
|
||||
@@ -33,7 +33,7 @@ class RelayTag {
|
||||
fun match(tag: Array<String>) = tag.has(1) && tag[0] == TAG_NAME && tag[1].isNotEmpty()
|
||||
|
||||
@JvmStatic
|
||||
fun notMatch(tag: Array<String>) = tag.has(0) && tag[0] == TAG_NAME
|
||||
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
||||
|
||||
@JvmStatic
|
||||
fun parse(tag: Array<String>): NormalizedRelayUrl? {
|
||||
|
||||
@@ -33,7 +33,7 @@ class RelayTag {
|
||||
fun match(tag: Array<String>) = tag.has(1) && tag[0] == TAG_NAME && tag[1].isNotEmpty()
|
||||
|
||||
@JvmStatic
|
||||
fun notMatch(tag: Array<String>) = tag.has(0) && tag[0] == TAG_NAME
|
||||
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
||||
|
||||
@JvmStatic
|
||||
fun shouldVanishFrom(
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ class AdvertisedRelayInfo(
|
||||
|
||||
fun match(tag: Array<String>) = tag.has(1) && tag[0] == TAG_NAME && tag[1].isNotEmpty()
|
||||
|
||||
fun notMatch(tag: Array<String>) = !match(tag)
|
||||
fun notMatch(tag: Array<String>) = !(tag.has(0) && tag[0] == TAG_NAME)
|
||||
|
||||
@JvmStatic
|
||||
fun parse(tag: Array<String>): AdvertisedRelayInfo? {
|
||||
|
||||
Reference in New Issue
Block a user