Performance updates
This commit is contained in:
@@ -122,6 +122,8 @@ object NostrSingleEventDataSource : NostrDataSource("SingleEventFeed") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val singleEventChannel = requestNewChannel { time, relayUrl ->
|
val singleEventChannel = requestNewChannel { time, relayUrl ->
|
||||||
|
checkNotInMainThread()
|
||||||
|
|
||||||
eventsToWatch.forEach {
|
eventsToWatch.forEach {
|
||||||
val eose = it.lastReactionsDownloadTime[relayUrl]
|
val eose = it.lastReactionsDownloadTime[relayUrl]
|
||||||
if (eose == null) {
|
if (eose == null) {
|
||||||
@@ -159,16 +161,16 @@ object NostrSingleEventDataSource : NostrDataSource("SingleEventFeed") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addAddress(aTag: Note) {
|
fun addAddress(addressableNote: Note) {
|
||||||
if (!addressesToWatch.contains(aTag)) {
|
if (!addressesToWatch.contains(addressableNote)) {
|
||||||
addressesToWatch = addressesToWatch.plus(aTag)
|
addressesToWatch = addressesToWatch.plus(addressableNote)
|
||||||
invalidateFilters()
|
invalidateFilters()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeAddress(aTag: Note) {
|
fun removeAddress(addressableNote: Note) {
|
||||||
if (addressesToWatch.contains(aTag)) {
|
if (addressesToWatch.contains(addressableNote)) {
|
||||||
addressesToWatch = addressesToWatch.minus(aTag)
|
addressesToWatch = addressesToWatch.minus(addressableNote)
|
||||||
invalidateFilters()
|
invalidateFilters()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ import kotlinx.coroutines.withContext
|
|||||||
@OptIn(ExperimentalComposeUiApi::class)
|
@OptIn(ExperimentalComposeUiApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = null, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = null, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
|
||||||
val accountState by accountViewModel.accountLiveData.observeAsState()
|
val account = remember(accountViewModel) { accountViewModel.account }
|
||||||
val account = remember(accountState) { accountState?.account } ?: return
|
|
||||||
|
|
||||||
val postViewModel: NewPostViewModel = viewModel()
|
val postViewModel: NewPostViewModel = viewModel()
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ fun RichTextViewer(
|
|||||||
) {
|
) {
|
||||||
Column(modifier = modifier) {
|
Column(modifier = modifier) {
|
||||||
if (remember(content) { isMarkdown(content) }) {
|
if (remember(content) { isMarkdown(content) }) {
|
||||||
RenderContentAsMarkdown(content, backgroundColor, tags, nav)
|
RenderContentAsMarkdown(content, tags, nav)
|
||||||
} else {
|
} else {
|
||||||
RenderRegular(content, tags, canPreview, backgroundColor, accountViewModel, nav)
|
RenderRegular(content, tags, canPreview, backgroundColor, accountViewModel, nav)
|
||||||
}
|
}
|
||||||
@@ -292,7 +292,7 @@ fun RenderCustomEmoji(word: String, state: RichTextViewerState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun RenderContentAsMarkdown(content: String, backgroundColor: MutableState<Color>, tags: ImmutableListOfLists<String>?, nav: (String) -> Unit) {
|
private fun RenderContentAsMarkdown(content: String, tags: ImmutableListOfLists<String>?, nav: (String) -> Unit) {
|
||||||
val uri = LocalUriHandler.current
|
val uri = LocalUriHandler.current
|
||||||
val onClick = remember {
|
val onClick = remember {
|
||||||
{ link: String ->
|
{ link: String ->
|
||||||
@@ -391,10 +391,12 @@ private fun ObserveNIP19Event(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ObserveNote(note: Note, onRefresh: () -> Unit) {
|
fun ObserveNote(note: Note, onRefresh: () -> Unit) {
|
||||||
val noteState by note.live().metadata.observeAsState()
|
val loadedNoteId by note.live().metadata.map {
|
||||||
|
it.note.event?.id()
|
||||||
|
}.distinctUntilChanged().observeAsState(note.event?.id())
|
||||||
|
|
||||||
LaunchedEffect(key1 = noteState) {
|
LaunchedEffect(key1 = loadedNoteId) {
|
||||||
if (noteState?.note?.event != null) {
|
if (loadedNoteId != null) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
onRefresh()
|
onRefresh()
|
||||||
}
|
}
|
||||||
@@ -428,10 +430,12 @@ private fun ObserveNIP19User(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun ObserveUser(user: User, onRefresh: () -> Unit) {
|
private fun ObserveUser(user: User, onRefresh: () -> Unit) {
|
||||||
val userState by user.live().metadata.observeAsState()
|
val loadedUserMetaId by user.live().metadata.map {
|
||||||
|
it.user.info?.latestMetadata?.id
|
||||||
|
}.distinctUntilChanged().observeAsState(user.info?.latestMetadata?.id)
|
||||||
|
|
||||||
LaunchedEffect(key1 = userState) {
|
LaunchedEffect(key1 = loadedUserMetaId) {
|
||||||
if (userState?.user?.info != null) {
|
if (loadedUserMetaId != null) {
|
||||||
launch(Dispatchers.IO) {
|
launch(Dispatchers.IO) {
|
||||||
onRefresh()
|
onRefresh()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,9 +235,7 @@ open class CardFeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel() {
|
|||||||
val thisAccount = (localFilter as? NotificationFeedFilter)?.account
|
val thisAccount = (localFilter as? NotificationFeedFilter)?.account
|
||||||
val lastNotesCopy = if (thisAccount == lastAccount) lastNotes else null
|
val lastNotesCopy = if (thisAccount == lastAccount) lastNotes else null
|
||||||
|
|
||||||
if (lastNotesCopy != null && localFilter is AdditiveFeedFilter && oldNotesState is CardFeedState.Loaded) {
|
if (lastNotesCopy != null && localFilter is AdditiveFeedFilter && oldNotesState is CardFeedState.Loaded && lastFeedKey == localFilter.feedKey()) {
|
||||||
lastFeedKey = localFilter.feedKey()
|
|
||||||
|
|
||||||
val filteredNewList = localFilter.applyFilter(newItems)
|
val filteredNewList = localFilter.applyFilter(newItems)
|
||||||
|
|
||||||
if (filteredNewList.isEmpty()) return
|
if (filteredNewList.isEmpty()) return
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ abstract class FeedViewModel(val localFilter: FeedFilter<Note>) : ViewModel(), I
|
|||||||
|
|
||||||
fun refreshFromOldState(newItems: Set<Note>) {
|
fun refreshFromOldState(newItems: Set<Note>) {
|
||||||
val oldNotesState = _feedContent.value
|
val oldNotesState = _feedContent.value
|
||||||
if (localFilter is AdditiveFeedFilter && lastFeedKey != localFilter.feedKey()) {
|
if (localFilter is AdditiveFeedFilter && lastFeedKey == localFilter.feedKey()) {
|
||||||
if (oldNotesState is FeedState.Loaded) {
|
if (oldNotesState is FeedState.Loaded) {
|
||||||
val newList = localFilter.updateListWith(oldNotesState.feed.value, newItems.toSet()).toImmutableList()
|
val newList = localFilter.updateListWith(oldNotesState.feed.value, newItems.toSet()).toImmutableList()
|
||||||
if (!equalImmutableLists(newList, oldNotesState.feed.value)) {
|
if (!equalImmutableLists(newList, oldNotesState.feed.value)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user