Merge remote-tracking branch 'origin/HEAD'

This commit is contained in:
Vitor Pamplona
2023-03-05 12:43:57 -05:00
17 changed files with 94 additions and 97 deletions

View File

@@ -16,6 +16,10 @@ object ChannelFeedFilter: FeedFilter<Note>() {
// returns the last Note of each user.
override fun feed(): List<Note> {
return channel.notes?.values?.filter { account.isAcceptable(it) }?.sortedBy { it.createdAt() }?.reversed() ?: emptyList()
return channel.notes
?.values
?.filter { account.isAcceptable(it) }
?.sortedBy { it.createdAt() }
?.reversed() ?: emptyList()
}
}
}

View File

@@ -21,8 +21,13 @@ object ChatroomFeedFilter: FeedFilter<Note>() {
if (myAccount == null || myUser == null) return emptyList()
val messages = myAccount.userProfile().privateChatrooms[myUser] ?: return emptyList()
val messages = myAccount
.userProfile()
.privateChatrooms[myUser] ?: return emptyList()
return messages.roomMessages.filter { myAccount.isAcceptable(it) }.sortedBy { it.createdAt() }.reversed()
return messages.roomMessages
.filter { myAccount.isAcceptable(it) }
.sortedBy { it.createdAt() }
.reversed()
}
}
}

View File

@@ -15,19 +15,24 @@ object ChatroomListKnownFeedFilter: FeedFilter<Note>() {
me.hasSentMessagesTo(it) && account.isAcceptable(it)
}
val privateMessages = messagingWith.mapNotNull {
privateChatrooms[it]?.roomMessages?.sortedBy {
it.createdAt()
}?.lastOrNull {
it.event != null
}
val privateMessages = messagingWith.mapNotNull { it ->
privateChatrooms[it]
?.roomMessages
?.sortedBy { it.createdAt() }
?.lastOrNull { it.event != null }
}
val publicChannels = account.followingChannels().map {
it.notes.values.filter { account.isAcceptable(it) }.sortedBy { it.createdAt() }.lastOrNull { it.event != null }
val publicChannels = account.followingChannels().map { it ->
it.notes.values
.filter { account.isAcceptable(it) }
.sortedBy { it.createdAt() }
.lastOrNull { it.event != null }
}
return (privateMessages + publicChannels).filterNotNull().sortedBy { it.createdAt() }.reversed()
return (privateMessages + publicChannels)
.filterNotNull()
.sortedBy { it.createdAt() }
.reversed()
}
}
}

View File

@@ -15,15 +15,15 @@ object ChatroomListNewFeedFilter: FeedFilter<Note>() {
!me.hasSentMessagesTo(it) && account.isAcceptable(it)
}
val privateMessages = messagingWith.mapNotNull {
privateChatrooms[it]?.roomMessages?.sortedBy {
it.createdAt()
}?.lastOrNull {
it.event != null
}
val privateMessages = messagingWith.mapNotNull { it ->
privateChatrooms[it]
?.roomMessages
?.sortedBy { it.createdAt() }
?.lastOrNull { it.event != null }
}
return privateMessages.sortedBy { it.createdAt() }.reversed()
return privateMessages
.sortedBy { it.createdAt() }
.reversed()
}
}
}

View File

@@ -11,9 +11,9 @@ abstract class FeedFilter<T>() {
feed().take(1000)
}
Log.d("Time","${this.javaClass.simpleName} Feed in ${elapsed} with ${feed.size} objects")
Log.d("Time", "${this.javaClass.simpleName} Feed in ${elapsed} with ${feed.size} objects")
return feed
}
abstract fun feed(): List<T>
}
}

View File

@@ -17,12 +17,12 @@ object GlobalFeedFilter: FeedFilter<Note>() {
}
.filter {
// does not show events already in the public chat list
(it.channel() == null || it.channel() !in account.followingChannels())
// does not show people the user already follows
(it.channel() == null || it.channel() !in account.followingChannels())
// does not show people the user already follows
&& (it.author !in account.userProfile().follows)
}
.filter { account.isAcceptable(it) }
.sortedBy { it.createdAt() }
.reversed()
}
}

View File

@@ -7,4 +7,4 @@ object HiddenAccountsFeedFilter: FeedFilter<User>() {
lateinit var account: Account
override fun feed() = account.hiddenUsers()
}
}

View File

@@ -23,4 +23,4 @@ object HomeConversationsFeedFilter: FeedFilter<Note>() {
.sortedBy { it.createdAt() }
.reversed()
}
}
}

View File

