投稿入力欄の#ボタンでフォロー中のハッシュタグも候補に出す

This commit is contained in:
tateisu 2023-04-22 15:58:46 +09:00
parent 63ae32c61a
commit 8b28856b88
2 changed files with 38 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package jp.juggler.subwaytooter.actpost
import android.os.SystemClock
import jp.juggler.subwaytooter.ActPost
import jp.juggler.subwaytooter.api.ApiTask
import jp.juggler.subwaytooter.api.TootApiResult
import jp.juggler.subwaytooter.api.TootParser
import jp.juggler.subwaytooter.api.entity.TootTag
import jp.juggler.subwaytooter.api.runApiTask
@ -43,15 +44,26 @@ fun ActPost.updateFeaturedTags() {
FeaturedTagCache(list, SystemClock.elapsedRealtime())
}
} else {
client.request("/api/v1/featured_tags")?.also { result ->
val list = TootTag.parseList(
TootParser(this@runApiTask, account),
result.jsonArray
)
val parser = TootParser(this@runApiTask, account)
val list = buildSet {
arrayOf(
"/api/v1/featured_tags",
"/api/v1/followed_tags",
).forEach { path ->
client.request(path)?.also { result ->
addAll(TootTag.parseList(parser, result.jsonArray))
}
}
}
if (list.isNotEmpty()) {
featuredTagCache[account.acct.ascii] =
FeaturedTagCache(list, SystemClock.elapsedRealtime())
FeaturedTagCache(
list.sortedBy { it.name },
SystemClock.elapsedRealtime()
)
}
}
TootApiResult()
}
if (isFinishing || isDestroyed) return@launchMain
updateFeaturedTags()

View File

@ -3,8 +3,12 @@ package jp.juggler.subwaytooter.api.entity
import android.net.Uri
import jp.juggler.subwaytooter.api.TootParser
import jp.juggler.subwaytooter.mfm.MisskeyMarkdownDecoder
import jp.juggler.util.*
import jp.juggler.util.data.*
import jp.juggler.util.data.JsonArray
import jp.juggler.util.data.JsonObject
import jp.juggler.util.data.asciiPattern
import jp.juggler.util.data.decodePercent
import jp.juggler.util.data.groupEx
import jp.juggler.util.data.notEmpty
import jp.juggler.util.log.LogCategory
import java.util.regex.Pattern
@ -13,6 +17,8 @@ open class TootTag constructor(
// The hashtag, not including the preceding #
val name: String,
val nameLower: String = name.lowercase(),
var type: TagType = TagType.Tag,
// (Mastodon 3.6) タグをフォロー中なら真
@ -28,7 +34,7 @@ open class TootTag constructor(
// Mastodon /api/v2/search provides history.
val history: ArrayList<History>? = null,
) : TimelineItem() {
) : TimelineItem(), Comparable<TootTag> {
enum class TagType {
Tag,
@ -79,6 +85,7 @@ open class TootTag constructor(
url = "https://${parser.apiHost}/tags/${Uri.encode(name)}",
)
}
src.string("type") == "link" -> {
TootTag(
type = TagType.Link,
@ -88,6 +95,7 @@ open class TootTag constructor(
history = parseHistories(src.jsonArray("history"))
)
}
else -> {
// /api/v1/accounts/$id/featured_tags の場合、
// name部分は先頭に#がついているかもしれない。必要なら除去するべき。
@ -241,4 +249,13 @@ open class TootTag constructor(
return null
}
}
override fun compareTo(other: TootTag) =
name.compareTo(other.nameLower)
override fun equals(other: Any?) =
(other is TootTag) && nameLower.equals(other.nameLower)
override fun hashCode() =
nameLower.hashCode()
}