Skip to content

Commit d889988

Browse files
authored
Implement legendary profiles in referenced articles and notes (#247)
1 parent df09dcb commit d889988

File tree

8 files changed

+1866
-45
lines changed

8 files changed

+1866
-45
lines changed

app/schemas/net.primal.android.db.PrimalDatabase/49.json

Lines changed: 1801 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/kotlin/net/primal/android/db/PrimalDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ import net.primal.android.wallet.db.WalletTransactionData
9090
ArticleCommentCrossRef::class,
9191
ArticleFeedCrossRef::class,
9292
],
93-
version = 48,
93+
version = 49,
9494
exportSchema = true,
9595
)
9696
@TypeConverters(

app/src/main/kotlin/net/primal/android/nostr/ext/NostrResources.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ private fun takeAsReferencedNoteOrNull(
335335
authorAvatarCdnImage = refPostAuthor.avatarCdnImage,
336336
authorInternetIdentifier = refPostAuthor.internetIdentifier,
337337
authorLightningAddress = refPostAuthor.lightningAddress,
338+
authorLegendProfile = refPostAuthor.primalPremiumInfo?.legendProfile,
338339
attachments = listOf(refNote).flatMapPostsAsNoteAttachmentPO(
339340
cdnResources = cdnResources,
340341
linkPreviews = linkPreviews,
@@ -385,6 +386,7 @@ private fun takeAsReferencedArticleOrNull(
385386
authorId = refArticle.authorId,
386387
authorName = refArticleAuthor.authorNameUiFriendly(),
387388
authorAvatarCdnImage = refArticleAuthor.avatarCdnImage,
389+
authorLegendProfile = refArticleAuthor.primalPremiumInfo?.legendProfile,
388390
createdAt = refArticle.createdAt,
389391
raw = refArticle.raw,
390392
articleImageCdnImage = refArticle.imageCdnImage,

app/src/main/kotlin/net/primal/android/notes/db/ReferencedArticle.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package net.primal.android.notes.db
22

3+
import java.time.Instant
34
import kotlinx.serialization.Serializable
5+
import net.primal.android.articles.feed.ui.FeedArticleUi
46
import net.primal.android.attachments.domain.CdnImage
7+
import net.primal.android.notes.feed.model.EventStatsUi
8+
import net.primal.android.premium.legend.asLegendaryCustomization
9+
import net.primal.android.profile.domain.PrimalLegendProfile
510

611
@Serializable
712
data class ReferencedArticle(
@@ -13,8 +18,28 @@ data class ReferencedArticle(
1318
val authorId: String,
1419
val authorName: String,
1520
val authorAvatarCdnImage: CdnImage?,
21+
val authorLegendProfile: PrimalLegendProfile?,
1622
val createdAt: Long,
1723
val raw: String,
1824
val articleImageCdnImage: CdnImage? = null,
1925
val articleReadingTimeInMinutes: Int? = null,
2026
)
27+
28+
fun ReferencedArticle.asFeedArticleUi() =
29+
FeedArticleUi(
30+
aTag = this.aTag,
31+
eventId = this.eventId,
32+
articleId = this.articleId,
33+
title = this.articleTitle,
34+
content = "",
35+
publishedAt = Instant.ofEpochSecond(this.createdAt),
36+
authorId = this.authorId,
37+
authorName = this.authorName,
38+
rawNostrEventJson = this.raw,
39+
isBookmarked = false,
40+
stats = EventStatsUi(),
41+
authorAvatarCdnImage = this.authorAvatarCdnImage,
42+
authorLegendaryCustomization = this.authorLegendProfile?.asLegendaryCustomization(),
43+
imageCdnImage = this.articleImageCdnImage,
44+
readingTimeInMinutes = this.articleReadingTimeInMinutes,
45+
)

app/src/main/kotlin/net/primal/android/notes/db/ReferencedNote.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package net.primal.android.notes.db
22

3+
import java.time.Instant
34
import kotlinx.serialization.Serializable
45
import net.primal.android.attachments.db.NoteAttachment
56
import net.primal.android.attachments.db.NoteNostrUri
67
import net.primal.android.attachments.domain.CdnImage
8+
import net.primal.android.core.compose.attachment.model.asNoteAttachmentUi
9+
import net.primal.android.core.utils.parseHashtags
10+
import net.primal.android.notes.feed.model.EventStatsUi
11+
import net.primal.android.notes.feed.model.FeedPostUi
12+
import net.primal.android.notes.feed.model.asNoteNostrUriUi
13+
import net.primal.android.premium.legend.asLegendaryCustomization
14+
import net.primal.android.profile.domain.PrimalLegendProfile
715

816
@Serializable
917
data class ReferencedNote(
@@ -15,6 +23,29 @@ data class ReferencedNote(
1523
val authorAvatarCdnImage: CdnImage?,
1624
val authorInternetIdentifier: String?,
1725
val authorLightningAddress: String?,
26+
val authorLegendProfile: PrimalLegendProfile?,
1827
val attachments: List<NoteAttachment>,
1928
val nostrUris: List<NoteNostrUri>,
2029
)
30+
31+
fun ReferencedNote.asFeedPostUi() =
32+
FeedPostUi(
33+
postId = this.postId,
34+
repostId = null,
35+
repostAuthorId = null,
36+
repostAuthorName = null,
37+
authorId = this.authorId,
38+
authorName = this.authorName,
39+
authorHandle = this.authorName,
40+
authorInternetIdentifier = this.authorInternetIdentifier,
41+
authorAvatarCdnImage = this.authorAvatarCdnImage,
42+
authorLegendaryCustomization = this.authorLegendProfile?.asLegendaryCustomization(),
43+
attachments = this.attachments.map { it.asNoteAttachmentUi() },
44+
nostrUris = this.nostrUris.map { it.asNoteNostrUriUi() },
45+
timestamp = Instant.ofEpochSecond(this.createdAt),
46+
content = this.content,
47+
stats = EventStatsUi(),
48+
hashtags = this.content.parseHashtags(),
49+
rawNostrEventJson = "",
50+
replyToAuthorHandle = null,
51+
)

app/src/main/kotlin/net/primal/android/notes/feed/note/ui/NoteContent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ fun PreviewPostContentWithReferencedPost() {
622622
authorLightningAddress = "h@getalby.com",
623623
attachments = emptyList(),
624624
nostrUris = emptyList(),
625+
authorLegendProfile = null,
625626
),
626627
referencedUser = null,
627628
referencedArticle = null,
@@ -642,6 +643,7 @@ fun PreviewPostContentWithReferencedPost() {
642643
authorLightningAddress = "h@getalby.com",
643644
attachments = emptyList(),
644645
nostrUris = emptyList(),
646+
authorLegendProfile = null,
645647
),
646648
referencedUser = null,
647649
referencedArticle = null,

app/src/main/kotlin/net/primal/android/notes/feed/note/ui/ReferencedArticlesColumn.kt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import androidx.compose.runtime.Composable
99
import androidx.compose.ui.Modifier
1010
import androidx.compose.ui.graphics.Color
1111
import androidx.compose.ui.unit.dp
12-
import java.time.Instant
13-
import net.primal.android.articles.feed.ui.FeedArticleUi
14-
import net.primal.android.notes.feed.model.EventStatsUi
12+
import net.primal.android.notes.db.asFeedArticleUi
1513
import net.primal.android.notes.feed.model.NoteNostrUriUi
1614
import net.primal.android.notes.feed.note.ui.events.NoteCallbacks
1715

@@ -39,22 +37,7 @@ fun ReferencedArticlesColumn(
3937
modifier = Modifier
4038
.fillMaxWidth()
4139
.padding(vertical = 4.dp),
42-
data = FeedArticleUi(
43-
aTag = data.aTag,
44-
eventId = data.eventId,
45-
articleId = data.articleId,
46-
title = data.articleTitle,
47-
content = "",
48-
publishedAt = Instant.ofEpochSecond(data.createdAt),
49-
authorId = data.authorId,
50-
authorName = data.authorName,
51-
rawNostrEventJson = data.raw,
52-
isBookmarked = false,
53-
stats = EventStatsUi(),
54-
authorAvatarCdnImage = data.authorAvatarCdnImage,
55-
imageCdnImage = data.articleImageCdnImage,
56-
readingTimeInMinutes = data.articleReadingTimeInMinutes,
57-
),
40+
data = data.asFeedArticleUi(),
5841
colors = CardDefaults.cardColors(containerColor = containerColor),
5942
hasBorder = hasBorder,
6043
onClick = {

app/src/main/kotlin/net/primal/android/notes/feed/note/ui/ReferencedNotesColumn.kt

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ import androidx.compose.runtime.Composable
88
import androidx.compose.ui.Modifier
99
import androidx.compose.ui.graphics.Color
1010
import androidx.compose.ui.unit.dp
11-
import java.time.Instant
12-
import net.primal.android.core.compose.attachment.model.asNoteAttachmentUi
13-
import net.primal.android.core.utils.parseHashtags
14-
import net.primal.android.notes.feed.model.EventStatsUi
15-
import net.primal.android.notes.feed.model.FeedPostUi
11+
import net.primal.android.notes.db.asFeedPostUi
1612
import net.primal.android.notes.feed.model.NoteNostrUriUi
17-
import net.primal.android.notes.feed.model.asNoteNostrUriUi
1813
import net.primal.android.notes.feed.note.ui.events.NoteCallbacks
1914

2015
@Composable
@@ -40,25 +35,7 @@ fun ReferencedNotesColumn(
4035
modifier = Modifier
4136
.fillMaxWidth()
4237
.padding(vertical = 4.dp),
43-
data = FeedPostUi(
44-
postId = data.postId,
45-
repostId = null,
46-
repostAuthorId = null,
47-
repostAuthorName = null,
48-
authorId = data.authorId,
49-
authorName = data.authorName,
50-
authorHandle = data.authorName,
51-
authorInternetIdentifier = data.authorInternetIdentifier,
52-
authorAvatarCdnImage = data.authorAvatarCdnImage,
53-
attachments = data.attachments.map { it.asNoteAttachmentUi() },
54-
nostrUris = data.nostrUris.map { it.asNoteNostrUriUi() },
55-
timestamp = Instant.ofEpochSecond(data.createdAt),
56-
content = data.content,
57-
stats = EventStatsUi(),
58-
hashtags = data.content.parseHashtags(),
59-
rawNostrEventJson = "",
60-
replyToAuthorHandle = null,
61-
),
38+
data = data.asFeedPostUi(),
6239
hasBorder = hasBorder,
6340
colors = CardDefaults.cardColors(containerColor = containerColor),
6441
noteCallbacks = noteCallbacks,

0 commit comments

Comments
 (0)