🚸 Format USK links with filenames better
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / text / SoneTextParser.kt
index 690ce6d..0063148 100644 (file)
@@ -17,11 +17,12 @@ import net.pterodactylus.sone.text.LinkType.SSK
 import net.pterodactylus.sone.text.LinkType.USK
 import org.bitpedia.util.Base32
 import java.net.MalformedURLException
+import javax.inject.*
 
 /**
  * [Parser] implementation that can recognize Freenet URIs.
  */
-class SoneTextParser(private val soneProvider: SoneProvider?, private val postProvider: PostProvider?) {
+class SoneTextParser @Inject constructor(private val soneProvider: SoneProvider?, private val postProvider: PostProvider?) {
 
        fun parse(source: String, context: SoneTextParserContext?) =
                        source.split("\n")
@@ -68,7 +69,7 @@ class SoneTextParser(private val soneProvider: SoneProvider?, private val postPr
                SSK, USK ->
                        try {
                                FreenetURI(link).let { uri ->
-                                       uri.docName ?: "${uri.keyType}@${uri.routingKey.freenetBase64}"
+                                       uri.allMetaStrings?.lastOrNull() ?: uri.docName ?: "${uri.keyType}@${uri.routingKey.freenetBase64}"
                                }.let { FreenetLinkPart(link, it, trusted = context?.routingKey?.contentEquals(FreenetURI(link).routingKey) == true) }
                        } catch (e: MalformedURLException) {
                                PlainTextPart(link)