diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt index fee35be229..1f406816c9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt @@ -41,6 +41,12 @@ import kotlin.coroutines.cancellation.CancellationException object OnlineChecker { val checkOnlineCache = LruCache(100) + fun isCachedAndOffline(url: String?): Boolean { + if (url.isNullOrBlank()) return false + val cached = checkOnlineCache.get(url) + return cached != null && !cached.online && cached.timeInSecs > TimeUtils.fiveMinutesAgo() + } + fun isOnlineCached(url: String?): Boolean { if (url.isNullOrBlank()) return false val cached = checkOnlineCache.get(url) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt index 118149e562..2b1d0720ca 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/DiscoverLiveFeedFilter.kt @@ -31,6 +31,7 @@ import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.author.AuthorsByPr import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.community.SingleCommunityTopNavFilter import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.muted.MutedAuthorsByOutboxTopNavFilter import com.vitorpamplona.amethyst.model.topNavFeeds.noteBased.muted.MutedAuthorsByProxyTopNavFilter +import com.vitorpamplona.amethyst.service.OnlineChecker import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter import com.vitorpamplona.amethyst.ui.dal.FilterByListParams import com.vitorpamplona.quartz.nip51Lists.muteList.MuteListEvent @@ -102,7 +103,7 @@ open class DiscoverLiveFeedFilter( return items .sortedWith( compareBy( - { convertStatusToOrder((it.event as? LiveActivitiesEvent)?.status()) }, + { convertStatusToOrder((it.event as? LiveActivitiesEvent)) }, { participantCounts[it] }, { allParticipants[it] }, { (it.event as? LiveActivitiesEvent)?.starts() ?: it.createdAt() }, @@ -111,11 +112,21 @@ open class DiscoverLiveFeedFilter( ).reversed() } - fun convertStatusToOrder(status: StatusTag.STATUS?): Int = - when (status) { - StatusTag.STATUS.LIVE -> 2 + fun convertStatusToOrder(event: LiveActivitiesEvent?): Int { + if (event == null) return 0 + val url = event.streaming() + if (url == null) return 0 + return when (event.status()) { + StatusTag.STATUS.LIVE -> { + if (OnlineChecker.isCachedAndOffline(url)) { + 0 + } else { + 2 + } + } StatusTag.STATUS.PLANNED -> 1 StatusTag.STATUS.ENDED -> 0 else -> 0 } + } }