2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.api.entity
|
|
|
|
|
|
|
|
import jp.juggler.subwaytooter.api.TootParser
|
2018-12-01 00:02:18 +01:00
|
|
|
import jp.juggler.util.notEmptyOrThrow
|
|
|
|
import jp.juggler.util.parseLong
|
|
|
|
import jp.juggler.util.parseString
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-21 17:47:13 +01:00
|
|
|
import org.json.JSONObject
|
|
|
|
|
2018-08-18 12:58:14 +02:00
|
|
|
class TootNotification(parser : TootParser, src : JSONObject) : TimelineItem() {
|
|
|
|
|
|
|
|
companion object {
|
2018-08-21 12:19:02 +02:00
|
|
|
// 言及と返信
|
|
|
|
const val TYPE_MENTION = "mention" // Mastodon,Misskey
|
|
|
|
const val TYPE_REPLY = "reply" // Misskey (メンションとReplyは別の物らしい
|
|
|
|
|
|
|
|
// ブーストとリノート
|
|
|
|
const val TYPE_REBLOG = "reblog" // Mastodon
|
|
|
|
const val TYPE_RENOTE = "renote" // Misskey
|
|
|
|
const val TYPE_QUOTE = "quote" // Misskey 引用Renote
|
|
|
|
|
|
|
|
// フォロー
|
|
|
|
const val TYPE_FOLLOW = "follow" // Mastodon,Misskey
|
2018-08-25 02:29:24 +02:00
|
|
|
const val TYPE_UNFOLLOW = "unfollow" // Mastodon,Misskey
|
2018-08-21 12:19:02 +02:00
|
|
|
|
2018-08-18 12:58:14 +02:00
|
|
|
const val TYPE_FAVOURITE = "favourite"
|
2018-08-21 12:19:02 +02:00
|
|
|
const val TYPE_REACTION = "reaction"
|
|
|
|
|
|
|
|
// 投票
|
|
|
|
const val TYPE_VOTE = "poll_vote"
|
|
|
|
const val TYPE_FOLLOW_REQUEST = "receiveFollowRequest"
|
|
|
|
|
2018-08-18 12:58:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
val json : JSONObject
|
|
|
|
val id : EntityId
|
|
|
|
val type : String // One of: "mention", "reblog", "favourite", "follow"
|
|
|
|
val accountRef : TootAccountRef? // The Account sending the notification to the user
|
2018-01-10 16:47:35 +01:00
|
|
|
val status : TootStatus? // The Status associated with the notification, if applicable
|
2018-08-21 12:19:02 +02:00
|
|
|
var reaction : String? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-18 12:58:14 +02:00
|
|
|
private val created_at : String? // The time the notification was created
|
2018-01-04 19:52:25 +01:00
|
|
|
val time_created_at : Long
|
2018-08-18 12:58:14 +02:00
|
|
|
|
2018-05-08 10:25:02 +02:00
|
|
|
val account : TootAccount?
|
2018-05-18 19:08:46 +02:00
|
|
|
get() = accountRef?.get()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
private val _orderId :EntityId
|
|
|
|
override fun getOrderId() = _orderId
|
2018-08-21 12:19:02 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
init {
|
2018-08-18 12:58:14 +02:00
|
|
|
json = src
|
|
|
|
|
2018-08-21 12:19:02 +02:00
|
|
|
if( parser.serviceType == ServiceType.MISSKEY){
|
2018-08-26 04:09:34 +02:00
|
|
|
id = EntityId.mayDefault(src.parseString("id"))
|
2018-08-21 12:19:02 +02:00
|
|
|
|
|
|
|
type = src.notEmptyOrThrow("type")
|
|
|
|
|
|
|
|
created_at = src.parseString("createdAt")
|
|
|
|
time_created_at = TootStatus.parseTime(created_at)
|
|
|
|
|
|
|
|
accountRef = TootAccountRef.mayNull(parser, parser.account(src.optJSONObject("user")))
|
|
|
|
status = parser.status(src.optJSONObject("note"))
|
|
|
|
|
|
|
|
reaction = src.parseString("reaction")
|
2018-08-26 04:09:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Misskeyの通知APIはページネーションをIDでしか行えない
|
|
|
|
// これは改善される予定 https://github.com/syuilo/misskey/issues/2275
|
|
|
|
_orderId = id
|
|
|
|
|
2018-08-21 12:19:02 +02:00
|
|
|
}else{
|
2018-08-26 04:09:34 +02:00
|
|
|
id = EntityId.mayDefault(src.parseLong("id"))
|
2018-08-21 12:19:02 +02:00
|
|
|
|
|
|
|
type = src.notEmptyOrThrow("type")
|
|
|
|
created_at = src.parseString("created_at")
|
|
|
|
time_created_at = TootStatus.parseTime(created_at)
|
|
|
|
accountRef = TootAccountRef.mayNull(parser, parser.account(src.optJSONObject("account")))
|
|
|
|
status = parser.status(src.optJSONObject("status"))
|
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
_orderId = id
|
2018-08-21 12:19:02 +02:00
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2018-08-18 12:58:14 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|