Refactors EOSE management for Chatroom List
This commit is contained in:
+49
-53
@@ -49,37 +49,48 @@ class ChatroomListFilterAssembler(
|
|||||||
val latestEOSEs = EOSEAccount()
|
val latestEOSEs = EOSEAccount()
|
||||||
val chatRoomListKey = "ChatroomList"
|
val chatRoomListKey = "ChatroomList"
|
||||||
|
|
||||||
fun createMessagesToMeFilter(account: Account) =
|
fun since(key: ChatroomListState) =
|
||||||
|
latestEOSEs.users[key.account.userProfile()]
|
||||||
|
?.followList
|
||||||
|
?.get(chatRoomListKey)
|
||||||
|
?.relayList
|
||||||
|
|
||||||
|
fun newEose(
|
||||||
|
key: ChatroomListState,
|
||||||
|
relayUrl: String,
|
||||||
|
time: Long,
|
||||||
|
) {
|
||||||
|
latestEOSEs.addOrUpdate(
|
||||||
|
key.account.userProfile(),
|
||||||
|
chatRoomListKey,
|
||||||
|
relayUrl,
|
||||||
|
time,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createMessagesToMeFilter(key: ChatroomListState) =
|
||||||
TypedFilter(
|
TypedFilter(
|
||||||
types = setOf(FeedType.PRIVATE_DMS),
|
types = setOf(FeedType.PRIVATE_DMS),
|
||||||
filter =
|
filter =
|
||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(PrivateDmEvent.KIND),
|
kinds = listOf(PrivateDmEvent.KIND),
|
||||||
tags = mapOf("p" to listOf(account.userProfile().pubkeyHex)),
|
tags = mapOf("p" to listOf(key.account.userProfile().pubkeyHex)),
|
||||||
since =
|
since = since(key),
|
||||||
latestEOSEs.users[account.userProfile()]
|
|
||||||
?.followList
|
|
||||||
?.get(chatRoomListKey)
|
|
||||||
?.relayList,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createMessagesFromMeFilter(account: Account) =
|
fun createMessagesFromMeFilter(key: ChatroomListState) =
|
||||||
TypedFilter(
|
TypedFilter(
|
||||||
types = setOf(FeedType.PRIVATE_DMS),
|
types = setOf(FeedType.PRIVATE_DMS),
|
||||||
filter =
|
filter =
|
||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(PrivateDmEvent.KIND),
|
kinds = listOf(PrivateDmEvent.KIND),
|
||||||
authors = listOf(account.userProfile().pubkeyHex),
|
authors = listOf(key.account.userProfile().pubkeyHex),
|
||||||
since =
|
since = since(key),
|
||||||
latestEOSEs.users[account.userProfile()]
|
|
||||||
?.followList
|
|
||||||
?.get(chatRoomListKey)
|
|
||||||
?.relayList,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createChannelsCreatedbyMeFilter(account: Account) =
|
fun createChannelsCreatedbyMeFilter(key: ChatroomListState) =
|
||||||
TypedFilter(
|
TypedFilter(
|
||||||
types = setOf(FeedType.PUBLIC_CHATS),
|
types = setOf(FeedType.PUBLIC_CHATS),
|
||||||
filter =
|
filter =
|
||||||
@@ -89,17 +100,13 @@ class ChatroomListFilterAssembler(
|
|||||||
ChannelCreateEvent.KIND,
|
ChannelCreateEvent.KIND,
|
||||||
ChannelMetadataEvent.KIND,
|
ChannelMetadataEvent.KIND,
|
||||||
),
|
),
|
||||||
authors = listOf(account.userProfile().pubkeyHex),
|
authors = listOf(key.account.userProfile().pubkeyHex),
|
||||||
since =
|
since = since(key),
|
||||||
latestEOSEs.users[account.userProfile()]
|
|
||||||
?.followList
|
|
||||||
?.get(chatRoomListKey)
|
|
||||||
?.relayList,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun createMyChannelsFilter(account: Account): TypedFilter? {
|
fun createMyChannelsFilter(key: ChatroomListState): TypedFilter? {
|
||||||
val followingEvents = account.publicChatList.livePublicChatEventIdSet.value
|
val followingEvents = key.account.publicChatList.livePublicChatEventIdSet.value
|
||||||
|
|
||||||
if (followingEvents.isEmpty()) return null
|
if (followingEvents.isEmpty()) return null
|
||||||
|
|
||||||
@@ -110,18 +117,14 @@ class ChatroomListFilterAssembler(
|
|||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(ChannelCreateEvent.KIND),
|
kinds = listOf(ChannelCreateEvent.KIND),
|
||||||
ids = followingEvents.toList(),
|
ids = followingEvents.toList(),
|
||||||
since =
|
since = since(key),
|
||||||
latestEOSEs.users[account.userProfile()]
|
|
||||||
?.followList
|
|
||||||
?.get(chatRoomListKey)
|
|
||||||
?.relayList,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createLastChannelInfoFilter(account: Account): List<TypedFilter>? {
|
fun createLastChannelInfoFilter(key: ChatroomListState): List<TypedFilter>? {
|
||||||
val followingEvents =
|
val followingEvents =
|
||||||
account.publicChatList.livePublicChatEventIdSet.value
|
key.account.publicChatList.livePublicChatEventIdSet.value
|
||||||
|
|
||||||
if (followingEvents.isEmpty()) return null
|
if (followingEvents.isEmpty()) return null
|
||||||
|
|
||||||
@@ -133,15 +136,16 @@ class ChatroomListFilterAssembler(
|
|||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(ChannelMetadataEvent.KIND),
|
kinds = listOf(ChannelMetadataEvent.KIND),
|
||||||
tags = mapOf("e" to listOf(it)),
|
tags = mapOf("e" to listOf(it)),
|
||||||
|
since = since(key),
|
||||||
limit = 1,
|
limit = 1,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createLastMessageOfEachChannelFilter(account: Account): List<TypedFilter>? {
|
fun createLastMessageOfEachChannelFilter(key: ChatroomListState): List<TypedFilter>? {
|
||||||
val followingEvents =
|
val followingEvents =
|
||||||
account.publicChatList.livePublicChatEventIdSet.value
|
key.account.publicChatList.livePublicChatEventIdSet.value
|
||||||
|
|
||||||
if (followingEvents.isEmpty()) return null
|
if (followingEvents.isEmpty()) return null
|
||||||
|
|
||||||
@@ -152,11 +156,7 @@ class ChatroomListFilterAssembler(
|
|||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(ChannelMessageEvent.KIND),
|
kinds = listOf(ChannelMessageEvent.KIND),
|
||||||
tags = mapOf("e" to listOf(it)),
|
tags = mapOf("e" to listOf(it)),
|
||||||
since =
|
since = since(key),
|
||||||
latestEOSEs.users[account.userProfile()]
|
|
||||||
?.followList
|
|
||||||
?.get(chatRoomListKey)
|
|
||||||
?.relayList,
|
|
||||||
// Remember to consider spam that is being removed from the UI
|
// Remember to consider spam that is being removed from the UI
|
||||||
limit = 50,
|
limit = 50,
|
||||||
),
|
),
|
||||||
@@ -164,9 +164,9 @@ class ChatroomListFilterAssembler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createLastMessageOfEachEphemeralChatFilter(account: Account): List<TypedFilter>? {
|
fun createLastMessageOfEachEphemeralChatFilter(key: ChatroomListState): List<TypedFilter>? {
|
||||||
val followingEvents =
|
val followingEvents =
|
||||||
account.ephemeralChatList.liveEphemeralChatList.value
|
key.account.ephemeralChatList.liveEphemeralChatList.value
|
||||||
.map { it.id }
|
.map { it.id }
|
||||||
|
|
||||||
if (followingEvents.isEmpty()) return null
|
if (followingEvents.isEmpty()) return null
|
||||||
@@ -179,11 +179,7 @@ class ChatroomListFilterAssembler(
|
|||||||
SincePerRelayFilter(
|
SincePerRelayFilter(
|
||||||
kinds = listOf(EphemeralChatEvent.KIND),
|
kinds = listOf(EphemeralChatEvent.KIND),
|
||||||
tags = mapOf("d" to followingEvents),
|
tags = mapOf("d" to followingEvents),
|
||||||
since =
|
since = since(key),
|
||||||
latestEOSEs.users[account.userProfile()]
|
|
||||||
?.followList
|
|
||||||
?.get(chatRoomListKey)
|
|
||||||
?.relayList,
|
|
||||||
// Remember to consider spam that is being removed from the UI
|
// Remember to consider spam that is being removed from the UI
|
||||||
limit = 50,
|
limit = 50,
|
||||||
),
|
),
|
||||||
@@ -191,21 +187,21 @@ class ChatroomListFilterAssembler(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun mergeAllFilters(account: Account): List<TypedFilter>? =
|
fun mergeAllFilters(key: ChatroomListState): List<TypedFilter>? =
|
||||||
listOfNotNull(
|
listOfNotNull(
|
||||||
listOfNotNull(
|
listOfNotNull(
|
||||||
createMessagesToMeFilter(account),
|
createMessagesToMeFilter(key),
|
||||||
createMessagesFromMeFilter(account),
|
createMessagesFromMeFilter(key),
|
||||||
createMyChannelsFilter(account),
|
createMyChannelsFilter(key),
|
||||||
),
|
),
|
||||||
createLastChannelInfoFilter(account),
|
createLastChannelInfoFilter(key),
|
||||||
createLastMessageOfEachChannelFilter(account),
|
createLastMessageOfEachChannelFilter(key),
|
||||||
createLastMessageOfEachEphemeralChatFilter(account),
|
createLastMessageOfEachEphemeralChatFilter(key),
|
||||||
).flatten().ifEmpty { null }
|
).flatten().ifEmpty { null }
|
||||||
|
|
||||||
fun newSub(key: ChatroomListState): Subscription =
|
fun newSub(key: ChatroomListState): Subscription =
|
||||||
requestNewSubscription { time, relayUrl ->
|
requestNewSubscription { time, relayUrl ->
|
||||||
latestEOSEs.addOrUpdate(key.account.userProfile(), chatRoomListKey, relayUrl, time)
|
newEose(key, relayUrl, time)
|
||||||
}
|
}
|
||||||
|
|
||||||
val userSubscriptionMap = mutableMapOf<User, String>()
|
val userSubscriptionMap = mutableMapOf<User, String>()
|
||||||
@@ -228,7 +224,7 @@ class ChatroomListFilterAssembler(
|
|||||||
uniqueSubscribedAccounts.forEach {
|
uniqueSubscribedAccounts.forEach {
|
||||||
val user = it.account.userProfile()
|
val user = it.account.userProfile()
|
||||||
val sub = findOrCreateSubFor(it)
|
val sub = findOrCreateSubFor(it)
|
||||||
sub.typedFilters = mergeAllFilters(it.account)
|
sub.typedFilters = mergeAllFilters(it)
|
||||||
|
|
||||||
updated.add(user)
|
updated.add(user)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user