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

Implement legendary profile customization on referenced articles and notes #247

Merged
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
1,801 changes: 1,801 additions & 0 deletions app/schemas/net.primal.android.db.PrimalDatabase/49.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import net.primal.android.wallet.db.WalletTransactionData
ArticleCommentCrossRef::class,
ArticleFeedCrossRef::class,
],
version = 48,
version = 49,
exportSchema = true,
)
@TypeConverters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ private fun takeAsReferencedNoteOrNull(
authorAvatarCdnImage = refPostAuthor.avatarCdnImage,
authorInternetIdentifier = refPostAuthor.internetIdentifier,
authorLightningAddress = refPostAuthor.lightningAddress,
authorLegendProfile = refPostAuthor.primalPremiumInfo?.legendProfile,
attachments = listOf(refNote).flatMapPostsAsNoteAttachmentPO(
cdnResources = cdnResources,
linkPreviews = linkPreviews,
Expand Down Expand Up @@ -385,6 +386,7 @@ private fun takeAsReferencedArticleOrNull(
authorId = refArticle.authorId,
authorName = refArticleAuthor.authorNameUiFriendly(),
authorAvatarCdnImage = refArticleAuthor.avatarCdnImage,
authorLegendProfile = refArticleAuthor.primalPremiumInfo?.legendProfile,
createdAt = refArticle.createdAt,
raw = refArticle.raw,
articleImageCdnImage = refArticle.imageCdnImage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package net.primal.android.notes.db

import java.time.Instant
import kotlinx.serialization.Serializable
import net.primal.android.articles.feed.ui.FeedArticleUi
import net.primal.android.attachments.domain.CdnImage
import net.primal.android.notes.feed.model.EventStatsUi
import net.primal.android.premium.legend.asLegendaryCustomization
import net.primal.android.profile.domain.PrimalLegendProfile

@Serializable
data class ReferencedArticle(
Expand All @@ -13,8 +18,28 @@ data class ReferencedArticle(
val authorId: String,
val authorName: String,
val authorAvatarCdnImage: CdnImage?,
val authorLegendProfile: PrimalLegendProfile?,
val createdAt: Long,
val raw: String,
val articleImageCdnImage: CdnImage? = null,
val articleReadingTimeInMinutes: Int? = null,
)

fun ReferencedArticle.asFeedArticleUi() =
FeedArticleUi(
aTag = this.aTag,
eventId = this.eventId,
articleId = this.articleId,
title = this.articleTitle,
content = "",
publishedAt = Instant.ofEpochSecond(this.createdAt),
authorId = this.authorId,
authorName = this.authorName,
rawNostrEventJson = this.raw,
isBookmarked = false,
stats = EventStatsUi(),
authorAvatarCdnImage = this.authorAvatarCdnImage,
authorLegendaryCustomization = this.authorLegendProfile?.asLegendaryCustomization(),
imageCdnImage = this.articleImageCdnImage,
readingTimeInMinutes = this.articleReadingTimeInMinutes,
)
31 changes: 31 additions & 0 deletions app/src/main/kotlin/net/primal/android/notes/db/ReferencedNote.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package net.primal.android.notes.db

import java.time.Instant
import kotlinx.serialization.Serializable
import net.primal.android.attachments.db.NoteAttachment
import net.primal.android.attachments.db.NoteNostrUri
import net.primal.android.attachments.domain.CdnImage
import net.primal.android.core.compose.attachment.model.asNoteAttachmentUi
import net.primal.android.core.utils.parseHashtags
import net.primal.android.notes.feed.model.EventStatsUi
import net.primal.android.notes.feed.model.FeedPostUi
import net.primal.android.notes.feed.model.asNoteNostrUriUi
import net.primal.android.premium.legend.asLegendaryCustomization
import net.primal.android.profile.domain.PrimalLegendProfile

@Serializable
data class ReferencedNote(
Expand All @@ -15,6 +23,29 @@ data class ReferencedNote(
val authorAvatarCdnImage: CdnImage?,
val authorInternetIdentifier: String?,
val authorLightningAddress: String?,
val authorLegendProfile: PrimalLegendProfile?,
val attachments: List<NoteAttachment>,
val nostrUris: List<NoteNostrUri>,
)

fun ReferencedNote.asFeedPostUi() =
FeedPostUi(
postId = this.postId,
repostId = null,
repostAuthorId = null,
repostAuthorName = null,
authorId = this.authorId,
authorName = this.authorName,
authorHandle = this.authorName,
authorInternetIdentifier = this.authorInternetIdentifier,
authorAvatarCdnImage = this.authorAvatarCdnImage,
authorLegendaryCustomization = this.authorLegendProfile?.asLegendaryCustomization(),
attachments = this.attachments.map { it.asNoteAttachmentUi() },
nostrUris = this.nostrUris.map { it.asNoteNostrUriUi() },
timestamp = Instant.ofEpochSecond(this.createdAt),
content = this.content,
stats = EventStatsUi(),
hashtags = this.content.parseHashtags(),
rawNostrEventJson = "",
replyToAuthorHandle = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ fun PreviewPostContentWithReferencedPost() {
authorLightningAddress = "[email protected]",
attachments = emptyList(),
nostrUris = emptyList(),
authorLegendProfile = null,
),
referencedUser = null,
referencedArticle = null,
Expand All @@ -642,6 +643,7 @@ fun PreviewPostContentWithReferencedPost() {
authorLightningAddress = "[email protected]",
attachments = emptyList(),
nostrUris = emptyList(),
authorLegendProfile = null,
),
referencedUser = null,
referencedArticle = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import java.time.Instant
import net.primal.android.articles.feed.ui.FeedArticleUi
import net.primal.android.notes.feed.model.EventStatsUi
import net.primal.android.notes.db.asFeedArticleUi
import net.primal.android.notes.feed.model.NoteNostrUriUi
import net.primal.android.notes.feed.note.ui.events.NoteCallbacks

Expand Down Expand Up @@ -39,22 +37,7 @@ fun ReferencedArticlesColumn(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
data = FeedArticleUi(
aTag = data.aTag,
eventId = data.eventId,
articleId = data.articleId,
title = data.articleTitle,
content = "",
publishedAt = Instant.ofEpochSecond(data.createdAt),
authorId = data.authorId,
authorName = data.authorName,
rawNostrEventJson = data.raw,
isBookmarked = false,
stats = EventStatsUi(),
authorAvatarCdnImage = data.authorAvatarCdnImage,
imageCdnImage = data.articleImageCdnImage,
readingTimeInMinutes = data.articleReadingTimeInMinutes,
),
data = data.asFeedArticleUi(),
colors = CardDefaults.cardColors(containerColor = containerColor),
hasBorder = hasBorder,
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import java.time.Instant
import net.primal.android.core.compose.attachment.model.asNoteAttachmentUi
import net.primal.android.core.utils.parseHashtags
import net.primal.android.notes.feed.model.EventStatsUi
import net.primal.android.notes.feed.model.FeedPostUi
import net.primal.android.notes.db.asFeedPostUi
import net.primal.android.notes.feed.model.NoteNostrUriUi
import net.primal.android.notes.feed.model.asNoteNostrUriUi
import net.primal.android.notes.feed.note.ui.events.NoteCallbacks

@Composable
Expand All @@ -40,25 +35,7 @@ fun ReferencedNotesColumn(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 4.dp),
data = FeedPostUi(
postId = data.postId,
repostId = null,
repostAuthorId = null,
repostAuthorName = null,
authorId = data.authorId,
authorName = data.authorName,
authorHandle = data.authorName,
authorInternetIdentifier = data.authorInternetIdentifier,
authorAvatarCdnImage = data.authorAvatarCdnImage,
attachments = data.attachments.map { it.asNoteAttachmentUi() },
nostrUris = data.nostrUris.map { it.asNoteNostrUriUi() },
timestamp = Instant.ofEpochSecond(data.createdAt),
content = data.content,
stats = EventStatsUi(),
hashtags = data.content.parseHashtags(),
rawNostrEventJson = "",
replyToAuthorHandle = null,
),
data = data.asFeedPostUi(),
hasBorder = hasBorder,
colors = CardDefaults.cardColors(containerColor = containerColor),
noteCallbacks = noteCallbacks,
Expand Down