-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement saving highlights from note feeds (#248)
* Implement Highlight db entities; * Store highlights from note feeds; * Upgrade to compose-richtext:1.0.0-alpha02; * Implement custom block composer of AstParagraph nodes;
- Loading branch information
Showing
19 changed files
with
2,349 additions
and
10 deletions.
There are no files selected for viewing
1,863 changes: 1,863 additions & 0 deletions
1,863
app/schemas/net.primal.android.db.PrimalDatabase/50.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/kotlin/net/primal/android/highlights/db/HighlightDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.primal.android.highlights.db | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Upsert | ||
|
||
@Dao | ||
interface HighlightDao { | ||
@Upsert | ||
fun upsertAll(data: List<HighlightData>) | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/kotlin/net/primal/android/highlights/db/HighlightData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.primal.android.highlights.db | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity | ||
data class HighlightData( | ||
@PrimaryKey | ||
val highlightId: String, | ||
val authorId: String, | ||
val content: String, | ||
val context: String?, | ||
val alt: String?, | ||
val referencedEventId: String?, | ||
val referencedEventAuthorId: String?, | ||
val createdAt: Long, | ||
) |
26 changes: 26 additions & 0 deletions
26
app/src/main/kotlin/net/primal/android/highlights/model/HighlightUi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.primal.android.highlights.model | ||
|
||
import net.primal.android.highlights.db.HighlightData | ||
|
||
data class HighlightUi( | ||
val highlightId: String, | ||
val authorId: String, | ||
val content: String, | ||
val context: String?, | ||
val alt: String?, | ||
val highlightEventId: String?, | ||
val highlightEventAuthorId: String?, | ||
val createdAt: Long, | ||
) | ||
|
||
fun HighlightData.asHighlightUi() = | ||
HighlightUi( | ||
highlightId = highlightId, | ||
authorId = authorId, | ||
content = content, | ||
context = context, | ||
alt = alt, | ||
highlightEventId = referencedEventId, | ||
highlightEventAuthorId = referencedEventAuthorId, | ||
createdAt = createdAt, | ||
) |
23 changes: 23 additions & 0 deletions
23
app/src/main/kotlin/net/primal/android/nostr/ext/HighlightEvents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.primal.android.nostr.ext | ||
|
||
import net.primal.android.highlights.db.HighlightData | ||
import net.primal.android.nostr.model.NostrEvent | ||
import net.primal.android.nostr.model.NostrEventKind | ||
import net.primal.android.nostr.model.primal.PrimalEvent | ||
|
||
fun List<PrimalEvent>.mapReferencedEventsAsHighlightDataPO() = | ||
this.mapNotNull { it.takeContentOrNull<NostrEvent>() } | ||
.filter { it.kind == NostrEventKind.Highlight.value } | ||
.map { it.asHighlightData() } | ||
|
||
fun NostrEvent.asHighlightData() = | ||
HighlightData( | ||
highlightId = this.id, | ||
authorId = this.pubKey, | ||
content = this.content, | ||
alt = this.tags.findFirstAltDescription(), | ||
context = this.tags.findFirstContextTag(), | ||
referencedEventId = this.tags.findFirstReplaceableEventId(), | ||
referencedEventAuthorId = this.tags.findFirstProfileId()?.extractProfileId(), | ||
createdAt = this.createdAt, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...kotlin/net/primal/android/thread/articles/details/ui/rendering/CustomBlockNodeComposer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package net.primal.android.thread.articles.details.ui.rendering | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.halilibo.richtext.markdown.AstBlockNodeComposer | ||
import com.halilibo.richtext.markdown.node.AstBlockNodeType | ||
import com.halilibo.richtext.markdown.node.AstNode | ||
import com.halilibo.richtext.markdown.node.AstParagraph | ||
import com.halilibo.richtext.ui.RichTextScope | ||
import net.primal.android.highlights.model.HighlightUi | ||
import net.primal.android.thread.articles.details.ui.richtext.MarkdownRichText | ||
|
||
fun customBlockNodeComposer(@Suppress("UnusedParameter") highlights: List<HighlightUi>) = | ||
object : AstBlockNodeComposer { | ||
override fun predicate(astBlockNodeType: AstBlockNodeType): Boolean = | ||
when (astBlockNodeType) { | ||
AstParagraph -> true | ||
else -> false | ||
} | ||
|
||
@Composable | ||
override fun RichTextScope.Compose(astNode: AstNode, visitChildren: @Composable (AstNode) -> Unit) { | ||
require(astNode.type == AstParagraph) | ||
MarkdownRichText(astNode = astNode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...t/primal/android/thread/articles/details/ui/rendering/PrimalMarkdownUriHandlerProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package net.primal.android.thread.articles.details.ui.rendering | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalUriHandler | ||
import androidx.compose.ui.platform.UriHandler | ||
|
||
@Composable | ||
fun PrimalMarkdownUriHandlerProvider(linkClickHandler: (uri: String) -> Unit, content: @Composable () -> Unit) { | ||
val uriHandler = remember { | ||
object : UriHandler { | ||
override fun openUri(uri: String) = linkClickHandler(uri) | ||
} | ||
} | ||
CompositionLocalProvider(LocalUriHandler provides uriHandler, content) | ||
} |
Oops, something went wrong.