Moving private messages and channel loading to a thread.
This commit is contained in:
@@ -1,21 +1,23 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.dal
|
package com.vitorpamplona.amethyst.ui.dal
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.Channel
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
|
|
||||||
object ChannelFeedFilter : AdditiveFeedFilter<Note>() {
|
object ChannelFeedFilter : AdditiveFeedFilter<Note>() {
|
||||||
lateinit var account: Account
|
lateinit var account: Account
|
||||||
lateinit var channel: Channel
|
var channelId: String? = null
|
||||||
|
|
||||||
fun loadMessagesBetween(accountLoggedIn: Account, channelId: String) {
|
fun loadMessagesBetween(accountLoggedIn: Account, channelId: String?) {
|
||||||
account = accountLoggedIn
|
this.account = accountLoggedIn
|
||||||
channel = LocalCache.getOrCreateChannel(channelId)
|
this.channelId = channelId
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the last Note of each user.
|
// returns the last Note of each user.
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
|
val processingChannel = channelId ?: return emptyList()
|
||||||
|
val channel = LocalCache.getOrCreateChannel(processingChannel)
|
||||||
|
|
||||||
return channel.notes
|
return channel.notes
|
||||||
.values
|
.values
|
||||||
.filter { account.isAcceptable(it) }
|
.filter { account.isAcceptable(it) }
|
||||||
@@ -24,6 +26,9 @@ object ChannelFeedFilter : AdditiveFeedFilter<Note>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun applyFilter(collection: Set<Note>): Set<Note> {
|
override fun applyFilter(collection: Set<Note>): Set<Note> {
|
||||||
|
val processingChannel = channelId ?: return emptySet()
|
||||||
|
val channel = LocalCache.getOrCreateChannel(processingChannel)
|
||||||
|
|
||||||
return collection
|
return collection
|
||||||
.filter { it.idHex in channel.notes.keys && account.isAcceptable(it) }
|
.filter { it.idHex in channel.notes.keys && account.isAcceptable(it) }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|||||||
@@ -3,21 +3,22 @@ package com.vitorpamplona.amethyst.ui.dal
|
|||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
|
||||||
|
|
||||||
object ChatroomFeedFilter : AdditiveFeedFilter<Note>() {
|
object ChatroomFeedFilter : AdditiveFeedFilter<Note>() {
|
||||||
var account: Account? = null
|
var account: Account? = null
|
||||||
var withUser: User? = null
|
var withUser: String? = null
|
||||||
|
|
||||||
fun loadMessagesBetween(accountIn: Account, userId: String) {
|
fun loadMessagesBetween(accountIn: Account, userId: String) {
|
||||||
account = accountIn
|
account = accountIn
|
||||||
withUser = LocalCache.checkGetOrCreateUser(userId)
|
withUser = userId
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the last Note of each user.
|
// returns the last Note of each user.
|
||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
|
val processingUser = withUser ?: return emptyList()
|
||||||
|
|
||||||
val myAccount = account
|
val myAccount = account
|
||||||
val myUser = withUser
|
val myUser = LocalCache.checkGetOrCreateUser(processingUser)
|
||||||
|
|
||||||
if (myAccount == null || myUser == null) return emptyList()
|
if (myAccount == null || myUser == null) return emptyList()
|
||||||
|
|
||||||
@@ -32,8 +33,10 @@ object ChatroomFeedFilter : AdditiveFeedFilter<Note>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun applyFilter(collection: Set<Note>): Set<Note> {
|
override fun applyFilter(collection: Set<Note>): Set<Note> {
|
||||||
|
val processingUser = withUser ?: return emptySet()
|
||||||
|
|
||||||
val myAccount = account
|
val myAccount = account
|
||||||
val myUser = withUser
|
val myUser = LocalCache.checkGetOrCreateUser(processingUser)
|
||||||
|
|
||||||
if (myAccount == null || myUser == null) return emptySet()
|
if (myAccount == null || myUser == null) return emptySet()
|
||||||
|
|
||||||
|
|||||||
@@ -190,16 +190,19 @@ fun NoteComposeInner(
|
|||||||
var popupExpanded by remember { mutableStateOf(false) }
|
var popupExpanded by remember { mutableStateOf(false) }
|
||||||
var showHiddenNote by remember { mutableStateOf(false) }
|
var showHiddenNote by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
var isAcceptable by remember { mutableStateOf(true) }
|
var isAcceptableAndCanPreview by remember { mutableStateOf(Pair(true, true)) }
|
||||||
var canPreview by remember { mutableStateOf(true) }
|
|
||||||
|
|
||||||
LaunchedEffect(key1 = noteReportsState) {
|
LaunchedEffect(key1 = noteReportsState) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
canPreview = note?.author === loggedIn ||
|
val newCanPreview = note?.author === loggedIn ||
|
||||||
(note?.author?.let { loggedIn.isFollowingCached(it) } ?: true) ||
|
(note?.author?.let { loggedIn.isFollowingCached(it) } ?: true) ||
|
||||||
!noteForReports.hasAnyReports()
|
!noteForReports.hasAnyReports()
|
||||||
|
|
||||||
isAcceptable = account.isAcceptable(noteForReports)
|
val newIsAcceptable = account.isAcceptable(noteForReports)
|
||||||
|
|
||||||
|
if (newIsAcceptable != isAcceptableAndCanPreview.first && newCanPreview != isAcceptableAndCanPreview.second) {
|
||||||
|
isAcceptableAndCanPreview = Pair(newIsAcceptable, newCanPreview)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +217,7 @@ fun NoteComposeInner(
|
|||||||
),
|
),
|
||||||
isBoostedNote
|
isBoostedNote
|
||||||
)
|
)
|
||||||
} else if (!isAcceptable && !showHiddenNote) {
|
} else if (!isAcceptableAndCanPreview.first && !showHiddenNote) {
|
||||||
if (!account.isHidden(noteForReports.author!!)) {
|
if (!account.isHidden(noteForReports.author!!)) {
|
||||||
HiddenNote(
|
HiddenNote(
|
||||||
account.getRelevantReports(noteForReports),
|
account.getRelevantReports(noteForReports),
|
||||||
@@ -340,18 +343,18 @@ fun NoteComposeInner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
is PrivateDmEvent -> {
|
is PrivateDmEvent -> {
|
||||||
RenderPrivateMessage(note, makeItShort, canPreview, backgroundColor, accountViewModel, navController)
|
RenderPrivateMessage(note, makeItShort, isAcceptableAndCanPreview.second, backgroundColor, accountViewModel, navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
is HighlightEvent -> {
|
is HighlightEvent -> {
|
||||||
RenderHighlight(note, makeItShort, canPreview, backgroundColor, accountViewModel, navController)
|
RenderHighlight(note, makeItShort, isAcceptableAndCanPreview.second, backgroundColor, accountViewModel, navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
is PollNoteEvent -> {
|
is PollNoteEvent -> {
|
||||||
RenderPoll(
|
RenderPoll(
|
||||||
note,
|
note,
|
||||||
makeItShort,
|
makeItShort,
|
||||||
canPreview,
|
isAcceptableAndCanPreview.second,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController
|
navController
|
||||||
@@ -362,7 +365,7 @@ fun NoteComposeInner(
|
|||||||
RenderTextEvent(
|
RenderTextEvent(
|
||||||
note,
|
note,
|
||||||
makeItShort,
|
makeItShort,
|
||||||
canPreview,
|
isAcceptableAndCanPreview.second,
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
navController
|
navController
|
||||||
|
|||||||
Reference in New Issue
Block a user