Fixing the Relay view in Profile
This commit is contained in:
@@ -149,7 +149,7 @@ object LocalCache {
|
|||||||
val author = getOrCreateUser(event.pubKey.toHexKey())
|
val author = getOrCreateUser(event.pubKey.toHexKey())
|
||||||
|
|
||||||
if (relay != null) {
|
if (relay != null) {
|
||||||
author.addRelay(relay, event.createdAt)
|
author.addRelayBeingUsed(relay, event.createdAt)
|
||||||
note.addRelay(relay)
|
note.addRelay(relay)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ object LocalCache {
|
|||||||
fun consume(event: ContactListEvent) {
|
fun consume(event: ContactListEvent) {
|
||||||
val user = getOrCreateUser(event.pubKey.toHexKey())
|
val user = getOrCreateUser(event.pubKey.toHexKey())
|
||||||
|
|
||||||
if (event.createdAt > user.updatedFollowsAt && event.follows.size > 0) {
|
if (event.createdAt > user.updatedFollowsAt && event.follows.isNotEmpty()) {
|
||||||
// Saves relay list only if it's a user that is currently been seen
|
// Saves relay list only if it's a user that is currently been seen
|
||||||
user.latestContactList = event
|
user.latestContactList = event
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ object LocalCache {
|
|||||||
val author = getOrCreateUser(event.pubKey.toHexKey())
|
val author = getOrCreateUser(event.pubKey.toHexKey())
|
||||||
|
|
||||||
if (relay != null) {
|
if (relay != null) {
|
||||||
author.addRelay(relay, event.createdAt)
|
author.addRelayBeingUsed(relay, event.createdAt)
|
||||||
note.addRelay(relay)
|
note.addRelay(relay)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +440,7 @@ object LocalCache {
|
|||||||
val author = getOrCreateUser(event.pubKey.toHexKey())
|
val author = getOrCreateUser(event.pubKey.toHexKey())
|
||||||
|
|
||||||
if (relay != null) {
|
if (relay != null) {
|
||||||
author.addRelay(relay, event.createdAt)
|
author.addRelayBeingUsed(relay, event.createdAt)
|
||||||
note.addRelay(relay)
|
note.addRelay(relay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ class User(val pubkeyHex: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addRelay(relay: Relay, eventTime: Long) {
|
fun addRelayBeingUsed(relay: Relay, eventTime: Long) {
|
||||||
val here = relaysBeingUsed[relay.url]
|
val here = relaysBeingUsed[relay.url]
|
||||||
if (here == null) {
|
if (here == null) {
|
||||||
relaysBeingUsed = relaysBeingUsed + Pair(relay.url, RelayInfo(relay.url, eventTime, 1))
|
relaysBeingUsed = relaysBeingUsed + Pair(relay.url, RelayInfo(relay.url, eventTime, 1))
|
||||||
|
|||||||
@@ -527,7 +527,7 @@ fun NoteDropDownMenu(note: Note, popupExpanded: Boolean, onDismiss: () -> Unit,
|
|||||||
DropdownMenuItem(onClick = { accountViewModel.broadcast(note); onDismiss() }) {
|
DropdownMenuItem(onClick = { accountViewModel.broadcast(note); onDismiss() }) {
|
||||||
Text("Broadcast")
|
Text("Broadcast")
|
||||||
}
|
}
|
||||||
if (note.author != accountViewModel.accountLiveData.value?.account?.userProfile) {
|
if (note.author != accountViewModel.accountLiveData.value?.account?.userProfile()) {
|
||||||
Divider()
|
Divider()
|
||||||
DropdownMenuItem(onClick = {
|
DropdownMenuItem(onClick = {
|
||||||
note.author?.let {
|
note.author?.let {
|
||||||
|
|||||||
@@ -26,14 +26,17 @@ import com.vitorpamplona.amethyst.service.NostrHomeDataSource
|
|||||||
import com.vitorpamplona.amethyst.ui.actions.NewRelayListView
|
import com.vitorpamplona.amethyst.ui.actions.NewRelayListView
|
||||||
import com.vitorpamplona.amethyst.ui.note.RelayCompose
|
import com.vitorpamplona.amethyst.ui.note.RelayCompose
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.NonCancellable
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.update
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class RelayFeedViewModel: ViewModel() {
|
class RelayFeedViewModel: ViewModel() {
|
||||||
val order = compareByDescending<RelayInfo> { it.lastEvent }.thenByDescending { it.counter }.thenBy { it.url }
|
val order = compareByDescending<RelayInfo> { it.lastEvent }.thenByDescending { it.counter }.thenBy { it.url }
|
||||||
@@ -79,21 +82,24 @@ class RelayFeedViewModel: ViewModel() {
|
|||||||
currentUser = null
|
currentUser = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCleared() {
|
var handlerWaiting = AtomicBoolean()
|
||||||
currentUser?.let { unsubscribeTo(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
var handlerWaiting = false
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun invalidateData() {
|
private fun invalidateData() {
|
||||||
if (handlerWaiting) return
|
if (handlerWaiting.getAndSet(true)) return
|
||||||
|
|
||||||
handlerWaiting = true
|
handlerWaiting.set(true)
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
delay(100)
|
try {
|
||||||
refresh()
|
delay(50)
|
||||||
handlerWaiting = false
|
refresh()
|
||||||
|
} finally {
|
||||||
|
withContext(NonCancellable) {
|
||||||
|
handlerWaiting.set(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handlerWaiting.set(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,8 +198,7 @@ fun ProfileScreen(userId: String?, accountViewModel: AccountViewModel, navContro
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
val userState by baseUser.live().relays.observeAsState()
|
val userState by baseUser.live().relays.observeAsState()
|
||||||
val userRelaysBeingUsed =
|
val userRelaysBeingUsed = userState?.user?.relaysBeingUsed?.size ?: "--"
|
||||||
userState?.user?.relaysBeingUsed?.size ?: "--"
|
|
||||||
|
|
||||||
val userStateRelayInfo by baseUser.live().relayInfo.observeAsState()
|
val userStateRelayInfo by baseUser.live().relayInfo.observeAsState()
|
||||||
val userRelays = userStateRelayInfo?.user?.relays?.size ?: "--"
|
val userRelays = userStateRelayInfo?.user?.relays?.size ?: "--"
|
||||||
@@ -567,8 +566,26 @@ fun TabReports(user: User, accountViewModel: AccountViewModel, navController: Na
|
|||||||
fun TabRelays(user: User, accountViewModel: AccountViewModel, navController: NavController) {
|
fun TabRelays(user: User, accountViewModel: AccountViewModel, navController: NavController) {
|
||||||
val feedViewModel: RelayFeedViewModel = viewModel()
|
val feedViewModel: RelayFeedViewModel = viewModel()
|
||||||
|
|
||||||
LaunchedEffect(key1 = user) {
|
val lifeCycleOwner = LocalLifecycleOwner.current
|
||||||
feedViewModel.subscribeTo(user)
|
|
||||||
|
DisposableEffect(user) {
|
||||||
|
val observer = LifecycleEventObserver { source, event ->
|
||||||
|
if (event == Lifecycle.Event.ON_RESUME) {
|
||||||
|
println("Profile Relay Start")
|
||||||
|
feedViewModel.subscribeTo(user)
|
||||||
|
}
|
||||||
|
if (event == Lifecycle.Event.ON_PAUSE) {
|
||||||
|
println("Profile Relay Stop")
|
||||||
|
feedViewModel.unsubscribeTo(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lifeCycleOwner.lifecycle.addObserver(observer)
|
||||||
|
onDispose {
|
||||||
|
lifeCycleOwner.lifecycle.removeObserver(observer)
|
||||||
|
println("Profile Relay Dispose")
|
||||||
|
feedViewModel.unsubscribeTo(user)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(Modifier.fillMaxHeight()) {
|
Column(Modifier.fillMaxHeight()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user