2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.api
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import jp.juggler.subwaytooter.api.entity.*
|
2018-08-20 02:07:55 +02:00
|
|
|
import jp.juggler.subwaytooter.table.UserRelation
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
|
2019-02-14 04:05:07 +01:00
|
|
|
import jp.juggler.util.WordTrieTree
|
2018-01-21 17:47:13 +01:00
|
|
|
import jp.juggler.subwaytooter.util.LinkHelper
|
2020-01-07 09:03:32 +01:00
|
|
|
import jp.juggler.util.JsonArray
|
|
|
|
import jp.juggler.util.JsonObject
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
class TootParser(
|
|
|
|
val context : Context,
|
2018-01-21 17:47:13 +01:00
|
|
|
val linkHelper : LinkHelper,
|
2018-01-04 19:52:25 +01:00
|
|
|
var pinned : Boolean = false, // プロフィールカラムからpinned TL を読んだ時だけ真
|
2018-01-21 17:47:13 +01:00
|
|
|
var highlightTrie : WordTrieTree? = null,
|
2018-08-18 12:58:14 +02:00
|
|
|
var serviceType : ServiceType = ServiceType.MASTODON,
|
2020-02-16 09:13:11 +01:00
|
|
|
var misskeyDecodeProfilePin : Boolean = false,
|
2020-02-23 14:48:32 +01:00
|
|
|
var fromStream : Boolean = false,
|
|
|
|
var decodeQuote : Boolean = true
|
2018-01-04 19:52:25 +01:00
|
|
|
) {
|
2019-08-30 05:05:19 +02:00
|
|
|
|
2018-08-20 02:07:55 +02:00
|
|
|
val misskeyUserRelationMap = HashMap<EntityId, UserRelation>()
|
2018-11-06 02:29:33 +01:00
|
|
|
val misskeyAccountDetailMap = HashMap<EntityId, TootAccount>()
|
2018-08-20 02:07:55 +02:00
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
val accessHost : Host?
|
|
|
|
get() = linkHelper.host
|
2019-08-30 05:05:19 +02:00
|
|
|
|
|
|
|
init {
|
2018-08-20 02:07:55 +02:00
|
|
|
if(linkHelper.isMisskey) serviceType = ServiceType.MISSKEY
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
fun getFullAcct(acct : Acct?) = linkHelper.getFullAcct(acct)
|
2019-08-30 05:05:19 +02:00
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
fun account(src : JsonObject?) = parseItem(::TootAccount, this, src)
|
|
|
|
fun accountList(array : JsonArray?) =
|
2019-08-30 05:05:19 +02:00
|
|
|
TootAccountRef.wrapList(this, parseList(::TootAccount, this, array))
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
fun status(src : JsonObject?) = parseItem(::TootStatus, this, src)
|
|
|
|
fun statusList(array : JsonArray?) = parseList(::TootStatus, this, array)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
fun notification(src : JsonObject?) = parseItem(::TootNotification, this, src)
|
|
|
|
fun notificationList(src : JsonArray?) = parseList(::TootNotification, this, src)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
fun tagList(array : JsonArray?) = parseList(::TootTag, array)
|
|
|
|
fun results(src : JsonObject?) = parseItem(::TootResults, this, src)
|
|
|
|
fun instance(src : JsonObject?) = parseItem(::TootInstance, this, src)
|
2018-08-20 02:07:55 +02:00
|
|
|
|
2019-08-30 05:05:19 +02:00
|
|
|
fun getMisskeyUserRelation(whoId : EntityId) = misskeyUserRelationMap[whoId]
|
2018-12-08 07:26:19 +01:00
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
fun parseMisskeyApShow(jsonObject : JsonObject?) : Any? {
|
2018-12-08 07:26:19 +01:00
|
|
|
// ap/show の戻り値はActivityPubオブジェクトではなく、Misskeyのエンティティです。
|
2020-01-08 04:23:45 +01:00
|
|
|
return when(jsonObject?.string("type")) {
|
|
|
|
"Note" -> status(jsonObject.jsonObject("object"))
|
|
|
|
"User" -> account(jsonObject.jsonObject("object"))
|
2018-12-08 07:26:19 +01:00
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|