From e3acf4c250cc6fd3420b2ea8d3cee7231d3df77c Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 10 Jul 2025 18:22:38 -0400 Subject: [PATCH] Fixes some of the live stream flags when the event doesn't update. --- .../amethyst/ui/note/types/LiveActivity.kt | 2 +- .../StreamingStatusFlags.kt | 15 ++++++--- .../DiscoverLiveFeedFilter.kt | 2 +- .../nip53LiveActivities/LiveActivityCard.kt | 2 +- .../streaming/LiveActivitiesEvent.kt | 31 ++++++++----------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt index f6a5f2f93b..4944db6f0e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt @@ -139,7 +139,7 @@ fun RenderLiveActivityEventInner( val subject = remember(eventUpdates) { noteEvent.title() } val content = remember(eventUpdates) { noteEvent.summary() } val participants = remember(eventUpdates) { noteEvent.participants() } - val status = remember(eventUpdates) { noteEvent.statusEnum() } + val status = remember(eventUpdates) { noteEvent.status() } val starts = remember(eventUpdates) { noteEvent.starts() } Row( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/StreamingStatusFlags.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/StreamingStatusFlags.kt index 671d0d89fb..81d36e517e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/StreamingStatusFlags.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/StreamingStatusFlags.kt @@ -35,6 +35,7 @@ import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.SmallBorder import com.vitorpamplona.amethyst.ui.theme.liveStreamTag +import com.vitorpamplona.quartz.utils.TimeUtils import java.text.DateFormat import java.text.SimpleDateFormat import java.util.Date @@ -92,11 +93,15 @@ fun OfflineFlag() { fun ScheduledFlag(starts: Long?) { val startsIn = starts?.let { - SimpleDateFormat - .getDateTimeInstance( - DateFormat.SHORT, - DateFormat.SHORT, - ).format(Date(starts * 1000)) + if (it > TimeUtils.now()) { + SimpleDateFormat + .getDateTimeInstance( + DateFormat.SHORT, + DateFormat.SHORT, + ).format(Date(starts * 1000)) + } else { + null + } } Text( 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 a67cb2f4ba..2f711d7038 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 @@ -94,7 +94,7 @@ open class DiscoverLiveFeedFilter( return collection .sortedWith( compareBy( - { convertStatusToOrder((it.event as? LiveActivitiesEvent)?.statusEnum()) }, + { convertStatusToOrder((it.event as? LiveActivitiesEvent)?.status()) }, { participantCounts[it] }, { allParticipants[it] }, { (it.event as? LiveActivitiesEvent)?.starts() ?: it.createdAt() }, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/LiveActivityCard.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/LiveActivityCard.kt index 897cea356b..b31d46c232 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/LiveActivityCard.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip53LiveActivities/LiveActivityCard.kt @@ -105,7 +105,7 @@ fun RenderLiveActivityThumb( subject = noteEvent?.title()?.ifBlank { null }, content = noteEvent?.summary(), participants = noteEvent?.participants()?.toImmutableList() ?: persistentListOf(), - status = noteEvent?.statusEnum(), + status = noteEvent?.status(), starts = noteEvent?.starts(), ) } diff --git a/quartz/src/main/java/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt b/quartz/src/main/java/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt index 6b6c0fad80..140a1dcd22 100644 --- a/quartz/src/main/java/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt +++ b/quartz/src/main/java/com/vitorpamplona/quartz/nip53LiveActivities/streaming/LiveActivitiesEvent.kt @@ -29,14 +29,8 @@ import com.vitorpamplona.quartz.nip01Core.hints.EventHintProvider import com.vitorpamplona.quartz.nip01Core.hints.PubKeyHintProvider import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag -import com.vitorpamplona.quartz.nip01Core.tags.addressables.ATag.Companion.parseAsHint import com.vitorpamplona.quartz.nip01Core.tags.events.ETag -import com.vitorpamplona.quartz.nip01Core.tags.events.ETag.Companion.parseAsHint -import com.vitorpamplona.quartz.nip01Core.tags.people.PTag.Companion.parseAsHint -import com.vitorpamplona.quartz.nip01Core.tags.people.PTag.Companion.parseKey import com.vitorpamplona.quartz.nip18Reposts.quotes.QTag -import com.vitorpamplona.quartz.nip18Reposts.quotes.QTag.Companion.parseAddressAsHint -import com.vitorpamplona.quartz.nip18Reposts.quotes.QTag.Companion.parseEventAsHint import com.vitorpamplona.quartz.nip23LongContent.tags.ImageTag import com.vitorpamplona.quartz.nip23LongContent.tags.SummaryTag import com.vitorpamplona.quartz.nip23LongContent.tags.TitleTag @@ -88,11 +82,9 @@ class LiveActivitiesEvent( fun ends() = tags.firstNotNullOfOrNull(EndsTag::parse) - fun status() = checkStatus(tags.firstNotNullOfOrNull(StatusTag::parse)) + fun status() = checkStatus(tags.firstNotNullOfOrNull(StatusTag::parseEnum)) - fun statusEnum() = checkStatusEnum(tags.firstNotNullOfOrNull(StatusTag::parseEnum)) - - fun isLive() = statusEnum() == StatusTag.STATUS.LIVE + fun isLive() = status() == StatusTag.STATUS.LIVE fun currentParticipants() = tags.firstNotNullOfOrNull(CurrentParticipantsTag::parse) @@ -110,16 +102,19 @@ class LiveActivitiesEvent( fun hosts() = tags.mapNotNull(ParticipantTag::parseHost) - fun checkStatus(eventStatus: String?): String? = - if (eventStatus == StatusTag.STATUS.LIVE.code && createdAt < TimeUtils.eightHoursAgo()) { - StatusTag.STATUS.ENDED.code - } else { - eventStatus - } - - fun checkStatusEnum(eventStatus: StatusTag.STATUS?): StatusTag.STATUS? = + fun checkStatus(eventStatus: StatusTag.STATUS?): StatusTag.STATUS? = if (eventStatus == StatusTag.STATUS.LIVE && createdAt < TimeUtils.eightHoursAgo()) { StatusTag.STATUS.ENDED + } else if (eventStatus == StatusTag.STATUS.PLANNED) { + val starts = starts() + val ends = ends() + if (starts != null && starts < TimeUtils.oneHourAgo()) { + StatusTag.STATUS.ENDED + } else if (ends != null && ends < TimeUtils.oneHourAgo()) { + StatusTag.STATUS.ENDED + } else { + eventStatus + } } else { eventStatus }