Misskeyのバージョン判定を修正。v13の絵文字をとりあず表示する。

This commit is contained in:
tateisu 2023-01-11 12:28:01 +09:00
parent d63c539508
commit 38c770cd8d
3 changed files with 55 additions and 14 deletions

View File

@ -232,8 +232,7 @@ class TootInstance(parser: TootParser, src: JsonObject) {
val misskeyVersion: Int
get() = when {
instanceType != InstanceType.Misskey -> 0
versionGE(MISSKEY_VERSION_11) -> 11
else -> 10
else-> decoded_version.majorVersion ?: 10
}
val canUseReference: Boolean?

View File

@ -1,7 +1,6 @@
package jp.juggler.subwaytooter.util
import android.content.Context
import android.os.SystemClock
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.util.SparseBooleanArray
@ -18,15 +17,15 @@ import jp.juggler.subwaytooter.span.HighlightSpan
import jp.juggler.subwaytooter.span.NetworkEmojiSpan
import jp.juggler.subwaytooter.span.createSpan
import jp.juggler.subwaytooter.table.HighlightWord
import jp.juggler.util.LogCategory
import jp.juggler.util.asciiPattern
import jp.juggler.util.codePointBefore
import java.util.*
import java.util.regex.Pattern
import kotlin.math.min
object EmojiDecoder {
// private val log = LogCategory("EmojiDecoder")
private val log = LogCategory("EmojiDecoder")
private const val cpColon = ':'.code
@ -383,17 +382,50 @@ object EmojiDecoder {
}
// カスタム絵文字
val emojiCustom = emojiMapCustom?.get(name)
?: App1.custom_emoji_lister.getCachedEmoji(
options.linkHelper?.apiHost?.ascii,
name
)
fun CustomEmoji.customEmojiToUrl(): String = when {
PrefB.bpDisableEmojiAnimation() && staticUrl?.isNotEmpty() == true ->
this.staticUrl
else ->
this.url
}
if (emojiCustom != null) {
val url = when {
PrefB.bpDisableEmojiAnimation() && emojiCustom.staticUrl?.isNotEmpty() == true -> emojiCustom.staticUrl
else -> emojiCustom.url
fun findCustomEmojiUrl(): String? {
val misskeyVersion = options.linkHelper?.misskeyVersion ?: 0
if (misskeyVersion >= 13) {
val cols = name.split("@", limit = 2)
val apiHostAscii = options.linkHelper?.apiHost?.ascii
// @以降にあるホスト名か、投稿者のホスト名か、閲覧先サーバのホスト名
val userHost = cols.elementAtOrNull(1)
?: options.authorDomain?.apiHost?.ascii
?: apiHostAscii
log.i("decodeEmoji Misskey13 c0=${cols.elementAtOrNull(0)} c1=${
cols.elementAtOrNull(1)
} apiHostAscii=$apiHostAscii, userHost=$userHost")
when {
apiHostAscii == null -> {
log.w("decodeEmoji Misskey13 missing apiHostAscii")
}
userHost != null && userHost != "." && userHost != apiHostAscii -> {
// 投稿者のホスト名を使う
return "https://${apiHostAscii}/emoji/${
cols.elementAtOrNull(0)
}@${userHost}.webp"
}
else -> {
// 閲覧先サーバの絵文字を探す
App1.custom_emoji_lister.getCachedEmoji(apiHostAscii, name)
?.let { return it.customEmojiToUrl() }
}
}
}
return emojiMapCustom?.get(name)?.customEmojiToUrl()
}
val url = findCustomEmojiUrl()
if (url != null) {
builder.addNetworkEmojiSpan(part, url)
return
}

View File

@ -168,4 +168,14 @@ class VersionString(src: String?) : Comparable<VersionString> {
this.isEmpty || other.isEmpty -> false
else -> this >= other
}
val majorVersion: Int?
get(){
nodeList.forEach {
if(it is BigInteger){
return it.toString().toIntOrNull()
}
}
return null
}
}