MSP検索を開く導線を削除
This commit is contained in:
parent
e7bbae83af
commit
d034c98a09
|
@ -294,7 +294,7 @@ class ActMain : AppCompatActivity(),
|
|||
|
||||
val arActText = ActivityResultHandler(log) { r ->
|
||||
when (r.resultCode) {
|
||||
ActText.RESULT_SEARCH_MSP -> searchFromActivityResult(r.data, ColumnType.SEARCH_MSP)
|
||||
// ActText.RESULT_SEARCH_MSP -> searchFromActivityResult(r.data, ColumnType.SEARCH_MSP)
|
||||
// ActText.RESULT_SEARCH_TS -> searchFromActivityResult(r.data, ColumnType.SEARCH_TS)
|
||||
ActText.RESULT_SEARCH_NOTESTOCK -> searchFromActivityResult(
|
||||
r.data,
|
||||
|
|
|
@ -24,8 +24,7 @@ class ActText : AppCompatActivity() {
|
|||
|
||||
internal val log = LogCategory("ActText")
|
||||
|
||||
internal const val RESULT_SEARCH_MSP = RESULT_FIRST_USER + 1
|
||||
|
||||
// internal const val RESULT_SEARCH_MSP = RESULT_FIRST_USER + 1
|
||||
// internal const val RESULT_SEARCH_TS = RESULT_FIRST_USER + 2
|
||||
internal const val RESULT_SEARCH_NOTESTOCK = RESULT_FIRST_USER + 3
|
||||
|
||||
|
|
|
@ -378,9 +378,9 @@ class SideMenuAdapter(
|
|||
Item(),
|
||||
Item(title = R.string.toot_search),
|
||||
|
||||
Item(icon = R.drawable.ic_search, title = R.string.mastodon_search_portal) {
|
||||
addColumn(defaultInsertPosition, SavedAccount.na, ColumnType.SEARCH_MSP, "")
|
||||
},
|
||||
// Item(icon = R.drawable.ic_search, title = R.string.mastodon_search_portal) {
|
||||
// addColumn(defaultInsertPosition, SavedAccount.na, ColumnType.SEARCH_MSP, "")
|
||||
// },
|
||||
// Item(icon = R.drawable.ic_search, title = R.string.tootsearch) {
|
||||
// addColumn(defaultInsertPosition, SavedAccount.na, ColumnType.SEARCH_TS, "")
|
||||
// },
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package jp.juggler.subwaytooter.search
|
||||
|
||||
import jp.juggler.subwaytooter.*
|
||||
import jp.juggler.subwaytooter.column.addWithFilterStatus
|
||||
import android.content.Context
|
||||
import jp.juggler.subwaytooter.R
|
||||
import jp.juggler.subwaytooter.api.TootApiClient
|
||||
import jp.juggler.subwaytooter.api.TootApiResult
|
||||
import jp.juggler.subwaytooter.api.TootParser
|
||||
|
@ -9,10 +9,11 @@ import jp.juggler.subwaytooter.api.entity.EntityId
|
|||
import jp.juggler.subwaytooter.api.entity.ServiceType
|
||||
import jp.juggler.subwaytooter.column.ColumnTask_Loading
|
||||
import jp.juggler.subwaytooter.column.ColumnTask_Refresh
|
||||
import jp.juggler.subwaytooter.pref.PrefS
|
||||
import jp.juggler.subwaytooter.pref.put
|
||||
import jp.juggler.util.*
|
||||
import okhttp3.Request
|
||||
import jp.juggler.subwaytooter.column.addWithFilterStatus
|
||||
import jp.juggler.util.JsonArray
|
||||
import jp.juggler.util.JsonObject
|
||||
import jp.juggler.util.cast
|
||||
import jp.juggler.util.notEmpty
|
||||
|
||||
object MspHelper {
|
||||
private const val mspTokenUrl = "https://msearch.fediverse.media/api/v1.0.1/utoken"
|
||||
|
@ -24,80 +25,86 @@ object MspHelper {
|
|||
private fun getNextId(array: JsonArray, old: String?) =
|
||||
array.lastOrNull().cast<JsonObject>()?.string("msp_id")?.notEmpty() ?: old
|
||||
|
||||
private suspend fun TootApiClient.search(query: String, maxId: String?): TootApiResult? {
|
||||
@Suppress("unused", "RedundantSuspendModifier", "UNUSED_PARAMETER")
|
||||
private suspend fun TootApiClient.search(
|
||||
context: Context,
|
||||
query: String,
|
||||
maxId: String?,
|
||||
): TootApiResult? {
|
||||
return TootApiResult(context.getString(R.string.msp_discontinued))
|
||||
|
||||
// ユーザトークンを読む
|
||||
var user_token: String? = PrefS.spMspUserToken(pref)
|
||||
|
||||
for (nTry in 0 until 3) {
|
||||
if (callback.isApiCancelled()) return null
|
||||
|
||||
// ユーザトークンがなければ取得する
|
||||
if (user_token == null || user_token.isEmpty()) {
|
||||
|
||||
callback.publishApiProgress("get MSP user token...")
|
||||
|
||||
val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
||||
if (result.error != null) return result
|
||||
|
||||
if (!sendRequest(result) {
|
||||
Request.Builder()
|
||||
.url(mspTokenUrl + "?apikey=" + mspApiKey.encodePercent())
|
||||
.build()
|
||||
}) return result
|
||||
|
||||
val r2 = parseJson(result) { json ->
|
||||
val error = json.string("error")
|
||||
if (error == null) {
|
||||
null
|
||||
} else {
|
||||
val type = json.string("type")
|
||||
"error: $type $error"
|
||||
}
|
||||
}
|
||||
val jsonObject = r2?.jsonObject ?: return r2
|
||||
user_token = jsonObject.jsonObject("result")?.string("token")
|
||||
if (user_token?.isEmpty() != false) {
|
||||
return result.setError("Can't get MSP user token. response=${result.bodyString}")
|
||||
} else {
|
||||
pref.edit().put(PrefS.spMspUserToken, user_token).apply()
|
||||
}
|
||||
}
|
||||
|
||||
// ユーザトークンを使って検索APIを呼び出す
|
||||
val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
||||
if (result.error != null) return result
|
||||
|
||||
if (!sendRequest(result) {
|
||||
val url = StringBuilder()
|
||||
.append(mspSearchUrl)
|
||||
.append("?apikey=").append(mspApiKey.encodePercent())
|
||||
.append("&utoken=").append(user_token.encodePercent())
|
||||
.append("&q=").append(query.encodePercent())
|
||||
.append("&max=").append(maxId?.encodePercent() ?: "")
|
||||
|
||||
Request.Builder().url(url.toString()).build()
|
||||
}) return result
|
||||
|
||||
var isUserTokenError = false
|
||||
val r2 = parseJson(result) { json ->
|
||||
val error = json.string("error")
|
||||
if (error == null) {
|
||||
null
|
||||
} else {
|
||||
// ユーザトークンがダメなら生成しなおす
|
||||
val detail = json.string("detail")
|
||||
if ("utoken" == detail) {
|
||||
isUserTokenError = true
|
||||
}
|
||||
|
||||
val type = json.string("type")
|
||||
"API returns error: $type $error"
|
||||
}
|
||||
}
|
||||
if (r2 == null || !isUserTokenError) return r2
|
||||
}
|
||||
return TootApiResult("MSP user token retry exceeded.")
|
||||
// // ユーザトークンを読む
|
||||
// var user_token: String? = PrefS.spMspUserToken(pref)
|
||||
//
|
||||
// for (nTry in 0 until 3) {
|
||||
// if (callback.isApiCancelled()) return null
|
||||
//
|
||||
// // ユーザトークンがなければ取得する
|
||||
// if (user_token == null || user_token.isEmpty()) {
|
||||
//
|
||||
// callback.publishApiProgress("get MSP user token...")
|
||||
//
|
||||
// val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
||||
// if (result.error != null) return result
|
||||
//
|
||||
// if (!sendRequest(result) {
|
||||
// Request.Builder()
|
||||
// .url(mspTokenUrl + "?apikey=" + mspApiKey.encodePercent())
|
||||
// .build()
|
||||
// }) return result
|
||||
//
|
||||
// val r2 = parseJson(result) { json ->
|
||||
// val error = json.string("error")
|
||||
// if (error == null) {
|
||||
// null
|
||||
// } else {
|
||||
// val type = json.string("type")
|
||||
// "error: $type $error"
|
||||
// }
|
||||
// }
|
||||
// val jsonObject = r2?.jsonObject ?: return r2
|
||||
// user_token = jsonObject.jsonObject("result")?.string("token")
|
||||
// if (user_token?.isEmpty() != false) {
|
||||
// return result.setError("Can't get MSP user token. response=${result.bodyString}")
|
||||
// } else {
|
||||
// pref.edit().put(PrefS.spMspUserToken, user_token).apply()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // ユーザトークンを使って検索APIを呼び出す
|
||||
// val result: TootApiResult = TootApiResult.makeWithCaption("Mastodon Search Portal")
|
||||
// if (result.error != null) return result
|
||||
//
|
||||
// if (!sendRequest(result) {
|
||||
// val url = StringBuilder()
|
||||
// .append(mspSearchUrl)
|
||||
// .append("?apikey=").append(mspApiKey.encodePercent())
|
||||
// .append("&utoken=").append(user_token.encodePercent())
|
||||
// .append("&q=").append(query.encodePercent())
|
||||
// .append("&max=").append(maxId?.encodePercent() ?: "")
|
||||
//
|
||||
// Request.Builder().url(url.toString()).build()
|
||||
// }) return result
|
||||
//
|
||||
// var isUserTokenError = false
|
||||
// val r2 = parseJson(result) { json ->
|
||||
// val error = json.string("error")
|
||||
// if (error == null) {
|
||||
// null
|
||||
// } else {
|
||||
// // ユーザトークンがダメなら生成しなおす
|
||||
// val detail = json.string("detail")
|
||||
// if ("utoken" == detail) {
|
||||
// isUserTokenError = true
|
||||
// }
|
||||
//
|
||||
// val type = json.string("type")
|
||||
// "API returns error: $type $error"
|
||||
// }
|
||||
// }
|
||||
// if (r2 == null || !isUserTokenError) return r2
|
||||
// }
|
||||
// return TootApiResult("MSP user token retry exceeded.")
|
||||
}
|
||||
|
||||
private fun parseList(parser: TootParser, root: JsonArray) =
|
||||
|
@ -110,7 +117,11 @@ object MspHelper {
|
|||
listTmp = java.util.ArrayList()
|
||||
TootApiResult()
|
||||
} else {
|
||||
client.search(column.searchQuery, column.idOld?.toString())?.also { result ->
|
||||
client.search(
|
||||
context,
|
||||
column.searchQuery,
|
||||
column.idOld?.toString()
|
||||
)?.also { result ->
|
||||
result.jsonArray?.let { root ->
|
||||
column.idOld = EntityId.mayNull(getNextId(root, null))
|
||||
listTmp = addWithFilterStatus(null, parseList(parser, root))
|
||||
|
@ -128,7 +139,11 @@ object MspHelper {
|
|||
listTmp = ArrayList()
|
||||
TootApiResult(context.getString(R.string.end_of_list))
|
||||
} else {
|
||||
client.search(q, old)?.also { result ->
|
||||
client.search(
|
||||
context,
|
||||
q,
|
||||
old
|
||||
)?.also { result ->
|
||||
result.jsonArray?.let { root ->
|
||||
column.idOld = EntityId.mayNull(getNextId(root, column.idOld?.toString()))
|
||||
listTmp = addWithFilterStatus(listTmp, parseList(parser, root))
|
||||
|
|
|
@ -1154,4 +1154,5 @@
|
|||
<string name="unfollow_hashtag_of">\"%1$s\"のフォロー解除</string>
|
||||
<string name="conversation_with_reference">会話と参照</string>
|
||||
<string name="tootsearch_discontinued">Tootsearchは2022/12/25にサービス終了しました。</string>
|
||||
<string name="msp_discontinued">マストドン検索ポータルはサービス終了しました。</string>
|
||||
</resources>
|
||||
|
|
|
@ -1163,4 +1163,5 @@
|
|||
<string name="unfollow_hashtag_of">Unfollow %1$s</string>
|
||||
<string name="conversation_with_reference">conversation + reference</string>
|
||||
<string name="tootsearch_discontinued">Tootsearch service discontinued on 2022/12/25.</string>
|
||||
<string name="msp_discontinued">Mastodon Search Portal service was discontinued.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue