投稿入力欄の#ボタンでフォロー中のハッシュタグも候補に出す
This commit is contained in:
parent
63ae32c61a
commit
8b28856b88
|
@ -3,6 +3,7 @@ package jp.juggler.subwaytooter.actpost
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
import jp.juggler.subwaytooter.ActPost
|
import jp.juggler.subwaytooter.ActPost
|
||||||
import jp.juggler.subwaytooter.api.ApiTask
|
import jp.juggler.subwaytooter.api.ApiTask
|
||||||
|
import jp.juggler.subwaytooter.api.TootApiResult
|
||||||
import jp.juggler.subwaytooter.api.TootParser
|
import jp.juggler.subwaytooter.api.TootParser
|
||||||
import jp.juggler.subwaytooter.api.entity.TootTag
|
import jp.juggler.subwaytooter.api.entity.TootTag
|
||||||
import jp.juggler.subwaytooter.api.runApiTask
|
import jp.juggler.subwaytooter.api.runApiTask
|
||||||
|
@ -43,15 +44,26 @@ fun ActPost.updateFeaturedTags() {
|
||||||
FeaturedTagCache(list, SystemClock.elapsedRealtime())
|
FeaturedTagCache(list, SystemClock.elapsedRealtime())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client.request("/api/v1/featured_tags")?.also { result ->
|
val parser = TootParser(this@runApiTask, account)
|
||||||
val list = TootTag.parseList(
|
val list = buildSet {
|
||||||
TootParser(this@runApiTask, account),
|
arrayOf(
|
||||||
result.jsonArray
|
"/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[account.acct.ascii] =
|
||||||
FeaturedTagCache(list, SystemClock.elapsedRealtime())
|
FeaturedTagCache(
|
||||||
|
list.sortedBy { it.name },
|
||||||
|
SystemClock.elapsedRealtime()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
TootApiResult()
|
||||||
}
|
}
|
||||||
if (isFinishing || isDestroyed) return@launchMain
|
if (isFinishing || isDestroyed) return@launchMain
|
||||||
updateFeaturedTags()
|
updateFeaturedTags()
|
||||||
|
|
|
@ -3,8 +3,12 @@ package jp.juggler.subwaytooter.api.entity
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import jp.juggler.subwaytooter.api.TootParser
|
import jp.juggler.subwaytooter.api.TootParser
|
||||||
import jp.juggler.subwaytooter.mfm.MisskeyMarkdownDecoder
|
import jp.juggler.subwaytooter.mfm.MisskeyMarkdownDecoder
|
||||||
import jp.juggler.util.*
|
import jp.juggler.util.data.JsonArray
|
||||||
import jp.juggler.util.data.*
|
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 jp.juggler.util.log.LogCategory
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
|
@ -13,6 +17,8 @@ open class TootTag constructor(
|
||||||
// The hashtag, not including the preceding #
|
// The hashtag, not including the preceding #
|
||||||
val name: String,
|
val name: String,
|
||||||
|
|
||||||
|
val nameLower: String = name.lowercase(),
|
||||||
|
|
||||||
var type: TagType = TagType.Tag,
|
var type: TagType = TagType.Tag,
|
||||||
|
|
||||||
// (Mastodon 3.6) タグをフォロー中なら真
|
// (Mastodon 3.6) タグをフォロー中なら真
|
||||||
|
@ -28,7 +34,7 @@ open class TootTag constructor(
|
||||||
// Mastodon /api/v2/search provides history.
|
// Mastodon /api/v2/search provides history.
|
||||||
val history: ArrayList<History>? = null,
|
val history: ArrayList<History>? = null,
|
||||||
|
|
||||||
) : TimelineItem() {
|
) : TimelineItem(), Comparable<TootTag> {
|
||||||
|
|
||||||
enum class TagType {
|
enum class TagType {
|
||||||
Tag,
|
Tag,
|
||||||
|
@ -79,6 +85,7 @@ open class TootTag constructor(
|
||||||
url = "https://${parser.apiHost}/tags/${Uri.encode(name)}",
|
url = "https://${parser.apiHost}/tags/${Uri.encode(name)}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
src.string("type") == "link" -> {
|
src.string("type") == "link" -> {
|
||||||
TootTag(
|
TootTag(
|
||||||
type = TagType.Link,
|
type = TagType.Link,
|
||||||
|
@ -88,6 +95,7 @@ open class TootTag constructor(
|
||||||
history = parseHistories(src.jsonArray("history"))
|
history = parseHistories(src.jsonArray("history"))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// /api/v1/accounts/$id/featured_tags の場合、
|
// /api/v1/accounts/$id/featured_tags の場合、
|
||||||
// name部分は先頭に#がついているかもしれない。必要なら除去するべき。
|
// name部分は先頭に#がついているかもしれない。必要なら除去するべき。
|
||||||
|
@ -241,4 +249,13 @@ open class TootTag constructor(
|
||||||
return null
|
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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue