diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/model/zaps/UserZaps.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/model/zaps/UserZaps.kt deleted file mode 100644 index fcf530c0d..000000000 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/model/zaps/UserZaps.kt +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2024 Vitor Pamplona - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package com.vitorpamplona.quartz.events.zaps - -import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.ui.screen.ZapReqResponse -import com.vitorpamplona.quartz.events.LnZapEventInterface - -object UserZaps { - fun forProfileFeed(zaps: Map?): List { - if (zaps == null) return emptyList() - - return ( - zaps - .mapNotNull { entry -> entry.value?.let { ZapReqResponse(entry.key, it) } } - .sortedBy { (it.zapEvent.event as? LnZapEventInterface)?.amount() } - .reversed() - ) - } -} diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileZapsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileZapsFeedFilter.kt index 334152829..3915b0d6e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileZapsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileZapsFeedFilter.kt @@ -20,16 +20,30 @@ */ package com.vitorpamplona.amethyst.ui.dal +import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.ui.screen.ZapReqResponse -import com.vitorpamplona.quartz.events.zaps.UserZaps +import com.vitorpamplona.quartz.events.LnZapEventInterface class UserProfileZapsFeedFilter( val user: User, ) : FeedFilter() { override fun feedKey(): String = user.pubkeyHex - override fun feed(): List = UserZaps.forProfileFeed(user.zaps) + override fun feed(): List = forProfileFeed(user.zaps) override fun limit() = 400 + + companion object { + fun forProfileFeed(zaps: Map?): List { + if (zaps == null) return emptyList() + + return ( + zaps + .mapNotNull { entry -> entry.value?.let { ZapReqResponse(entry.key, it) } } + .sortedBy { (it.zapEvent.event as? LnZapEventInterface)?.amount() } + .reversed() + ) + } + } } diff --git a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/zaps/UserZapsTest.kt b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/zaps/UserProfileZapsFeedFilterTest.kt similarity index 91% rename from amethyst/src/test/java/com/vitorpamplona/amethyst/service/zaps/UserZapsTest.kt rename to amethyst/src/test/java/com/vitorpamplona/amethyst/service/zaps/UserProfileZapsFeedFilterTest.kt index 7d4475efd..df49e615d 100644 --- a/amethyst/src/test/java/com/vitorpamplona/amethyst/service/zaps/UserZapsTest.kt +++ b/amethyst/src/test/java/com/vitorpamplona/amethyst/service/zaps/UserProfileZapsFeedFilterTest.kt @@ -21,16 +21,16 @@ package com.vitorpamplona.amethyst.service.zaps import com.vitorpamplona.amethyst.model.Note +import com.vitorpamplona.amethyst.ui.dal.UserProfileZapsFeedFilter import com.vitorpamplona.quartz.encoders.HexKey import com.vitorpamplona.quartz.events.LnZapEventInterface -import com.vitorpamplona.quartz.events.zaps.UserZaps import io.mockk.every import io.mockk.mockk import org.junit.Assert import org.junit.Test import java.math.BigDecimal -class UserZapsTest { +class UserProfileZapsFeedFilterTest { @Test fun nothing() { Assert.assertEquals(1, 1) @@ -38,7 +38,7 @@ class UserZapsTest { @Test fun user_without_zaps() { - val actual = UserZaps.forProfileFeed(zaps = null) + val actual = UserProfileZapsFeedFilter.forProfileFeed(zaps = null) Assert.assertEquals(emptyList>(), actual) } @@ -53,7 +53,7 @@ class UserZapsTest { zapRequest to mockZapNoteWith("user-1", amount = 200), ) - val actual = UserZaps.forProfileFeed(zaps) + val actual = UserProfileZapsFeedFilter.forProfileFeed(zaps) Assert.assertEquals(1, actual.count()) Assert.assertEquals(zapRequest, actual.first().zapRequest)