2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.api
|
|
|
|
|
2018-01-20 07:51:14 +01:00
|
|
|
import jp.juggler.subwaytooter.api.entity.*
|
2019-04-07 15:47:05 +02:00
|
|
|
import jp.juggler.util.LogCategory
|
2019-08-30 05:05:19 +02:00
|
|
|
import java.util.*
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
class DuplicateMap {
|
|
|
|
|
2019-04-07 15:47:05 +02:00
|
|
|
companion object {
|
|
|
|
val log = LogCategory("DuplicateMap")
|
|
|
|
}
|
2018-08-26 04:09:34 +02:00
|
|
|
private val set_id = HashSet<EntityId>()
|
|
|
|
private val set_uri = HashSet<String>()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
fun clear() {
|
2018-08-26 04:09:34 +02:00
|
|
|
set_id.clear()
|
|
|
|
set_uri.clear()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 07:51:14 +01:00
|
|
|
fun isDuplicate(o : TimelineItem) : Boolean {
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
if(o is TootStatus) {
|
|
|
|
val uri = o.uri
|
|
|
|
val url = o.url
|
|
|
|
when {
|
2018-12-06 23:43:13 +01:00
|
|
|
uri.isNotEmpty() -> {
|
2018-08-26 04:09:34 +02:00
|
|
|
if(set_uri.contains(uri)) return true
|
|
|
|
set_uri.add(uri)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
url?.isNotEmpty() == true -> {
|
|
|
|
// URIとURLで同じマップを使いまわすが、害はないと思う…
|
|
|
|
if(set_uri.contains(url)) return true
|
|
|
|
set_uri.add(url)
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2018-08-26 04:09:34 +02:00
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-26 04:09:34 +02:00
|
|
|
when(o) {
|
|
|
|
is TootReport,
|
|
|
|
is TootStatus,
|
|
|
|
is TootAccount,
|
2019-08-29 18:16:21 +02:00
|
|
|
is TootAccountRef,
|
2018-08-26 04:09:34 +02:00
|
|
|
is TootNotification -> {
|
2019-04-07 15:47:05 +02:00
|
|
|
var id = o.getOrderId()
|
2018-08-26 04:09:34 +02:00
|
|
|
if(id.notDefault){
|
2019-04-07 15:47:05 +02:00
|
|
|
|
|
|
|
// Misskeyで時刻順ページングを行う際は重複排除は時刻ではなくオブジェクトIDを使う
|
2020-02-20 04:03:52 +01:00
|
|
|
if( id.fromTime && o is TootStatus) id = o.id
|
2019-04-07 15:47:05 +02:00
|
|
|
|
|
|
|
if(set_id.contains(id)) return true
|
|
|
|
set_id.add(id)
|
2018-08-26 04:09:34 +02:00
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-04-07 15:47:05 +02:00
|
|
|
|
2018-01-20 07:51:14 +01:00
|
|
|
fun filterDuplicate(src : Collection<TimelineItem>?) : ArrayList<TimelineItem> {
|
|
|
|
val list_new = ArrayList<TimelineItem>()
|
2018-08-26 04:09:34 +02:00
|
|
|
if(src != null) {
|
2018-01-20 07:51:14 +01:00
|
|
|
for(o in src) {
|
2019-04-07 15:47:05 +02:00
|
|
|
if(isDuplicate(o) ){
|
|
|
|
log.w("filterDuplicate: filter orderId ${o.getOrderId()}")
|
|
|
|
continue
|
|
|
|
}
|
2018-01-20 07:51:14 +01:00
|
|
|
list_new.add(o)
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
return list_new
|
|
|
|
}
|
|
|
|
}
|