Skip to content

Commit

Permalink
Use the correct default relays for the correct use-case. Apply stylin…
Browse files Browse the repository at this point in the history
…g fixes.
  • Loading branch information
KotlinGeekDev committed Feb 27, 2025
1 parent 7c001e2 commit 6f77f16
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe
}

suspend fun fetch(url: String, transformUrl: Boolean = true): FeedFetchResult {
return if (url.isNostrUri()) fetchNostrFeed(url)
else fetch(url, redirectCount = 0)
return if (url.isNostrUri()) fetchNostrFeed(url) else fetch(url, redirectCount = 0)
}

private suspend fun fetch(
Expand Down Expand Up @@ -226,7 +225,7 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe
val authorInfoEvent =
nostrService.getMetadataFor(
profileHex = profilePubKey,
preferredRelays = profileRelays.ifEmpty { DEFAULT_METADATA_RELAYS }
preferredRelays = profileRelays.ifEmpty { DEFAULT_FETCH_RELAYS }
)

if (authorInfoEvent.content.isBlank()) {
Expand All @@ -243,7 +242,10 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe

val userPublishRelays =
nostrService
.fetchRelayListFor(profileHex = profilePubKey, fetchRelays = DEFAULT_FETCH_RELAYS)
.fetchRelayListFor(
profileHex = profilePubKey,
fetchRelays = profileRelays.ifEmpty { DEFAULT_METADATA_RELAYS }
)
.filter { relay -> relay.writePolicy }

val userArticlesRequest =
Expand Down Expand Up @@ -325,13 +327,13 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe
)
}


// Funny hack to determine if a timestamp is in millis or seconds.
private fun toActualMillis(timeStamp: Long): Long {
fun isTimestampInMilliseconds(timestamp: Long): Boolean {
val generatedMillis = Instant.fromEpochMilliseconds(timestamp).toEpochMilliseconds()
println("Converted timestamp : $generatedMillis")
return generatedMillis.toString().length == Clock.System.now().toEpochMilliseconds().toString().length
return generatedMillis.toString().length ==
Clock.System.now().toEpochMilliseconds().toString().length
}

return if (isTimestampInMilliseconds(timeStamp)) timeStamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,17 @@ class AppPresenter(
if (showReaderView) {
navigation.pushNew(Config.Reader(post.id))
} else {
val actualLink = kotlin.run {
if (post.link.isNostrUri()) {
val nostrRef = post.link.removePrefix("nostr:")
val modifiedLink = if (nostrRef.startsWith("naddr"))
"https://highlighter.com/a/$nostrRef" else "https://njump.me/$nostrRef"

modifiedLink
} else post.link
}
val actualLink =
kotlin.run {
if (post.link.isNostrUri()) {
val nostrRef = post.link.removePrefix("nostr:")
val modifiedLink =
if (nostrRef.startsWith("naddr")) "https://highlighter.com/a/$nostrRef"
else "https://njump.me/$nostrRef"

modifiedLink
} else post.link
}
linkHandler.openLink(actualLink)
rssRepository.updatePostReadStatus(read = true, id = post.id)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ class ReaderPresenter(
private suspend fun loadRssContent() {
_state.update { it.copy(postMode = InProgress) }
val post = rssRepository.post(postId)
val postContent = if (post.link.isNostrUri()) {
transformMarkdownContent(post.rawContent!!)
} else post.rawContent ?: post.description
val postContent =
if (post.link.isNostrUri()) {
transformMarkdownContent(post.rawContent!!)
} else post.rawContent ?: post.description
_state.update { it.copy(content = postContent, postMode = RssContent) }
}

Expand All @@ -184,8 +185,7 @@ class ReaderPresenter(

if (postLink.isNostrUri()) {
loadRssContent()
}
else {
} else {
_state.update { it.copy(postMode = InProgress) }
val content = fullArticleFetcher.fetch(postLink)

Expand All @@ -200,15 +200,12 @@ class ReaderPresenter(
}
}

val markDownParser = MarkdownParser(CommonMarkFlavourDescriptor())

private fun transformMarkdownContent(originalContent: String): String {
val markDownParser = MarkdownParser(CommonMarkFlavourDescriptor())
val parsedMarkdown = markDownParser.buildMarkdownTreeFromString(originalContent)
val transformedContent = HtmlGenerator(
originalContent,
parsedMarkdown,
CommonMarkFlavourDescriptor()
)
.generateHtml()
val transformedContent =
HtmlGenerator(originalContent, parsedMarkdown, CommonMarkFlavourDescriptor()).generateHtml()

return transformedContent
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ internal fun ReaderScreen(
coroutineScope.launch {
if (state.link?.isNostrUri() == true) {
val nostrRef = state.link!!.removePrefix("nostr:")
val modifiedLink = if (nostrRef.startsWith("naddr"))
"https://highlighter.com/a/$nostrRef" else "https://njump.me/$nostrRef"
val modifiedLink =
if (nostrRef.startsWith("naddr")) "https://highlighter.com/a/$nostrRef"
else "https://njump.me/$nostrRef"
linkHandler.openLink(modifiedLink)
} else {
linkHandler.openLink(state.link)
Expand Down

0 comments on commit 6f77f16

Please sign in to comment.