@@ -14,7 +14,7 @@ object HomeNewThreadFeedFilter: FeedFilter<Note>() {
val user = account.userProfile()
val notes = LocalCache.notes.values
.filter {
.filter { it ->
(it.event is TextNoteEvent || it.event is RepostEvent || it.event is LongTextNoteEvent)
&& it.author in user.follows
// && account.isAcceptable(it) // This filter follows only. No need to check if acceptable
@@ -23,7 +23,7 @@ object HomeNewThreadFeedFilter: FeedFilter<Note>() {
}
val longFormNotes = LocalCache.addressables.values
.filter {
.filter { it ->
(it.event is TextNoteEvent || it.event is RepostEvent || it.event is LongTextNoteEvent)
&& it.author in user.follows
// && account.isAcceptable(it) // This filter follows only. No need to check if acceptable
@@ -35,4 +35,4 @@ object HomeNewThreadFeedFilter: FeedFilter<Note>() {
.sortedBy { it.createdAt() }
.reversed()
}
}
}

View File

@@ -2,68 +2,41 @@ package com.vitorpamplona.amethyst.ui.dal
import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
import com.vitorpamplona.amethyst.service.model.ChannelMetadataEvent
import com.vitorpamplona.amethyst.service.model.LnZapRequestEvent
import com.vitorpamplona.amethyst.service.model.ReactionEvent
import com.vitorpamplona.amethyst.service.model.RepostEvent
import com.vitorpamplona.amethyst.service.model.TextNoteEvent
import com.vitorpamplona.amethyst.service.model.*
object NotificationFeedFilter: FeedFilter<Note>() {
lateinit var account: Account
override fun feed(): List<Note> {
return account.userProfile().taggedPosts
return account.userProfile()
.taggedPosts
.asSequence()
.filter {
it.author == null
|| (!account.isHidden(it.author!!) && it.author != account.userProfile())
it.author == null
|| (!account.isHidden(it.author!!) && it.author != account.userProfile())
}
.filter {
it.event !is ChannelCreateEvent
&& it.event !is ChannelMetadataEvent
&& it.event !is LnZapRequestEvent
it.event !is ChannelCreateEvent
&& it.event !is ChannelMetadataEvent
&& it.event !is LnZapRequestEvent
}
.filter {
.filter { it ->
it.event !is TextNoteEvent
||
(
it.event is TextNoteEvent
&&
(
it.replyTo?.any { it.author == account.userProfile() } == true
||
account.userProfile() in it.directlyCiteUsers()
)
)
|| it.replyTo?.any { it.author == account.userProfile() } == true
|| account.userProfile() in it.directlyCiteUsers()
}
.filter {
it.event !is ReactionEvent
||
(
it.event is ReactionEvent
&&
(
it.replyTo?.lastOrNull()?.author == account.userProfile()
||
account.userProfile() in it.directlyCiteUsers()
)
)
|| it.replyTo?.lastOrNull()?.author == account.userProfile()
|| account.userProfile() in it.directlyCiteUsers()
}
.filter {
it.event !is RepostEvent
||
(
it.event is RepostEvent
&&
(
it.replyTo?.lastOrNull()?.author == account.userProfile()
||
account.userProfile() in it.directlyCiteUsers()
)
)
|| it.replyTo?.lastOrNull()?.author == account.userProfile()
|| account.userProfile() in it.directlyCiteUsers()
}
.sortedBy { it.createdAt() }
.toList()
.reversed()
}
}
}

View File

@@ -18,4 +18,4 @@ object ThreadFeedFilter: FeedFilter<Note>() {
fun loadThread(noteId: String?) {
this.noteId = noteId
}
}
}

View File

@@ -18,7 +18,6 @@ object UserProfileConversationsFeedFilter: FeedFilter<Note>() {
return user?.notes
?.filter { account?.isAcceptable(it) == true && !it.isNewThread() }
?.sortedBy { it.createdAt() }
?.reversed()
?: emptyList()
?.reversed() ?: emptyList()
}
}
}

View File

@@ -14,6 +14,7 @@ object UserProfileFollowersFeedFilter: FeedFilter<User>() {
}
override fun feed(): List<User> {
return user?.followers?.filter { account.isAcceptable(it) } ?: emptyList()
return user?.followers
?.filter { account.isAcceptable(it) } ?: emptyList()
}
}
}

View File

@@ -14,6 +14,8 @@ object UserProfileFollowsFeedFilter: FeedFilter<User>() {
}
override fun feed(): List<User> {
return user?.follows?.filter { account.isAcceptable(it) }?.reversed() ?: emptyList()
return user?.follows
?.filter { account.isAcceptable(it) }
?.reversed() ?: emptyList()
}
}
}

View File

@@ -17,10 +17,10 @@ object UserProfileNewThreadFeedFilter: FeedFilter<Note>() {
override fun feed(): List<Note> {
val longFormNotes = LocalCache.addressables.values.filter { it.author == user }
return user?.notes?.plus(longFormNotes)
return user?.notes
?.plus(longFormNotes)
?.filter { account?.isAcceptable(it) == true && it.isNewThread() }
?.sortedBy { it.createdAt() }
?.reversed()
?: emptyList()
?.reversed() ?: emptyList()
}
}
}

View File

@@ -12,6 +12,10 @@ object UserProfileReportsFeedFilter: FeedFilter<Note>() {
}
override fun feed(): List<Note> {
return user?.reports?.values?.flatten()?.sortedBy { it.createdAt() }?.reversed() ?: emptyList()
return user?.reports
?.values
?.flatten()
?.sortedBy { it.createdAt() }
?.reversed() ?: emptyList()
}
}
}

View File

@@ -5,14 +5,18 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.model.LnZapEvent
object UserProfileZapsFeedFilter: FeedFilter<Pair<Note,Note>>() {
object UserProfileZapsFeedFilter: FeedFilter<Pair<Note, Note>>() {
var user: User? = null
fun loadUserProfile(userId: String) {
user = LocalCache.checkGetOrCreateUser(userId)
}
override fun feed(): List<Pair<Note,Note>> {
return (user?.zaps?.filter { it.value != null }?.toList()?.sortedBy { (it.second?.event as? LnZapEvent)?.amount }?.reversed() ?: emptyList()) as List<Pair<Note, Note>>
override fun feed(): List<Pair<Note, Note>> {
return (user?.zaps
?.filter { it.value != null }
?.toList()
?.sortedBy { (it.second?.event as? LnZapEvent)?.amount }
?.reversed() ?: emptyList()) as List<Pair<Note, Note>>
}
}
}