予約投稿カラムでカラムロードじに投稿者の情報も読む。あと忘れたけどなにかリファクタらしきもの

This commit is contained in:
tateisu 2020-05-16 21:01:24 +09:00
parent cd3b6ec37d
commit 290205dba9
4 changed files with 66 additions and 53 deletions

View File

@ -817,7 +817,7 @@ class ActPost : AsyncActivity(),
// 比較する前にデフォルトの公開範囲を計算する
visibility = visibility
?: account.visibility
// ?: TootVisibility.Public
// ?: TootVisibility.Public
// VISIBILITY_WEB_SETTING だと 1.5未満のタンスでトラブルになる
if(TootVisibility.WebSetting == visibility) {
@ -2276,55 +2276,54 @@ class ActPost : AsyncActivity(),
fun postV1() = postMedia("/api/v1/media")
var result : TootApiResult?
if(! ti.versionGE(TootInstance.VERSION_3_1_3)) {
fun postV2() : TootApiResult? {
// 3.1.3未満は v1 APIを使う
result = postV1()
} else {
if(! ti.versionGE(TootInstance.VERSION_3_1_3))
return postV1()
// v2 APIを試す
result = postMedia("/api/v2/media")
when(result?.response?.code) {
val result = postMedia("/api/v2/media")
val code = result?.response?.code // complete,or 4xx error
when {
// 404ならv1 APIにフォールバック
404 -> result = postV1()
code == 404 -> return postV1()
// 202 accepted 以外はポーリングしない
code != 202 -> return result
}
// ポーリングして処理完了を待つ
val id = parseItem(
::TootAttachment,
ServiceType.MASTODON,
result?.jsonObject
)
?.id
?: return TootApiResult("/api/v2/media did not return the media ID.")
var lastResponse = SystemClock.elapsedRealtime()
loop@ while(true) {
// 202 accepted ならポーリングして処理完了を待つ
202 -> {
val id = parseItem(
::TootAttachment,
ServiceType.MASTODON,
result.jsonObject
)
?.id
?: error("/api/v2/media did not returns media ID.")
var lastResponse = SystemClock.elapsedRealtime()
while(true) {
result = client.request("/api/v1/media/$id")
?: break // cancelled.
val code = result.response?.code
// complete,or 4xx error
if(code == 200 || code in 400 until 500) break
val now = SystemClock.elapsedRealtime()
if( code == 206) {
// continue to wait
lastResponse = now
}else if( now - lastResponse >= 120000L ) {
// too many temporary error without 206 response.
result = TootApiResult("timeout.")
break
} // else temporary error
sleep(1000L)
}
sleep(1000L)
val r2 = client.request("/api/v1/media/$id")
?: return null // cancelled
val now = SystemClock.elapsedRealtime()
when(r2.response?.code) {
// complete,or 4xx error
200, in 400 until 500 -> return r2
// continue to wait
206 -> lastResponse = now
// too many temporary error without 206 response.
else ->
if(now - lastResponse >= 120000L)
return TootApiResult("timeout.")
}
}
}
val result = postV2()
opener.deleteTempFile()
onUploadEnd()
@ -2780,11 +2779,11 @@ class ActPost : AsyncActivity(),
val list_warning = ArrayList<String>()
var target_account : SavedAccount? = null
runWithProgress(
"restore from draft",
{progress->
fun isTaskCancelled() = !this.coroutineContext.isActive
{ progress ->
fun isTaskCancelled() = ! this.coroutineContext.isActive
var content = draft.string(DRAFT_CONTENT) ?: ""
val account_db_id = draft.long(DRAFT_ACCOUNT_DB_ID) ?: - 1L
@ -2816,7 +2815,7 @@ class ActPost : AsyncActivity(),
return@runWithProgress "OK"
}
target_account = account
// アカウントがあるなら基本的にはすべての情報を復元できるはずだが、いくつか確認が必要だ
@ -2874,9 +2873,9 @@ class ActPost : AsyncActivity(),
"OK"
},
{result->
{ result ->
// cancelled.
if( result == null) return@runWithProgress
if(result == null) return@runWithProgress
val content = draft.string(DRAFT_CONTENT) ?: ""
val content_warning = draft.string(DRAFT_CONTENT_WARNING) ?: ""

View File

@ -1473,7 +1473,21 @@ enum class ColumnType(
bAllowPseudo = false,
bAllowMisskey = false,
loading = { client -> getScheduledStatuses(client) },
loading = { client ->
val result = client.request("/api/v1/accounts/verify_credentials")
if(result==null || result.error != null){
result
}else{
val a = parser.account(result.jsonObject) ?: access_info.loginAccount
if(a==null){
TootApiResult("can't parse account information")
}else {
column.who_account = TootAccountRef(parser, a)
getScheduledStatuses(client)
}
}
},
refresh = { client -> getScheduledStatuses(client) }
),

View File

@ -572,8 +572,8 @@ internal class ItemViewHolder(
showStatusTimeScheduled(activity, tvTime, item)
val who = access_info.loginAccount !!
val whoRef = TootAccountRef(TootParser(activity, access_info), who)
val who = column.who_account!!.get()
val whoRef = TootAccountRef(TootParser(activity, access_info), who )
this.status_account = whoRef
setAcct(tvAcct, access_info, who)

View File

@ -22,7 +22,6 @@ import java.util.concurrent.atomic.AtomicBoolean
- TootApiClientからの進捗イベントをProgressDialogに伝達します
*/
@Suppress("DEPRECATION", "MemberVisibilityCanPrivate")
class TootTaskRunner(
context : Context,
private val progress_style : Int = PROGRESS_SPINNER,
@ -30,7 +29,6 @@ class TootTaskRunner(
) : TootApiCallback {
companion object {
const val PROGRESS_NONE = - 1
const val PROGRESS_SPINNER = ProgressDialogEx.STYLE_SPINNER
const val PROGRESS_HORIZONTAL = ProgressDialogEx.STYLE_HORIZONTAL
@ -153,6 +151,7 @@ class TootTaskRunner(
this.progress = progress
progress.setCancelable(true)
progress.setOnCancelListener { task?.cancel() }
@Suppress("DEPRECATION")
progress.setProgressStyle(progress_style)
progressSetupCallback(progress)
showProgressMessage()
@ -169,6 +168,7 @@ class TootTaskRunner(
// ダイアログのメッセージを更新する
// 初期化時とメッセージ更新時に呼ばれる
@Suppress("DEPRECATION")
private fun showProgressMessage() {
val progress = this.progress ?: return