refactor
This commit is contained in:
parent
68f401c420
commit
c08a5dfd8e
|
@ -220,6 +220,7 @@ fun Column.parseRange(
|
||||||
// int scroll_hack;
|
// int scroll_hack;
|
||||||
|
|
||||||
// return true if list bottom may have unread remain
|
// return true if list bottom may have unread remain
|
||||||
|
// カラムが既に範囲を持ってる場合、その範囲を拡張する。
|
||||||
fun Column.saveRange(
|
fun Column.saveRange(
|
||||||
bBottom: Boolean,
|
bBottom: Boolean,
|
||||||
bTop: Boolean,
|
bTop: Boolean,
|
||||||
|
@ -261,10 +262,13 @@ fun Column.saveRange(
|
||||||
fun Column.saveRangeBottom(result: TootApiResult?, list: List<TimelineItem>?) =
|
fun Column.saveRangeBottom(result: TootApiResult?, list: List<TimelineItem>?) =
|
||||||
saveRange(true, bTop = false, result = result, list = list)
|
saveRange(true, bTop = false, result = result, list = list)
|
||||||
|
|
||||||
// return true if list bottom may have unread remain
|
// no return value: can't find there may be more items.
|
||||||
fun Column.saveRangeTop(result: TootApiResult?, list: List<TimelineItem>?) =
|
fun Column.saveRangeTop(result: TootApiResult?, list: List<TimelineItem>?){
|
||||||
saveRange(false, bTop = true, result = result, list = list)
|
saveRange(false, bTop = true, result = result, list = list)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun Column.addRange(
|
fun Column.addRange(
|
||||||
bBottom: Boolean,
|
bBottom: Boolean,
|
||||||
path: String,
|
path: String,
|
||||||
|
|
|
@ -8,9 +8,9 @@ import jp.juggler.util.*
|
||||||
import java.lang.StringBuilder
|
import java.lang.StringBuilder
|
||||||
|
|
||||||
class ColumnTask_Gap(
|
class ColumnTask_Gap(
|
||||||
columnArg: Column,
|
columnArg: Column,
|
||||||
private val gap: TimelineItem,
|
private val gap: TimelineItem,
|
||||||
private val isHead: Boolean
|
private val isHead: Boolean
|
||||||
) : ColumnTask(columnArg, ColumnTaskType.GAP) {
|
) : ColumnTask(columnArg, ColumnTaskType.GAP) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -30,17 +30,17 @@ class ColumnTask_Gap(
|
||||||
ctStarted.set(true)
|
ctStarted.set(true)
|
||||||
|
|
||||||
val client = TootApiClient(context, callback = object : TootApiCallback {
|
val client = TootApiClient(context, callback = object : TootApiCallback {
|
||||||
override val isApiCancelled: Boolean
|
override val isApiCancelled: Boolean
|
||||||
get() = isCancelled || column.is_dispose.get()
|
get() = isCancelled || column.is_dispose.get()
|
||||||
|
|
||||||
override suspend fun publishApiProgress(s: String) {
|
override suspend fun publishApiProgress(s: String) {
|
||||||
runOnMainLooper {
|
runOnMainLooper {
|
||||||
if (isCancelled) return@runOnMainLooper
|
if (isCancelled) return@runOnMainLooper
|
||||||
column.task_progress = s
|
column.task_progress = s
|
||||||
column.fireShowContent(reason = "gap progress", changeList = ArrayList())
|
column.fireShowContent(reason = "gap progress", changeList = ArrayList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
client.account = access_info
|
client.account = access_info
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class ColumnTask_Gap(
|
||||||
val list_new = when (column.type) {
|
val list_new = when (column.type) {
|
||||||
|
|
||||||
// 検索カラムはIDによる重複排除が不可能
|
// 検索カラムはIDによる重複排除が不可能
|
||||||
ColumnType.SEARCH -> list_tmp
|
ColumnType.SEARCH -> list_tmp
|
||||||
|
|
||||||
// 他のカラムは重複排除してから追加
|
// 他のカラムは重複排除してから追加
|
||||||
else -> column.duplicate_map.filterDuplicate(list_tmp)
|
else -> column.duplicate_map.filterDuplicate(list_tmp)
|
||||||
|
@ -127,12 +127,12 @@ class ColumnTask_Gap(
|
||||||
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, position))
|
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, position))
|
||||||
if (added > 0) {
|
if (added > 0) {
|
||||||
changeList.add(
|
changeList.add(
|
||||||
AdapterChange(
|
AdapterChange(
|
||||||
AdapterChangeType.RangeInsert,
|
AdapterChangeType.RangeInsert,
|
||||||
position,
|
position,
|
||||||
added
|
added
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
column.fireShowContent(reason = "gap updated", changeList = changeList)
|
column.fireShowContent(reason = "gap updated", changeList = changeList)
|
||||||
|
|
||||||
|
@ -162,12 +162,12 @@ class ColumnTask_Gap(
|
||||||
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, position))
|
changeList.add(AdapterChange(AdapterChangeType.RangeRemove, position))
|
||||||
if (added > 0) {
|
if (added > 0) {
|
||||||
changeList.add(
|
changeList.add(
|
||||||
AdapterChange(
|
AdapterChange(
|
||||||
AdapterChangeType.RangeInsert,
|
AdapterChangeType.RangeInsert,
|
||||||
position,
|
position,
|
||||||
added
|
added
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
column.fireShowContent(reason = "gap updated", changeList = changeList)
|
column.fireShowContent(reason = "gap updated", changeList = changeList)
|
||||||
|
|
||||||
|
@ -209,14 +209,14 @@ class ColumnTask_Gap(
|
||||||
|
|
||||||
// max_id を指定してギャップの上から読む
|
// max_id を指定してギャップの上から読む
|
||||||
private suspend fun <T : TimelineItem> readGapHeadMisskey(
|
private suspend fun <T : TimelineItem> readGapHeadMisskey(
|
||||||
logCaption: String,
|
logCaption: String,
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String,
|
path_base: String,
|
||||||
paramsCreator: (EntityId?) -> JsonObject,
|
paramsCreator: (EntityId?) -> JsonObject,
|
||||||
arrayFinder: (JsonObject) -> JsonArray? = { null },
|
arrayFinder: (JsonObject) -> JsonArray? = { null },
|
||||||
listParser: (TootParser, JsonArray) -> List<T>,
|
listParser: (TootParser, JsonArray) -> List<T>,
|
||||||
adder: (List<T>) -> Unit
|
adder: (List<T>) -> Unit
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
list_tmp = ArrayList()
|
list_tmp = ArrayList()
|
||||||
val time_start = SystemClock.elapsedRealtime()
|
val time_start = SystemClock.elapsedRealtime()
|
||||||
var result: TootApiResult? = null
|
var result: TootApiResult? = null
|
||||||
|
@ -243,12 +243,12 @@ class ColumnTask_Gap(
|
||||||
log.d("$logCaption: $path_base ${params.toString().removeIToken()}")
|
log.d("$logCaption: $path_base ${params.toString().removeIToken()}")
|
||||||
|
|
||||||
val r2 = client.request(
|
val r2 = client.request(
|
||||||
path_base,
|
path_base,
|
||||||
params.toPostRequestBuilder()
|
params.toPostRequestBuilder()
|
||||||
)
|
)
|
||||||
|
|
||||||
val jsonObject = r2?.jsonObject
|
|
||||||
if (jsonObject != null) r2.data = arrayFinder(jsonObject)
|
r2?.jsonObject?.let { r2.data = arrayFinder(it) }
|
||||||
|
|
||||||
val jsonArray = r2?.jsonArray
|
val jsonArray = r2?.jsonArray
|
||||||
if (jsonArray == null) {
|
if (jsonArray == null) {
|
||||||
|
@ -265,12 +265,11 @@ class ColumnTask_Gap(
|
||||||
// 成功した場合はそれを返したい
|
// 成功した場合はそれを返したい
|
||||||
result = r2
|
result = r2
|
||||||
|
|
||||||
var src: List<T> = listParser(parser, jsonArray)
|
var src = listParser(parser, jsonArray)
|
||||||
|
|
||||||
if (olderLimit != null)
|
if (olderLimit != null)
|
||||||
src = src.filter { it.isInjected() || it.getOrderId() > olderLimit }
|
src = src.filter { it.isInjected() || it.getOrderId() > olderLimit }
|
||||||
|
|
||||||
|
|
||||||
if (src.none { !it.isInjected() }) {
|
if (src.none { !it.isInjected() }) {
|
||||||
// 直前の取得でカラのデータが帰ってきたら終了
|
// 直前の取得でカラのデータが帰ってきたら終了
|
||||||
log.d("$logCaption: empty.")
|
log.d("$logCaption: empty.")
|
||||||
|
@ -293,14 +292,14 @@ class ColumnTask_Gap(
|
||||||
|
|
||||||
// since_idを指定してギャップの下から読む
|
// since_idを指定してギャップの下から読む
|
||||||
private suspend fun <T : TimelineItem> readGapTailMisskey(
|
private suspend fun <T : TimelineItem> readGapTailMisskey(
|
||||||
logCaption: String,
|
logCaption: String,
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String,
|
path_base: String,
|
||||||
paramsCreator: (EntityId?) -> JsonObject,
|
paramsCreator: (EntityId?) -> JsonObject,
|
||||||
arrayFinder: (JsonObject) -> JsonArray? = { null },
|
arrayFinder: (JsonObject) -> JsonArray? = { null },
|
||||||
listParser: (TootParser, JsonArray) -> List<T>,
|
listParser: (TootParser, JsonArray) -> List<T>,
|
||||||
adder: (List<T>) -> Unit
|
adder: (List<T>) -> Unit
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
list_tmp = ArrayList()
|
list_tmp = ArrayList()
|
||||||
val time_start = SystemClock.elapsedRealtime()
|
val time_start = SystemClock.elapsedRealtime()
|
||||||
var result: TootApiResult? = null
|
var result: TootApiResult? = null
|
||||||
|
@ -325,12 +324,11 @@ class ColumnTask_Gap(
|
||||||
log.d("$logCaption: $path_base ${params.toString().removeIToken()}")
|
log.d("$logCaption: $path_base ${params.toString().removeIToken()}")
|
||||||
|
|
||||||
val r2 = client.request(
|
val r2 = client.request(
|
||||||
path_base,
|
path_base,
|
||||||
params.toPostRequestBuilder()
|
params.toPostRequestBuilder()
|
||||||
)
|
)
|
||||||
|
|
||||||
val jsonObject = r2?.jsonObject
|
r2?.jsonObject?.let { r2.data = arrayFinder(it) }
|
||||||
if (jsonObject != null) r2.data = arrayFinder(jsonObject)
|
|
||||||
|
|
||||||
val jsonArray = r2?.jsonArray
|
val jsonArray = r2?.jsonArray
|
||||||
if (jsonArray == null) {
|
if (jsonArray == null) {
|
||||||
|
@ -347,7 +345,7 @@ class ColumnTask_Gap(
|
||||||
// 成功した場合はそれを返したい
|
// 成功した場合はそれを返したい
|
||||||
result = r2
|
result = r2
|
||||||
|
|
||||||
var src: List<T> = listParser(parser, jsonArray)
|
var src = listParser(parser, jsonArray)
|
||||||
|
|
||||||
if (newerLimit != null)
|
if (newerLimit != null)
|
||||||
src = src.filter { it.isInjected() || it.getOrderId() < newerLimit }
|
src = src.filter { it.isInjected() || it.getOrderId() < newerLimit }
|
||||||
|
@ -374,13 +372,13 @@ class ColumnTask_Gap(
|
||||||
|
|
||||||
// max_id を指定してギャップの上から読む
|
// max_id を指定してギャップの上から読む
|
||||||
private suspend fun <T : TimelineItem> readGapHeadMastodon(
|
private suspend fun <T : TimelineItem> readGapHeadMastodon(
|
||||||
logCaption: String,
|
logCaption: String,
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String,
|
path_base: String,
|
||||||
filterByIdRange: Boolean,
|
filterByIdRange: Boolean,
|
||||||
listParser: (TootParser, JsonArray) -> List<T>,
|
listParser: (TootParser, JsonArray) -> List<T>,
|
||||||
adder: (List<T>) -> Unit,
|
adder: (List<T>) -> Unit,
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
list_tmp = ArrayList()
|
list_tmp = ArrayList()
|
||||||
val delimiter = if (-1 != path_base.indexOf('?')) '&' else '?'
|
val delimiter = if (-1 != path_base.indexOf('?')) '&' else '?'
|
||||||
val requester: suspend (EntityId?) -> TootApiResult? = {
|
val requester: suspend (EntityId?) -> TootApiResult? = {
|
||||||
|
@ -440,7 +438,7 @@ class ColumnTask_Gap(
|
||||||
// 成功した場合はそれを返したい
|
// 成功した場合はそれを返したい
|
||||||
result = r2
|
result = r2
|
||||||
|
|
||||||
var src: List<T> = listParser(parser, jsonArray)
|
var src = listParser(parser, jsonArray)
|
||||||
|
|
||||||
if (olderLimit != null)
|
if (olderLimit != null)
|
||||||
src = src.filter { it.getOrderId() > olderLimit }
|
src = src.filter { it.getOrderId() > olderLimit }
|
||||||
|
@ -467,13 +465,13 @@ class ColumnTask_Gap(
|
||||||
|
|
||||||
// since_idを指定してギャップの下から読む
|
// since_idを指定してギャップの下から読む
|
||||||
private suspend fun <T : TimelineItem> readGapTailMastodon(
|
private suspend fun <T : TimelineItem> readGapTailMastodon(
|
||||||
logCaption: String,
|
logCaption: String,
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String,
|
path_base: String,
|
||||||
filterByIdRange: Boolean,
|
filterByIdRange: Boolean,
|
||||||
listParser: (TootParser, JsonArray) -> List<T>,
|
listParser: (TootParser, JsonArray) -> List<T>,
|
||||||
adder: (List<T>) -> Unit
|
adder: (List<T>) -> Unit
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
list_tmp = ArrayList()
|
list_tmp = ArrayList()
|
||||||
val delimiter = if (-1 != path_base.indexOf('?')) '&' else '?'
|
val delimiter = if (-1 != path_base.indexOf('?')) '&' else '?'
|
||||||
val requester: suspend (EntityId?) -> TootApiResult? = {
|
val requester: suspend (EntityId?) -> TootApiResult? = {
|
||||||
|
@ -526,7 +524,7 @@ class ColumnTask_Gap(
|
||||||
// 成功した場合はそれを返したい
|
// 成功した場合はそれを返したい
|
||||||
result = r2
|
result = r2
|
||||||
|
|
||||||
var src: List<T> = listParser(parser, jsonArray)
|
var src = listParser(parser, jsonArray)
|
||||||
|
|
||||||
if (newerLimit != null)
|
if (newerLimit != null)
|
||||||
src = src.filter { it.getOrderId() < newerLimit }
|
src = src.filter { it.getOrderId() < newerLimit }
|
||||||
|
@ -554,15 +552,15 @@ class ColumnTask_Gap(
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
suspend fun getAccountList(
|
suspend fun getAccountList(
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String,
|
path_base: String,
|
||||||
mastodonFilterByIdRange: Boolean,
|
mastodonFilterByIdRange: Boolean,
|
||||||
misskeyParams: JsonObject? = null,
|
misskeyParams: JsonObject? = null,
|
||||||
arrayFinder: (jsonObject: JsonObject) -> JsonArray? =
|
arrayFinder: (jsonObject: JsonObject) -> JsonArray? =
|
||||||
nullArrayFinder,
|
nullArrayFinder,
|
||||||
listParser: (parser: TootParser, jsonArray: JsonArray) -> List<TootAccountRef> =
|
listParser: (parser: TootParser, jsonArray: JsonArray) -> List<TootAccountRef> =
|
||||||
defaultAccountListParser
|
defaultAccountListParser
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
|
|
||||||
if (column.pagingType != ColumnPagingType.Default) {
|
if (column.pagingType != ColumnPagingType.Default) {
|
||||||
return TootApiResult("can't support gap")
|
return TootApiResult("can't support gap")
|
||||||
|
@ -576,56 +574,56 @@ class ColumnTask_Gap(
|
||||||
val params = misskeyParams ?: column.makeMisskeyBaseParameter(parser)
|
val params = misskeyParams ?: column.makeMisskeyBaseParameter(parser)
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMisskey(
|
readGapHeadMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeyUntil(it) },
|
paramsCreator = { params.putMisskeyUntil(it) },
|
||||||
arrayFinder = arrayFinder,
|
arrayFinder = arrayFinder,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder,
|
adder = adder,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMisskey(
|
readGapTailMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeySince(it) },
|
paramsCreator = { params.putMisskeySince(it) },
|
||||||
arrayFinder = arrayFinder,
|
arrayFinder = arrayFinder,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val logCaption = "getAccountList.Mastodon"
|
val logCaption = "getAccountList.Mastodon"
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMastodon(
|
readGapHeadMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMastodon(
|
readGapTailMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getReportList(
|
suspend fun getReportList(
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String,
|
path_base: String,
|
||||||
mastodonFilterByIdRange: Boolean,
|
mastodonFilterByIdRange: Boolean,
|
||||||
listParser: (parser: TootParser, jsonArray: JsonArray) -> List<TootReport> =
|
listParser: (parser: TootParser, jsonArray: JsonArray) -> List<TootReport> =
|
||||||
defaultReportListParser
|
defaultReportListParser
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
|
|
||||||
val adder: (List<TootReport>) -> Unit =
|
val adder: (List<TootReport>) -> Unit =
|
||||||
{ addAll(list_tmp, it, head = !isHead) }
|
{ addAll(list_tmp, it, head = !isHead) }
|
||||||
|
@ -635,52 +633,52 @@ class ColumnTask_Gap(
|
||||||
val params = column.makeMisskeyBaseParameter(parser)
|
val params = column.makeMisskeyBaseParameter(parser)
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMisskey(
|
readGapHeadMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeyUntil(it) },
|
paramsCreator = { params.putMisskeyUntil(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMisskey(
|
readGapTailMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeySince(it) },
|
paramsCreator = { params.putMisskeySince(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val logCaption = "getReportList.Mastodon"
|
val logCaption = "getReportList.Mastodon"
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMastodon(
|
readGapHeadMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMastodon(
|
readGapTailMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getNotificationList(
|
suspend fun getNotificationList(
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
fromAcct: String? = null,
|
fromAcct: String? = null,
|
||||||
mastodonFilterByIdRange: Boolean,
|
mastodonFilterByIdRange: Boolean,
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
|
|
||||||
val path_base: String = column.makeNotificationUrl(client, fromAcct)
|
val path_base: String = column.makeNotificationUrl(client, fromAcct)
|
||||||
|
|
||||||
|
@ -696,44 +694,44 @@ class ColumnTask_Gap(
|
||||||
.addMisskeyNotificationFilter(column)
|
.addMisskeyNotificationFilter(column)
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMisskey(
|
readGapHeadMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeyUntil(it) },
|
paramsCreator = { params.putMisskeyUntil(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMisskey(
|
readGapTailMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeySince(it) },
|
paramsCreator = { params.putMisskeySince(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val logCaption = "getNotificationList.Mastodon"
|
val logCaption = "getNotificationList.Mastodon"
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMastodon(
|
readGapHeadMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMastodon(
|
readGapTailMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}.also {
|
}.also {
|
||||||
|
@ -744,13 +742,13 @@ class ColumnTask_Gap(
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getStatusList(
|
suspend fun getStatusList(
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String?,
|
path_base: String?,
|
||||||
mastodonFilterByIdRange: Boolean,
|
mastodonFilterByIdRange: Boolean,
|
||||||
misskeyParams: JsonObject? = null,
|
misskeyParams: JsonObject? = null,
|
||||||
listParser: (parser: TootParser, jsonArray: JsonArray) -> List<TootStatus> =
|
listParser: (parser: TootParser, jsonArray: JsonArray) -> List<TootStatus> =
|
||||||
defaultStatusListParser
|
defaultStatusListParser
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
|
|
||||||
path_base ?: return null // cancelled.
|
path_base ?: return null // cancelled.
|
||||||
|
|
||||||
|
@ -763,55 +761,55 @@ class ColumnTask_Gap(
|
||||||
|
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMisskey(
|
readGapHeadMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeyUntil(it) },
|
paramsCreator = { params.putMisskeyUntil(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMisskey(
|
readGapTailMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeySince(it) },
|
paramsCreator = { params.putMisskeySince(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val logCaption = "getStatusList.Mastodon"
|
val logCaption = "getStatusList.Mastodon"
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMastodon(
|
readGapHeadMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMastodon(
|
readGapTailMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getConversationSummaryList(
|
suspend fun getConversationSummaryList(
|
||||||
client: TootApiClient,
|
client: TootApiClient,
|
||||||
path_base: String,
|
path_base: String,
|
||||||
mastodonFilterByIdRange: Boolean,
|
mastodonFilterByIdRange: Boolean,
|
||||||
misskeyParams: JsonObject? = null,
|
misskeyParams: JsonObject? = null,
|
||||||
listParser: (TootParser, JsonArray) -> List<TootConversationSummary> =
|
listParser: (TootParser, JsonArray) -> List<TootConversationSummary> =
|
||||||
defaultConversationSummaryListParser
|
defaultConversationSummaryListParser
|
||||||
): TootApiResult? {
|
): TootApiResult? {
|
||||||
|
|
||||||
val adder: (List<TootConversationSummary>) -> Unit =
|
val adder: (List<TootConversationSummary>) -> Unit =
|
||||||
{ addWithFilterConversationSummary(list_tmp, it, head = !isHead) }
|
{ addWithFilterConversationSummary(list_tmp, it, head = !isHead) }
|
||||||
|
@ -821,43 +819,43 @@ class ColumnTask_Gap(
|
||||||
val params = misskeyParams ?: column.makeMisskeyTimelineParameter(parser)
|
val params = misskeyParams ?: column.makeMisskeyTimelineParameter(parser)
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMisskey(
|
readGapHeadMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeyUntil(it) },
|
paramsCreator = { params.putMisskeyUntil(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMisskey(
|
readGapTailMisskey(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
paramsCreator = { params.putMisskeySince(it) },
|
paramsCreator = { params.putMisskeySince(it) },
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val logCaption = "getConversationSummaryList.Mastodon"
|
val logCaption = "getConversationSummaryList.Mastodon"
|
||||||
if (isHead) {
|
if (isHead) {
|
||||||
readGapHeadMastodon(
|
readGapHeadMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
readGapTailMastodon(
|
readGapTailMastodon(
|
||||||
logCaption,
|
logCaption,
|
||||||
client,
|
client,
|
||||||
path_base,
|
path_base,
|
||||||
filterByIdRange = mastodonFilterByIdRange,
|
filterByIdRange = mastodonFilterByIdRange,
|
||||||
listParser = listParser,
|
listParser = listParser,
|
||||||
adder = adder
|
adder = adder
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -871,26 +869,26 @@ class ColumnTask_Gap(
|
||||||
if (it is TootStatus && (minId == null || it.id < minId)) it.id else minId
|
if (it is TootStatus && (minId == null || it.id < minId)) it.id else minId
|
||||||
}
|
}
|
||||||
|
|
||||||
val (_, counter) = when (gap.type) {
|
val (_, counter) = when (gap.type) {
|
||||||
TootSearchGap.SearchType.Status -> Pair("statuses", countStatuses)
|
TootSearchGap.SearchType.Status -> Pair("statuses", countStatuses)
|
||||||
|
|
||||||
//TootSearchGap.SearchType.Hashtag -> Pair("hashtags", countTag)
|
//TootSearchGap.SearchType.Hashtag -> Pair("hashtags", countTag)
|
||||||
//TootSearchGap.SearchType.Account -> Pair("accounts", countAccount)
|
//TootSearchGap.SearchType.Account -> Pair("accounts", countAccount)
|
||||||
else -> return TootApiResult("paging for ${gap.type} is not yet supported")
|
else -> return TootApiResult("paging for ${gap.type} is not yet supported")
|
||||||
}
|
}
|
||||||
var minId: EntityId? = null
|
var minId: EntityId? = null
|
||||||
for (it in column.list_data) minId = counter(it, minId)
|
for (it in column.list_data) minId = counter(it, minId)
|
||||||
|
|
||||||
minId ?: return TootApiResult("can't detect paging parameter.")
|
minId ?: return TootApiResult("can't detect paging parameter.")
|
||||||
|
|
||||||
val result = client.request(
|
val result = client.request(
|
||||||
"/api/notes/search",
|
"/api/notes/search",
|
||||||
access_info.putMisskeyApiToken().apply {
|
access_info.putMisskeyApiToken().apply {
|
||||||
put("query", column.search_query)
|
put("query", column.search_query)
|
||||||
put("untilId", minId.toString())
|
put("untilId", minId.toString())
|
||||||
}
|
}
|
||||||
.toPostRequestBuilder()
|
.toPostRequestBuilder()
|
||||||
)
|
)
|
||||||
|
|
||||||
val jsonArray = result?.jsonArray
|
val jsonArray = result?.jsonArray
|
||||||
if (jsonArray != null) {
|
if (jsonArray != null) {
|
||||||
|
@ -912,18 +910,18 @@ class ColumnTask_Gap(
|
||||||
val countStatuses: (TimelineItem) -> Unit =
|
val countStatuses: (TimelineItem) -> Unit =
|
||||||
{ if (it is TootStatus) ++offset }
|
{ if (it is TootStatus) ++offset }
|
||||||
|
|
||||||
val (type, counter) = when (gap.type) {
|
val (type, counter) = when (gap.type) {
|
||||||
TootSearchGap.SearchType.Account -> Pair("accounts", countAccounts)
|
TootSearchGap.SearchType.Account -> Pair("accounts", countAccounts)
|
||||||
TootSearchGap.SearchType.Hashtag -> Pair("hashtags", countTags)
|
TootSearchGap.SearchType.Hashtag -> Pair("hashtags", countTags)
|
||||||
TootSearchGap.SearchType.Status -> Pair("statuses", countStatuses)
|
TootSearchGap.SearchType.Status -> Pair("statuses", countStatuses)
|
||||||
}
|
}
|
||||||
column.list_data.forEach { counter(it) }
|
column.list_data.forEach { counter(it) }
|
||||||
|
|
||||||
// https://mastodon2.juggler.jp/api/v2/search?q=gargron&type=accounts&offset=5
|
// https://mastodon2.juggler.jp/api/v2/search?q=gargron&type=accounts&offset=5
|
||||||
var query = "q=${column.search_query.encodePercent()}&type=$type&offset=$offset"
|
var query = "q=${column.search_query.encodePercent()}&type=$type&offset=$offset"
|
||||||
if (column.search_resolve) query += "&resolve=1"
|
if (column.search_resolve) query += "&resolve=1"
|
||||||
|
|
||||||
val (apiResult, searchResult) = client.requestMastodonSearch(parser, query)
|
val (apiResult, searchResult) = client.requestMastodonSearch(parser, query)
|
||||||
if (searchResult != null) {
|
if (searchResult != null) {
|
||||||
list_tmp = ArrayList()
|
list_tmp = ArrayList()
|
||||||
addAll(list_tmp, searchResult.hashtags)
|
addAll(list_tmp, searchResult.hashtags)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -2,96 +2,71 @@ package jp.juggler.util
|
||||||
|
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
|
||||||
class LogCategory(category : String) {
|
fun Throwable.withCaption(caption: String) =
|
||||||
|
"${caption} :${javaClass.simpleName} ${message}"
|
||||||
companion object {
|
|
||||||
private const val TAG = "SubwayTooter"
|
class LogCategory(category: String) {
|
||||||
|
|
||||||
private fun format(fmt : String, args : Array<out Any?>) =
|
companion object {
|
||||||
if(args.isEmpty()) fmt else String.format(fmt, *args)
|
private const val TAG = "SubwayTooter"
|
||||||
|
}
|
||||||
private fun format(res : Resources, string_id : Int, args : Array<out Any?>) =
|
|
||||||
res.getString(string_id, *args)
|
private val tag = "$TAG:$category"
|
||||||
|
|
||||||
private fun Throwable.withCaption(caption : String) =
|
///////////////////////////////
|
||||||
"${caption} :${javaClass.simpleName} ${message}"
|
// string
|
||||||
}
|
|
||||||
|
fun msg(priority: Int, msg: String): Boolean {
|
||||||
private val tag = "$TAG:$category"
|
Log.println(priority, tag, msg)
|
||||||
|
return false
|
||||||
fun e(fmt : String, vararg args : Any?) {
|
}
|
||||||
Log.e(tag, format(fmt, args))
|
|
||||||
}
|
fun e(msg: String) = msg(Log.ERROR, msg)
|
||||||
|
fun w(msg: String) = msg(Log.WARN, msg)
|
||||||
fun w(fmt : String, vararg args : Any?) {
|
fun i(msg: String) = msg(Log.INFO, msg)
|
||||||
Log.w(tag, format(fmt, args))
|
fun d(msg: String) = msg(Log.DEBUG, msg)
|
||||||
}
|
fun v(msg: String) = msg(Log.VERBOSE, msg)
|
||||||
|
|
||||||
fun i(fmt : String, vararg args : Any?) {
|
///////////////////////////////
|
||||||
Log.i(tag, format(fmt, args))
|
// Resources.getString()
|
||||||
}
|
|
||||||
|
fun msg(priority: Int, res: Resources, @StringRes stringId: Int, args: Array<out Any?>) =
|
||||||
fun d(fmt : String, vararg args : Any?) {
|
msg(priority, res.getString(stringId, *args))
|
||||||
Log.d(tag, format(fmt, args))
|
|
||||||
}
|
fun e(res: Resources, @StringRes stringId: Int, vararg args: Any) =
|
||||||
|
msg(Log.ERROR, res, stringId, args)
|
||||||
fun v(fmt : String, vararg args : Any?) {
|
|
||||||
Log.v(tag, format(fmt, args))
|
fun w(res: Resources, @StringRes stringId: Int, vararg args: Any) =
|
||||||
}
|
msg(Log.WARN, res, stringId, args)
|
||||||
|
|
||||||
////////////////////////
|
fun i(res: Resources, @StringRes stringId: Int, vararg args: Any) =
|
||||||
// getString()
|
msg(Log.INFO, res, stringId, args)
|
||||||
|
|
||||||
fun e(res : Resources, string_id : Int, vararg args : Any?) {
|
fun d(res: Resources, @StringRes stringId: Int, vararg args: Any) =
|
||||||
Log.e(tag, format(res, string_id, args))
|
msg(Log.DEBUG, res, stringId, args)
|
||||||
}
|
|
||||||
|
fun v(res: Resources, @StringRes stringId: Int, vararg args: Any) =
|
||||||
fun w(res : Resources, string_id : Int, vararg args : Any?) {
|
msg(Log.VERBOSE, res, stringId, args)
|
||||||
Log.w(tag, format(res, string_id, args))
|
|
||||||
}
|
///////////////////////////////
|
||||||
|
// Throwable + string
|
||||||
fun i(res : Resources, string_id : Int, vararg args : Any?) {
|
|
||||||
Log.i(tag, format(res, string_id, args))
|
fun msg(priority: Int, ex: Throwable, caption: String = "exception.") =
|
||||||
}
|
msg(priority, ex.withCaption(caption))
|
||||||
|
|
||||||
fun d(res : Resources, string_id : Int, vararg args : Any?) {
|
fun e(ex: Throwable, caption: String) = msg(Log.ERROR, ex, caption)
|
||||||
Log.d(tag, format(res, string_id, args))
|
fun w(ex: Throwable, caption: String) = msg(Log.WARN, ex, caption)
|
||||||
}
|
fun i(ex: Throwable, caption: String) = msg(Log.INFO, ex, caption)
|
||||||
|
fun d(ex: Throwable, caption: String) = msg(Log.DEBUG, ex, caption)
|
||||||
fun v(res : Resources, string_id : Int, vararg args : Any?) {
|
fun v(ex: Throwable, caption: String) = msg(Log.VERBOSE, ex, caption)
|
||||||
Log.v(tag, format(res, string_id, args))
|
|
||||||
}
|
////////////////////////
|
||||||
////////////////////////
|
// stack trace
|
||||||
// exception
|
|
||||||
|
fun trace(ex: Throwable, caption: String = "exception."): Boolean {
|
||||||
fun e(ex : Throwable, fmt : String, vararg args : Any?) {
|
Log.e(tag, caption, ex)
|
||||||
Log.e(tag, ex.withCaption(format(fmt, args)))
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fun w(ex : Throwable, fmt : String, vararg args : Any?) {
|
|
||||||
Log.w(tag, ex.withCaption(format(fmt, args)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun i(ex : Throwable, fmt : String, vararg args : Any?) {
|
|
||||||
Log.i(tag, ex.withCaption(format(fmt, args)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun d(ex : Throwable, fmt : String, vararg args : Any?) {
|
|
||||||
Log.d(tag, ex.withCaption(format(fmt, args)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun v(ex : Throwable, fmt : String, vararg args : Any?) {
|
|
||||||
Log.v(tag, ex.withCaption(format(fmt, args)))
|
|
||||||
}
|
|
||||||
////////////////////////
|
|
||||||
// stack trace
|
|
||||||
|
|
||||||
fun trace(ex : Throwable, fmt : String, vararg args : Any?) {
|
|
||||||
Log.e(tag, format(fmt, args), ex)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun trace(ex : Throwable) {
|
|
||||||
Log.e(tag, "exception.", ex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue