This commit is contained in:
tateisu 2020-09-21 07:00:04 +09:00
parent f4077df5ad
commit e01e14325f
10 changed files with 74 additions and 72 deletions

View File

@ -1940,7 +1940,10 @@ class ActMain : AsyncActivity(), Column.Callback, View.OnClickListener,
client.authentication2Misskey(client_name, token, ti.misskeyVersion)
this.ta = TootParser(
this@ActMain,
LinkHelper.newLinkHelper(instance, misskeyVersion = ti.misskeyVersion)
linkHelper = LinkHelper.create(
instance,
misskeyVersion = ti.misskeyVersion
)
).account(result?.jsonObject)
return result
@ -2007,7 +2010,8 @@ class ActMain : AsyncActivity(), Column.Callback, View.OnClickListener,
val client_name = Pref.spClientName(this@ActMain)
val result = client.authentication2(client_name, code)
this.ta = TootParser(
this@ActMain, LinkHelper.newLinkHelper(instance)
this@ActMain,
linkHelper = LinkHelper.create(instance)
).account(result?.jsonObject)
return result
}
@ -2182,14 +2186,18 @@ class ActMain : AsyncActivity(), Column.Callback, View.OnClickListener,
this.ti = instance
val misskeyVersion = instance.misskeyVersion
val linkHelper = LinkHelper.newLinkHelper(
val result = client.getUserCredential(access_token, misskeyVersion = misskeyVersion)
this.ta = TootParser(
this@ActMain,
LinkHelper.create(
apiHost,
apDomainArg = instance.uri?.let { Host.parse(it) },
misskeyVersion = misskeyVersion
)
val result = client.getUserCredential(access_token, misskeyVersion = misskeyVersion)
this.ta = TootParser(this@ActMain, linkHelper)
.account(result?.jsonObject)
).account(result?.jsonObject)
return result
}

View File

@ -3090,8 +3090,7 @@ class ActPost : AsyncActivity(),
val evEmoji = DecodeOptions(
this@ActPost,
decodeEmoji = true,
mentionDefaultHostDomain = unknownHostAndDomain
decodeEmoji = true
).decodeEmoji(content)
etContent.setText(evEmoji)
etContent.setSelection(evEmoji.length)
@ -3273,9 +3272,9 @@ class ActPost : AsyncActivity(),
val sv = DecodeOptions(
this@ActPost,
LinkHelper.nullHost,
mentionDefaultHostDomain = unknownHostAndDomain
linkHelper = LinkHelper.unknown,
).decodeHTML(text)
tvText.text = sv
tvText.movementMethod = LinkMovementMethod.getInstance()

View File

@ -168,9 +168,11 @@ object Action_Account {
val ti = r1?.jsonObject ?: return r1
val misskeyVersion = TootInstance.parseMisskeyVersion(ti)
val linkHelper =
LinkHelper.newLinkHelper(instance, misskeyVersion = misskeyVersion)
val parser =TootParser(activity, linkHelper)
val parser = TootParser(
activity,
linkHelper = LinkHelper.create(instance, misskeyVersion = misskeyVersion)
)
this.ti = TootInstance(parser, ti)
@ -189,7 +191,7 @@ object Action_Account {
put("url", "https://$instance/@$username")
}
this.ta = TootParser(activity, linkHelper).account(jsonObject)
this.ta = parser.account(jsonObject)
r1.data = jsonObject
r1.tokenInfo = ti
return r1
@ -245,7 +247,6 @@ object Action_Account {
ColumnType.PROFILE_DIRECTORY ->
activity.addColumn(pos, ai, type, ai.apiHost)
else -> activity.addColumn(pos, ai, type, *args)
}
}

View File

@ -123,9 +123,7 @@ class TootApiClient(
// HTMLならタグの除去を試みる
val ct = response.body?.contentType()
if(ct?.subtype == "html") {
val decoded =
DecodeOptions(mentionDefaultHostDomain = unknownHostAndDomain).decodeHTML(sv)
.toString()
val decoded = DecodeOptions().decodeHTML(sv).toString()
return reWhiteSpace.matcher(decoded).replaceAll(" ").trim()
}
@ -475,9 +473,7 @@ class TootApiClient(
// HTMLならタグを除去する
val ct = response.body?.contentType()
if(ct?.subtype == "html") {
val decoded = DecodeOptions(
mentionDefaultHostDomain = unknownHostAndDomain
).decodeHTML(bodyString).toString()
val decoded = DecodeOptions().decodeHTML(bodyString).toString()
.replace("""[\s ]+""".toRegex(), " ")
bodyString = decoded
}
@ -1524,7 +1520,7 @@ fun TootApiClient.syncStatus(
?.also { result ->
TootParser(
context,
LinkHelper.newLinkHelper(host, misskeyVersion = 10),
linkHelper = LinkHelper.create(host, misskeyVersion = 10),
serviceType = ServiceType.MISSKEY
)
.status(result.jsonObject)

View File

@ -86,7 +86,6 @@ class TootInstance(parser : TootParser, src : JsonObject) {
var feature_quote = false
// XXX: urls をパースしてない。使ってないから…
init {
@ -143,7 +142,7 @@ class TootInstance(parser : TootParser, src : JsonObject) {
val parser2 = TootParser(
parser.context,
LinkHelper.newLinkHelper(Host.parse(uri ?: "?"))
LinkHelper.create(Host.parse(uri ?: "?"))
)
contact_account =
parseItem(::TootAccount, parser2, src.jsonObject("contact_account"))
@ -160,6 +159,7 @@ class TootInstance(parser : TootParser, src : JsonObject) {
}
class Stats(src : JsonObject) {
val user_count : Long
val status_count : Long
val domain_count : Long
@ -185,12 +185,14 @@ class TootInstance(parser : TootParser, src : JsonObject) {
}
companion object {
private val rePleroma = """\bpleroma\b""".asciiPattern(Pattern.CASE_INSENSITIVE)
private val rePixelfed = """\bpixelfed\b""".asciiPattern(Pattern.CASE_INSENSITIVE)
val VERSION_1_6 = VersionString("1.6")
val VERSION_2_4_0_rc1 = VersionString("2.4.0rc1")
val VERSION_2_4_0_rc2 = VersionString("2.4.0rc2")
// val VERSION_2_4_0 = VersionString("2.4.0")
// val VERSION_2_4_1_rc1 = VersionString("2.4.1rc1")
val VERSION_2_4_1 = VersionString("2.4.1")
@ -296,7 +298,8 @@ class TootInstance(parser : TootParser, src : JsonObject) {
account : SavedAccount? = client.account?.takeIf { it.matchHost(host) },
allowPixelfed : Boolean = false,
forceUpdate : Boolean = false
) : Pair<TootInstance?, TootApiResult?> = get(client,Host.parse(host),account,allowPixelfed,forceUpdate)
) : Pair<TootInstance?, TootApiResult?> =
get(client, Host.parse(host), account, allowPixelfed, forceUpdate)
fun get(
client : TootApiClient,
@ -357,17 +360,13 @@ class TootInstance(parser : TootParser, src : JsonObject) {
item = parseItem(
::TootInstance,
if(account != null) {
TootParser(client.context, account)
} else {
TootParser(
client.context,
LinkHelper.newLinkHelper(
linkHelper = account ?: LinkHelper.create(
Host.parse(instanceName),
misskeyVersion = parseMisskeyVersion(json)
)
)
},
),
json
)

View File

@ -13,7 +13,6 @@ import jp.juggler.subwaytooter.App1
import jp.juggler.subwaytooter.R
import jp.juggler.subwaytooter.api.entity.Host
import jp.juggler.subwaytooter.api.entity.TootInstance
import jp.juggler.subwaytooter.api.entity.unknownHostAndDomain
import jp.juggler.subwaytooter.util.DecodeOptions
import jp.juggler.subwaytooter.util.LinkHelper
import jp.juggler.util.neatSpaces
@ -69,17 +68,15 @@ class DlgCreateAccount(
tvDescription.text =
DecodeOptions(
activity,
LinkHelper.newLinkHelper(
instance, misskeyVersion = instanceInfo?.misskeyVersion ?: 0
),
mentionDefaultHostDomain = unknownHostAndDomain
linkHelper = LinkHelper.create(
instance,
misskeyVersion = instanceInfo?.misskeyVersion ?: 0
)
.decodeHTML(
).decodeHTML(
instanceInfo?.short_description?.notBlank()
?: instanceInfo?.description?.notBlank()
?: TootInstance.DESCRIPTION_DEFAULT
)
.neatSpaces()
).neatSpaces()
val showReason = instanceInfo?.approval_required ?: false
tvReasonCaption.vg(showReason)

View File

@ -104,7 +104,7 @@ class SavedAccount(
} else {
TootParser(
context,
LinkHelper.newLinkHelper(
LinkHelper.create(
apiHostArg = this@SavedAccount.apiHost,
apDomainArg = this@SavedAccount.apDomain,
misskeyVersion = misskeyVersion

View File

@ -26,7 +26,7 @@ class DecodeOptions(
var mentionFullAcct : Boolean = false,
var mentions : ArrayList<TootMention>? = null,
// Account.note などmentionsがない状況でメンションリンクをfull acct化するにはアカウント等からapDomainを補う必要がある
var mentionDefaultHostDomain: HostAndDomain,
var mentionDefaultHostDomain : HostAndDomain = linkHelper ?: unknownHostAndDomain,
) {
internal fun isMediaAttachment(url : String?) : Boolean {

View File

@ -35,8 +35,12 @@ interface LinkHelper : HostAndDomain {
}
companion object{
val unknown = object : LinkHelper {
override val apiHost : Host = Host.UNKNOWN
override val apDomain : Host = Host.UNKNOWN
}
fun newLinkHelper(apiHostArg : Host, apDomainArg : Host? = null, misskeyVersion : Int = 0) =
fun create(apiHostArg : Host, apDomainArg : Host? = null, misskeyVersion : Int = 0) =
object : LinkHelper {
override val apiHost : Host = apiHostArg
@ -48,13 +52,11 @@ interface LinkHelper : HostAndDomain {
override val misskeyVersion : Int
get() = misskeyVersion
}
}
}
val nullHost = object : LinkHelper {
override val apiHost : Host = Host.parse("")
override val apDomain : Host = Host.parse("")
}
}
}
fun LinkHelper.matchHost(src : String?) = apiHost.match(src) || apDomain.match(src)
fun LinkHelper.matchHost(src : Host?) = apiHost == src || apDomain == src

View File

@ -1019,12 +1019,12 @@ class PostHelper(
} else if(! bInstanceHasCustomEmoji) {
// 古いタンスだとshortcodeを使う。見た目は絵文字に変える。
if(! EmojiDecoder.canStartShortCode(this, this.length)) append(separator)
this.append(DecodeOptions(activity,mentionDefaultHostDomain = unknownHostAndDomain).decodeEmoji(":$name:"))
this.append(DecodeOptions(activity).decodeEmoji(":$name:"))
// セパレータにZWSPを使う設定なら、補完した次の位置にもZWSPを追加する。連続して入力補完できるようになる。
if(separator != ' ') append(separator)
} else {
// 十分に新しいタンスなら絵文字のunicodeを使う。見た目は絵文字に変える。
this.append(DecodeOptions(activity,mentionDefaultHostDomain = unknownHostAndDomain).decodeEmoji(item.unified))
this.append(DecodeOptions(activity).decodeEmoji(item.unified))
}
return this