1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2025-02-08 08:09:02 +01:00

煩雑なログやステータス表示を軽減する

This commit is contained in:
tateisu 2023-02-09 15:17:37 +09:00
parent 03352bb180
commit fd3e329e7e
7 changed files with 44 additions and 25 deletions

View File

@ -158,6 +158,8 @@ class ActMain : AppCompatActivity(),
lateinit var sideMenuAdapter: SideMenuAdapter
var subscriptionUpdaterCalled = false
//////////////////////////////////////////////////////////////////
// 読み取り専用のプロパティ

View File

@ -253,7 +253,12 @@ fun ActMain.launchDialogs() {
if (!prNotification.checkOrLaunch()) return@launchAndShowError
}
afterNotificationGranted()
// 画面を作成したあと一度だけ行う
// 画像ビューアから戻ってきたときなどは行わない
if(!subscriptionUpdaterCalled){
subscriptionUpdaterCalled=true
afterNotificationGranted()
}
}
}

View File

@ -183,7 +183,7 @@ class PollingChecker(
account.acct,
null
)
log.i("notification check not required.")
log.i("[${account.acct}]pull check not required.")
return@withLock
}

View File

@ -57,7 +57,7 @@ fun AppCompatActivity.resetNotificationTracking(account: SavedAccount) {
return
}
launchAndShowError {
withContext(AppDispatchers.IO){
withContext(AppDispatchers.IO) {
daoNotificationShown.cleayByAcct(account.acct)
PollingChecker.accountMutex(account.db_id).withLock {
daoNotificationTracking.resetTrackingState(account.db_id)
@ -204,7 +204,7 @@ suspend fun checkNoticifationAll(
// 進捗表示
// 複数アカウントの状態をマップにまとめる
suspend fun updateStatus(a: SavedAccount, s: PollingState) {
log.i("$logPrefix[${a.acct.pretty}]${s.desc}")
if (s != PollingState.Complete) log.i("$logPrefix[${a.acct.pretty}]${s.desc}")
when (s) {
PollingState.CheckNotifications,
-> nextPollingRequired = true
@ -235,6 +235,15 @@ suspend fun checkNoticifationAll(
daoSavedAccount.loadRealAccounts().mapNotNull { sa ->
when {
sa.isPseudo || !sa.isConfirmed -> null
!sa.isRequiredPullCheck() -> {
// 通知チェックの定期実行が不要なら
// 通知表示のエラーをクリアする
daoAccountNotificationStatus.updateNotificationError(
sa.acct,
null
)
null
}
else -> EmptyScope.launch(AppDispatchers.DEFAULT) {
try {
PollingChecker(

View File

@ -73,8 +73,6 @@ class PushMastodon(
throw ex
}
}
log.i("${account.acct} oldSubscription=${oldSubscription}")
val oldEndpointUrl = oldSubscription?.string("endpoint")
when (oldEndpointUrl) {
// 購読がない。作ってもよい
@ -94,7 +92,6 @@ class PushMastodon(
}
if (params["dh"] != deviceHash && !isOldSubscription(account, oldEndpointUrl)) {
// この端末で作成した購読ではない。
// TODO: 古い形式のURLを移行できないか
log.w("deviceHash not match. keep it for other devices. ${account.acct} $oldEndpointUrl")
return context.getString(
R.string.push_subscription_exists_but_not_created_by_this_device
@ -145,6 +142,8 @@ class PushMastodon(
return null
}
log.i("${account.acct} oldSubscription=${oldSubscription}")
if (newUrl == oldEndpointUrl) {
subLog.i(R.string.push_subscription_exists_updateing)
api.updatePushSubscriptionData(

View File

@ -268,6 +268,7 @@ class PushRepo(
val now = System.currentTimeMillis()
if (now - lastUpdated < TimeUnit.DAYS.toMillis(3)) {
log.i("lazeMode: skip re-registration.")
return
}
}

View File

@ -50,17 +50,17 @@ class AccountNotificationStatus(
private const val COL_LAST_SUBSCRIPTION_ERROR = "last_subscription_error"
val columnList = MetaColumns(table = TABLE, initialVersion = 65).apply {
column( 0, COL_ID, MetaColumns.TS_INT_PRIMARY_KEY_NOT_NULL)
column( 0, COL_ACCT, MetaColumns.TS_EMPTY_NOT_NULL)
column( 0, COL_ACCT_HASH, MetaColumns.TS_EMPTY_NOT_NULL)
column( 0, COL_APP_SERVER_HASH, MetaColumns.TS_TEXT_NULL)
column( 0, COL_PUSH_KEY_PRIVATE, MetaColumns.TS_BLOB_NULL)
column( 0, COL_PUSH_KEY_PUBLIC, MetaColumns.TS_BLOB_NULL)
column( 0, COL_PUSH_AUTH_SECRET, MetaColumns.TS_BLOB_NULL)
column( 0, COL_PUSH_SERVER_KEY, MetaColumns.TS_BLOB_NULL)
column( 0, COL_LAST_PUSH_ENDPOINT, MetaColumns.TS_TEXT_NULL)
column( 0, COL_LAST_NOTIFICATION_ERROR, MetaColumns.TS_TEXT_NULL)
column( 0, COL_LAST_SUBSCRIPTION_ERROR, MetaColumns.TS_TEXT_NULL)
column(0, COL_ID, MetaColumns.TS_INT_PRIMARY_KEY_NOT_NULL)
column(0, COL_ACCT, MetaColumns.TS_EMPTY_NOT_NULL)
column(0, COL_ACCT_HASH, MetaColumns.TS_EMPTY_NOT_NULL)
column(0, COL_APP_SERVER_HASH, MetaColumns.TS_TEXT_NULL)
column(0, COL_PUSH_KEY_PRIVATE, MetaColumns.TS_BLOB_NULL)
column(0, COL_PUSH_KEY_PUBLIC, MetaColumns.TS_BLOB_NULL)
column(0, COL_PUSH_AUTH_SECRET, MetaColumns.TS_BLOB_NULL)
column(0, COL_PUSH_SERVER_KEY, MetaColumns.TS_BLOB_NULL)
column(0, COL_LAST_PUSH_ENDPOINT, MetaColumns.TS_TEXT_NULL)
column(0, COL_LAST_NOTIFICATION_ERROR, MetaColumns.TS_TEXT_NULL)
column(0, COL_LAST_SUBSCRIPTION_ERROR, MetaColumns.TS_TEXT_NULL)
createExtra = {
arrayOf(
@ -240,17 +240,20 @@ class AccountNotificationStatus(
put(COL_APP_SERVER_HASH, appServerHash)
}.updateTo(db, TABLE, id.toString())
private fun updateSingleString(acct:Acct, col: String, value: String?) {
ContentValues().apply{
put(col, value)
}.updateTo(db, TABLE,acct.ascii, COL_ACCT)
private fun updateSingleString(acct: Acct, col: String, value: String?) {
db.update(
TABLE,
ContentValues().apply { put(col, value) },
"$COL_ACCT=? and $col!=?",
arrayOf(acct.ascii, value)
)
}
fun updateNotificationError(acct:Acct, text: String?) {
fun updateNotificationError(acct: Acct, text: String?) {
updateSingleString(acct, COL_LAST_NOTIFICATION_ERROR, text)
}
fun updateSubscriptionError(acct:Acct, text: String?) {
fun updateSubscriptionError(acct: Acct, text: String?) {
updateSingleString(acct, COL_LAST_SUBSCRIPTION_ERROR, text)
}
}