某タンスのプロフ絵文字に対応
This commit is contained in:
parent
d4534a55b1
commit
c6fa3fa1a1
|
@ -124,6 +124,32 @@ inline fun <reified K, reified V> parseMapOrNull(
|
|||
return null
|
||||
}
|
||||
|
||||
inline fun <reified V> parseProfileEmoji2(
|
||||
factory : (src : JSONObject,shortcode:String) -> V,
|
||||
src : JSONObject?,
|
||||
log : LogCategory = EntityUtil.log
|
||||
) : HashMap<String, V>? {
|
||||
if(src != null) {
|
||||
val size = src.length()
|
||||
if(size > 0) {
|
||||
val dst = HashMap<String, V>()
|
||||
for( key in src.keys()){
|
||||
val v = src.optJSONObject(key) ?: continue
|
||||
val item = try{
|
||||
factory(v,key)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
log.e(ex, "parseProfileEmoji2 failed.")
|
||||
null
|
||||
}
|
||||
if(item != null) dst[key] = item
|
||||
}
|
||||
if(dst.isNotEmpty()) return dst
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
inline fun <reified T> parseItem(
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package jp.juggler.subwaytooter.api.entity
|
||||
|
||||
import jp.juggler.util.notEmptyOrThrow
|
||||
import jp.juggler.util.parseLong
|
||||
import jp.juggler.util.parseString
|
||||
|
||||
import org.json.JSONObject
|
||||
|
||||
class NicoProfileEmoji(
|
||||
|
@ -13,13 +11,15 @@ class NicoProfileEmoji(
|
|||
@Suppress("unused") private val account_id : EntityId
|
||||
) : Mappable<String> {
|
||||
|
||||
constructor(src : JSONObject) : this(
|
||||
constructor(src : JSONObject, shortcode : String? = null) : this(
|
||||
url = src.notEmptyOrThrow("url"),
|
||||
shortcode = src.notEmptyOrThrow("shortcode"),
|
||||
shortcode = shortcode ?: src.notEmptyOrThrow("shortcode"),
|
||||
account_url = src.parseString("account_url"),
|
||||
account_id = EntityId.mayDefault( src.parseString("account_id") )
|
||||
account_id = EntityId.mayDefault(src.parseString("account_id"))
|
||||
)
|
||||
|
||||
constructor(src : JSONObject) : this( src,null)
|
||||
|
||||
override val mapKey : String
|
||||
get() = shortcode
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ class TootStatus(parser : TootParser, src : JSONObject) : TimelineItem() {
|
|||
this.id = EntityId.mayDefault(misskeyId)
|
||||
|
||||
// ページネーションには日時を使う
|
||||
this._orderId = EntityId(time_created_at.toString(),fromTime = true)
|
||||
this._orderId = EntityId(time_created_at.toString(), fromTime = true)
|
||||
|
||||
// お気に入りカラムなどではパース直後に変更することがある
|
||||
|
||||
|
@ -331,7 +331,9 @@ class TootStatus(parser : TootParser, src : JSONObject) : TimelineItem() {
|
|||
TootPollsType.Misskey
|
||||
)
|
||||
|
||||
this.reactionCounts = parseReactionCounts(src.optJSONObject("reactions") ?: src.optJSONObject("reactionCounts") )
|
||||
this.reactionCounts = parseReactionCounts(
|
||||
src.optJSONObject("reactions") ?: src.optJSONObject("reactionCounts")
|
||||
)
|
||||
this.myReaction = src.parseString("myReaction")
|
||||
this.reblog = parser.status(src.optJSONObject("renote"))
|
||||
|
||||
|
@ -360,8 +362,12 @@ class TootStatus(parser : TootParser, src : JSONObject) : TimelineItem() {
|
|||
|
||||
// 絵文字マップはすぐ後で使うので、最初の方で読んでおく
|
||||
this.custom_emojis = parseMapOrNull(CustomEmoji.decode, src.optJSONArray("emojis"), log)
|
||||
this.profile_emojis =
|
||||
parseMapOrNull(::NicoProfileEmoji, src.optJSONArray("profile_emojis"), log)
|
||||
|
||||
this.profile_emojis = when(val o = src.opt("profile_emojis")) {
|
||||
is JSONArray -> parseMapOrNull(::NicoProfileEmoji, o, log)
|
||||
is JSONObject ->parseProfileEmoji2(::NicoProfileEmoji, o, log)
|
||||
else -> null
|
||||
}
|
||||
|
||||
val who = parser.account(src.optJSONObject("account"))
|
||||
?: throw RuntimeException("missing account")
|
||||
|
@ -916,7 +922,7 @@ class TootStatus(parser : TootParser, src : JSONObject) : TimelineItem() {
|
|||
var rv : HashMap<String, Int>? = null
|
||||
if(src != null) {
|
||||
for(key in src.keys()) {
|
||||
if( key?.isEmpty() != false ) continue
|
||||
if(key?.isEmpty() != false) continue
|
||||
val v = src.parseInt(key) ?: continue
|
||||
// カスタム絵文字などが含まれるようになったので、内容のバリデーションはできない
|
||||
if(rv == null) rv = HashMap()
|
||||
|
|
Loading…
Reference in New Issue