Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle no Profile Metadata available for highlight event #298

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.primal.android.core.compose.profile.model

import net.primal.android.attachments.domain.CdnImage
import net.primal.android.core.utils.asEllipsizedNpub
import net.primal.android.core.utils.authorNameUiFriendly
import net.primal.android.core.utils.usernameUiFriendly
import net.primal.android.premium.legend.domain.asLegendaryCustomization
Expand Down Expand Up @@ -52,3 +53,10 @@ private fun PrimalPremiumInfo.asPremiumProfileDataUi() =
expiresAt = this.expiresAt,
legendaryCustomization = this.legendProfile?.asLegendaryCustomization(),
)

fun String.asFallbackProfileDetailsUi() =
ProfileDetailsUi(
pubkey = this,
authorDisplayName = this.asEllipsizedNpub(),
userDisplayName = this.asEllipsizedNpub(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package net.primal.android.highlights.model

import java.time.Instant
import net.primal.android.attachments.domain.CdnImage
import net.primal.android.core.utils.asEllipsizedNpub
import net.primal.android.notes.db.PostWithAuthorData
import net.primal.android.premium.legend.domain.LegendaryCustomization
import net.primal.android.premium.legend.domain.asLegendaryCustomization

data class CommentUi(
val commentId: String,
val authorId: String,
val authorId: String?,
val authorDisplayName: String?,
val authorInternetIdentifier: String?,
val authorLegendaryCustomization: LegendaryCustomization?,
Expand All @@ -20,11 +21,11 @@ data class CommentUi(
fun PostWithAuthorData.toCommentUi() =
CommentUi(
commentId = this.post.postId,
authorId = this.author.ownerId,
authorDisplayName = this.author.displayName,
authorInternetIdentifier = this.author.internetIdentifier,
authorLegendaryCustomization = this.author.primalPremiumInfo?.legendProfile?.asLegendaryCustomization(),
authorCdnImage = this.author.avatarCdnImage,
authorId = this.post.authorId,
authorDisplayName = this.author?.displayName ?: this.post.authorId.asEllipsizedNpub(),
authorInternetIdentifier = this.author?.internetIdentifier,
authorLegendaryCustomization = this.author?.primalPremiumInfo?.legendProfile?.asLegendaryCustomization(),
authorCdnImage = this.author?.avatarCdnImage,
content = this.post.content,
createdAt = Instant.ofEpochSecond(this.post.createdAt),
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.primal.android.highlights.model

import net.primal.android.core.compose.profile.model.ProfileDetailsUi
import net.primal.android.core.compose.profile.model.asFallbackProfileDetailsUi
import net.primal.android.core.compose.profile.model.asProfileDetailsUi
import net.primal.android.highlights.db.Highlight
import net.primal.android.nostr.model.NostrEventKind
Expand Down Expand Up @@ -62,7 +63,7 @@ fun List<Highlight>.sum() =
fun Highlight.asJoinedHighlightsUi() =
JoinedHighlightsUi(
highlightId = this.data.highlightId,
authors = setOfNotNull(this.author?.asProfileDetailsUi()),
authors = setOf(this.author?.asProfileDetailsUi() ?: this.data.authorId.asFallbackProfileDetailsUi()),
content = this.data.content,
comments = this.comments.map { it.toCommentUi() },
referencedEventATag = this.data.referencedEventATag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class PostWithAuthorData(
val post: PostData,

@Relation(entityColumn = "ownerId", parentColumn = "authorId")
val author: ProfileData,
val author: ProfileData?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private fun List<String>.buildHighlightedString() =
buildAnnotatedString {
withStyle(style = SpanStyle(color = AppTheme.colorScheme.onPrimary)) {
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
append(this@buildHighlightedString.first())
append(this@buildHighlightedString.firstOrNull())
}
val otherSize = [email protected] - 1
if (otherSize == 0) {
Expand Down