MisskeyのタグTLのストリーミングを修正。めいすきーでも/streaming を使う。
This commit is contained in:
parent
362e026a76
commit
cb505b3bde
|
@ -83,7 +83,7 @@ enum class ColumnType(
|
|||
val streamFilterMastodon: Column.(String?, TimelineItem) -> Boolean = { _, _ -> true },
|
||||
val streamNameMisskey: String? = null,
|
||||
val streamParamMisskey: Column.() -> JsonObject? = { null },
|
||||
val streamPathMisskey10: Column.() -> String? = { null },
|
||||
val streamPathMisskey9: Column.() -> String? = { null },
|
||||
) {
|
||||
|
||||
ProfileStatusMastodon(
|
||||
|
@ -418,7 +418,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(StreamSpec.STREAM to "user")
|
||||
jsonObjectOf(StreamSpec.STREAM to "user")
|
||||
},
|
||||
streamFilterMastodon = { stream, item ->
|
||||
item is TootStatus && (stream == null || stream == "user")
|
||||
|
@ -426,7 +426,7 @@ enum class ColumnType(
|
|||
|
||||
streamNameMisskey = "homeTimeline",
|
||||
streamParamMisskey = { null },
|
||||
streamPathMisskey10 = { "/" },
|
||||
streamPathMisskey9 = { "/" },
|
||||
),
|
||||
|
||||
LOCAL(
|
||||
|
@ -449,7 +449,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(StreamSpec.STREAM to
|
||||
jsonObjectOf(StreamSpec.STREAM to
|
||||
"public:local"
|
||||
.appendIf(":media", with_attachment)
|
||||
)
|
||||
|
@ -464,7 +464,7 @@ enum class ColumnType(
|
|||
},
|
||||
streamNameMisskey = "localTimeline",
|
||||
streamParamMisskey = { null },
|
||||
streamPathMisskey10 = { "/local-timeline" },
|
||||
streamPathMisskey9 = { "/local-timeline" },
|
||||
),
|
||||
|
||||
FEDERATE(
|
||||
|
@ -488,7 +488,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(StreamSpec.STREAM to
|
||||
jsonObjectOf(StreamSpec.STREAM to
|
||||
"public"
|
||||
.appendIf(":remote", remote_only)
|
||||
.appendIf(":media", with_attachment)
|
||||
|
@ -508,7 +508,7 @@ enum class ColumnType(
|
|||
|
||||
streamNameMisskey = "globalTimeline",
|
||||
streamParamMisskey = { null },
|
||||
streamPathMisskey10 = { "/global-timeline" },
|
||||
streamPathMisskey9 = { "/global-timeline" },
|
||||
),
|
||||
|
||||
MISSKEY_HYBRID(
|
||||
|
@ -533,7 +533,7 @@ enum class ColumnType(
|
|||
|
||||
streamNameMisskey = "hybridTimeline",
|
||||
streamParamMisskey = { null },
|
||||
streamPathMisskey10 = { "/hybrid-timeline" },
|
||||
streamPathMisskey9 = { "/hybrid-timeline" },
|
||||
),
|
||||
|
||||
DOMAIN_TIMELINE(
|
||||
|
@ -561,7 +561,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(StreamSpec.STREAM to
|
||||
jsonObjectOf(StreamSpec.STREAM to
|
||||
"public:domain"
|
||||
.appendIf(":media", with_attachment),
|
||||
"domain" to instance_uri
|
||||
|
@ -747,7 +747,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(StreamSpec.STREAM to "user")
|
||||
jsonObjectOf(StreamSpec.STREAM to "user")
|
||||
},
|
||||
streamFilterMastodon = { stream, item ->
|
||||
when {
|
||||
|
@ -759,7 +759,7 @@ enum class ColumnType(
|
|||
|
||||
streamNameMisskey = "main",
|
||||
streamParamMisskey = { null },
|
||||
streamPathMisskey10 = { "/" },
|
||||
streamPathMisskey9 = { "/" },
|
||||
),
|
||||
|
||||
NOTIFICATION_FROM_ACCT(
|
||||
|
@ -850,7 +850,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(
|
||||
jsonObjectOf(
|
||||
StreamSpec.STREAM to "hashtag".appendIf(":local", instance_local),
|
||||
"tag" to hashtag
|
||||
)
|
||||
|
@ -865,8 +865,9 @@ enum class ColumnType(
|
|||
else -> this.checkHashtagExtra(item)
|
||||
}
|
||||
},
|
||||
// {"type":"connect","body":{"channel":"hashtag","id":"84970575","params":{"q":[["misskey"]]}}}
|
||||
streamNameMisskey = "hashtag",
|
||||
streamParamMisskey = { jsonObject ("q" to hashtag) },
|
||||
streamParamMisskey = { jsonObjectOf ("q" to jsonArrayOf(jsonArrayOf(hashtag))) },
|
||||
// Misskey10 というかめいすきーでタグTLのストリーミングができるのか不明
|
||||
// streamPathMisskey10 = { "/???? ?q=${hashtag.encodePercent()}" },
|
||||
|
||||
|
@ -1329,7 +1330,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(StreamSpec.STREAM to "list", "list" to profile_id.toString())
|
||||
jsonObjectOf(StreamSpec.STREAM to "list", "list" to profile_id.toString())
|
||||
},
|
||||
|
||||
streamFilterMastodon = { stream, item ->
|
||||
|
@ -1340,8 +1341,8 @@ enum class ColumnType(
|
|||
}
|
||||
},
|
||||
streamNameMisskey = "userList",
|
||||
streamParamMisskey = { jsonObject("listId" to profile_id.toString()) },
|
||||
streamPathMisskey10 = { "/user-list?listId=${profile_id.toString()}" },
|
||||
streamParamMisskey = { jsonObjectOf("listId" to profile_id.toString()) },
|
||||
streamPathMisskey9 = { "/user-list?listId=${profile_id.toString()}" },
|
||||
|
||||
),
|
||||
|
||||
|
@ -1444,7 +1445,7 @@ enum class ColumnType(
|
|||
canAutoRefresh = true,
|
||||
|
||||
streamKeyMastodon = {
|
||||
jsonObject(StreamSpec.STREAM to "direct")
|
||||
jsonObjectOf(StreamSpec.STREAM to "direct")
|
||||
},
|
||||
|
||||
streamFilterMastodon = { stream, _ ->
|
||||
|
@ -1708,7 +1709,7 @@ enum class ColumnType(
|
|||
|
||||
canAutoRefresh = true,
|
||||
streamNameMisskey = "antenna",
|
||||
streamParamMisskey = { jsonObject("antennaId" to profile_id.toString()) },
|
||||
streamParamMisskey = { jsonObjectOf("antennaId" to profile_id.toString()) },
|
||||
// Misskey10 にアンテナはない
|
||||
),
|
||||
|
||||
|
|
|
@ -264,18 +264,18 @@ internal fun JsonObject.addMisskeyNotificationFilter(column: Column): JsonObject
|
|||
// QUICK_FILTER_FAVOURITE // misskeyはお気に入りの通知はない
|
||||
Column.QUICK_FILTER_BOOST -> put(
|
||||
"includeTypes",
|
||||
jsonArray("renote", "quote")
|
||||
jsonArrayOf("renote", "quote")
|
||||
)
|
||||
Column.QUICK_FILTER_FOLLOW -> put(
|
||||
"includeTypes",
|
||||
jsonArray("follow", "receiveFollowRequest")
|
||||
jsonArrayOf("follow", "receiveFollowRequest")
|
||||
)
|
||||
Column.QUICK_FILTER_MENTION -> put(
|
||||
"includeTypes",
|
||||
jsonArray("mention", "reply")
|
||||
jsonArrayOf("mention", "reply")
|
||||
)
|
||||
Column.QUICK_FILTER_REACTION -> put("includeTypes", jp.juggler.util.jsonArray("reaction"))
|
||||
Column.QUICK_FILTER_VOTE -> put("includeTypes", jp.juggler.util.jsonArray("poll_vote"))
|
||||
Column.QUICK_FILTER_REACTION -> put("includeTypes", jsonArrayOf("reaction"))
|
||||
Column.QUICK_FILTER_VOTE -> put("includeTypes", jsonArrayOf("poll_vote"))
|
||||
|
||||
Column.QUICK_FILTER_POST -> {
|
||||
// FIXME Misskeyには特定フォロー者からの投稿を通知する機能があるのか?
|
||||
|
|
|
@ -332,7 +332,7 @@ class StreamConnection(
|
|||
|
||||
jsonObject {
|
||||
put("type", "disconnect")
|
||||
put("body", jsonObject("id" to group.channelId))
|
||||
put("body", jsonObjectOf("id" to group.channelId))
|
||||
}
|
||||
}
|
||||
socket.get()?.send(jsonObject.toString())
|
||||
|
@ -359,7 +359,7 @@ class StreamConnection(
|
|||
後から body.put("id", "xxx")して
|
||||
さらに外側を {"type": "connect", "body": body} でラップする
|
||||
*/
|
||||
jsonObject(
|
||||
jsonObjectOf(
|
||||
"type" to "connect",
|
||||
"body" to group.paramsClone().also{ it["id"]= group.channelId }
|
||||
)
|
||||
|
|
|
@ -80,15 +80,15 @@ private fun Column.streamSpecMastodon(): StreamSpec? {
|
|||
val root = type.streamKeyMastodon(this) ?: return null
|
||||
|
||||
return StreamSpec(
|
||||
params= root,
|
||||
path= "/api/v1/streaming/?${root.encodeQuery()}",
|
||||
name=encodeStreamNameMastodon(root),
|
||||
streamFilter = type.streamFilterMastodon
|
||||
params = root,
|
||||
path = "/api/v1/streaming/?${root.encodeQuery()}",
|
||||
name = encodeStreamNameMastodon(root),
|
||||
streamFilter = type.streamFilterMastodon
|
||||
)
|
||||
}
|
||||
|
||||
private fun encodeStreamNameMisskey(root:JsonObject) =
|
||||
StringWriter().also{sw->
|
||||
private fun encodeStreamNameMisskey(root: JsonObject) =
|
||||
StringWriter().also { sw ->
|
||||
sw.append(root.string(CHANNEL)!!)
|
||||
val params = root.jsonObject(PARAMS)!!
|
||||
params.entries.sortedBy { it.key }.forEach { pair ->
|
||||
|
@ -106,22 +106,28 @@ private fun encodeStreamNameMisskey(root:JsonObject) =
|
|||
}.toString()
|
||||
|
||||
fun Column.streamSpecMisskey(): StreamSpec? {
|
||||
val channelName =
|
||||
if( access_info.misskeyApiToken==null && type != ColumnType.LOCAL) {
|
||||
null
|
||||
}else {
|
||||
type.streamNameMisskey
|
||||
} ?: return null
|
||||
|
||||
// 認証トークンがないなら認証トークン必須のカラムにはアクセスできない
|
||||
if (access_info.misskeyApiToken == null &&
|
||||
when (type) {
|
||||
ColumnType.HOME,
|
||||
ColumnType.MISSKEY_HYBRID,
|
||||
ColumnType.NOTIFICATIONS,
|
||||
ColumnType.LIST_TL,
|
||||
ColumnType.MISSKEY_ANTENNA_TL -> true
|
||||
else -> false
|
||||
}
|
||||
) return null
|
||||
|
||||
val channelName = type.streamNameMisskey ?: return null
|
||||
|
||||
val path = when {
|
||||
// Misskey 11以降は統合されてる
|
||||
misskeyVersion >= 11 -> "/streaming"
|
||||
|
||||
else -> type.streamPathMisskey10(this)
|
||||
misskeyVersion >= 10 -> "/streaming"
|
||||
else -> type.streamPathMisskey9(this)
|
||||
} ?: return null
|
||||
|
||||
val channelParam = type.streamParamMisskey(this) ?: JsonObject()
|
||||
val root = jsonObject(CHANNEL to channelName, PARAMS to channelParam)
|
||||
val root = jsonObjectOf(CHANNEL to channelName, PARAMS to channelParam)
|
||||
|
||||
return StreamSpec(
|
||||
params = root,
|
||||
|
|
|
@ -1094,9 +1094,9 @@ inline fun jsonObject(initializer: JsonObject.() -> Unit) =
|
|||
inline fun jsonArray(initializer: JsonArray.() -> Unit) =
|
||||
JsonArray().apply { initializer() }
|
||||
|
||||
fun jsonArray(vararg args: String) = JsonArray(args)
|
||||
fun jsonArrayOf(vararg args: Any) = JsonArray(args)
|
||||
|
||||
fun jsonObject(vararg args: Pair<String, *>) = JsonObject().apply {
|
||||
fun jsonObjectOf(vararg args: Pair<String, *>) = JsonObject().apply {
|
||||
for (pair in args) {
|
||||
put(pair.first, pair.second)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue