/api/v1/instance の urls.streaming_api を読む
This commit is contained in:
parent
04ca3d017a
commit
cb30ea6af0
|
@ -1265,7 +1265,7 @@ class TestTootApiClient {
|
|||
)
|
||||
client.account = accessInfo
|
||||
val (_, ws) = client.webSocket(
|
||||
"/api/v1/streaming/?stream=public:local",
|
||||
"wss://${accessInfo.apiHost.ascii}/api/v1/streaming/?stream=public:local",
|
||||
object : WebSocketListener() {}
|
||||
)
|
||||
assertNotNull(ws)
|
||||
|
|
|
@ -489,7 +489,7 @@ class TootApiClient(
|
|||
}
|
||||
|
||||
suspend fun webSocket(
|
||||
path: String,
|
||||
urlArg: String,
|
||||
wsListener: WebSocketListener,
|
||||
): Pair<TootApiResult?, WebSocket?> {
|
||||
var ws: WebSocket? = null
|
||||
|
@ -497,10 +497,8 @@ class TootApiClient(
|
|||
if (result.error != null) return Pair(result, null)
|
||||
val account = this.account ?: return Pair(TootApiResult("account is null"), null)
|
||||
try {
|
||||
var url = "wss://${apiHost?.ascii}$path"
|
||||
|
||||
val requestBuilder = Request.Builder()
|
||||
|
||||
var url = urlArg
|
||||
if (account.isMisskey) {
|
||||
val accessToken = account.misskeyApiToken
|
||||
if (accessToken?.isNotEmpty() == true) {
|
||||
|
@ -515,7 +513,7 @@ class TootApiClient(
|
|||
}
|
||||
|
||||
val request = requestBuilder.url(url).build()
|
||||
publishApiProgress(context.getString(R.string.request_api, request.method, path))
|
||||
publishApiProgress(context.getString(R.string.request_api, request.method, urlArg))
|
||||
ws = httpClient.getWebSocket(request, wsListener)
|
||||
if (isApiCancelled()) {
|
||||
ws.cancel()
|
||||
|
|
|
@ -166,7 +166,7 @@ class TootInstance(parser: TootParser, src: JsonObject) {
|
|||
|
||||
var configuration: JsonObject? = null
|
||||
|
||||
// XXX: urls をパースしてない。使ってないから…
|
||||
var urls: JsonObject? = null
|
||||
|
||||
init {
|
||||
if (parser.serviceType == ServiceType.MISSKEY) {
|
||||
|
@ -252,6 +252,7 @@ class TootInstance(parser: TootParser, src: JsonObject) {
|
|||
?.stringList()?.toSet()
|
||||
|
||||
this.configuration = src.jsonObject("configuration")
|
||||
this.urls = src.jsonObject("urls")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -507,13 +507,24 @@ class StreamConnection(
|
|||
|
||||
status = StreamStatus.Connecting
|
||||
|
||||
val path = group?.spec?.path ?: when {
|
||||
acctGroup.account.isMisskey -> "/streaming"
|
||||
else -> "/api/v1/streaming/"
|
||||
val url = when {
|
||||
acctGroup.account.isMisskey ->
|
||||
"wss://${acctGroup.account.apiHost.ascii}${group?.spec?.misskeyPath ?: "/streaming"}"
|
||||
else -> {
|
||||
val ti = TootInstance.getCached(acctGroup.account.apiHost)
|
||||
val prefix = ti?.urls?.string("streaming_api")
|
||||
?: "wss://${acctGroup.account.apiHost}"
|
||||
val path = when (val query = group?.spec?.mastodonQuery) {
|
||||
null, "" -> "/api/v1/streaming/"
|
||||
else -> "/api/v1/streaming/?${query}"
|
||||
}
|
||||
"$prefix$path"
|
||||
}
|
||||
}
|
||||
|
||||
val (result, ws) = try {
|
||||
client.webSocket(path, this)
|
||||
log.i("webSocket $url")
|
||||
client.webSocket(url, this)
|
||||
} catch (ex: Throwable) {
|
||||
Pair(TootApiResult(ex.withCaption("can't create WebSocket.")), null)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ private fun StringWriter.appendValue(v: Any?) {
|
|||
|
||||
class StreamSpec(
|
||||
val params: JsonObject,
|
||||
val path: String,
|
||||
val misskeyPath: String? = null,
|
||||
val mastodonQuery: String? = null,
|
||||
val name: String,
|
||||
val streamFilter: Column.(JsonArray, TimelineItem) -> Boolean = { _, _ -> true },
|
||||
) {
|
||||
|
@ -44,7 +45,8 @@ class StreamSpec(
|
|||
const val PARAMS = "params"
|
||||
}
|
||||
|
||||
val keyString = "$path?${params.toString(indentFactor = 0, sort = true)}"
|
||||
val keyString =
|
||||
"${misskeyPath ?: mastodonQuery}?${params.toString(indentFactor = 0, sort = true)}"
|
||||
|
||||
val channelId = keyString.digestSHA256Base64Url()
|
||||
|
||||
|
@ -82,7 +84,7 @@ private fun Column.streamSpecMastodon(): StreamSpec? {
|
|||
|
||||
return StreamSpec(
|
||||
params = root,
|
||||
path = "/api/v1/streaming/?${root.encodeQuery()}",
|
||||
mastodonQuery = root.encodeQuery(),
|
||||
name = encodeStreamNameMastodon(root),
|
||||
streamFilter = type.streamFilterMastodon
|
||||
)
|
||||
|
@ -133,7 +135,7 @@ fun Column.streamSpecMisskey(): StreamSpec? {
|
|||
|
||||
return StreamSpec(
|
||||
params = root,
|
||||
path = path,
|
||||
misskeyPath = path,
|
||||
name = encodeStreamNameMisskey(root),
|
||||
// no stream filter
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue