2021-05-27 04:15:59 +02:00
|
|
|
package jp.juggler.subwaytooter.action
|
|
|
|
|
|
|
|
import jp.juggler.subwaytooter.ActMain
|
|
|
|
import jp.juggler.subwaytooter.ColumnType
|
|
|
|
import jp.juggler.subwaytooter.R
|
2021-06-23 06:14:25 +02:00
|
|
|
import jp.juggler.subwaytooter.addColumn
|
2021-05-27 04:15:59 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.EntityId
|
|
|
|
import jp.juggler.subwaytooter.api.entity.Host
|
2021-06-21 05:03:09 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAccount
|
2021-05-27 04:15:59 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootStatus
|
|
|
|
import jp.juggler.subwaytooter.api.runApiTask
|
|
|
|
import jp.juggler.subwaytooter.api.syncStatus
|
|
|
|
import jp.juggler.subwaytooter.dialog.pickAccount
|
|
|
|
import jp.juggler.subwaytooter.table.SavedAccount
|
|
|
|
import jp.juggler.subwaytooter.util.matchHost
|
|
|
|
import jp.juggler.util.launchMain
|
|
|
|
import jp.juggler.util.showToast
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
// アカウントを選んでタイムラインカラムを追加
|
|
|
|
fun ActMain.timeline(
|
|
|
|
pos: Int,
|
|
|
|
type: ColumnType,
|
2021-06-20 15:12:25 +02:00
|
|
|
args: Array<out Any> = emptyArray(),
|
2021-05-27 04:15:59 +02:00
|
|
|
) {
|
|
|
|
launchMain {
|
|
|
|
pickAccount(
|
|
|
|
bAllowPseudo = type.bAllowPseudo,
|
|
|
|
bAllowMisskey = type.bAllowMisskey,
|
|
|
|
bAllowMastodon = type.bAllowMastodon,
|
|
|
|
bAuto = true,
|
|
|
|
message = getString(R.string.account_picker_add_timeline_of, type.name1(applicationContext))
|
|
|
|
)?.let { account ->
|
|
|
|
when (type) {
|
|
|
|
ColumnType.PROFILE ->
|
|
|
|
account.loginAccount?.id?.let { addColumn(pos, account, type, it) }
|
|
|
|
|
|
|
|
ColumnType.PROFILE_DIRECTORY ->
|
|
|
|
addColumn(pos, account, type, account.apiHost)
|
|
|
|
|
|
|
|
else -> addColumn(pos, account, type, *args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// アカウント選択付きでタイムラインを追加
|
|
|
|
// その際にアカウントをラムダ式でフィルタする
|
|
|
|
//fun ActMain.timelineWithFilter(
|
|
|
|
// pos: Int,
|
|
|
|
// type: ColumnType,
|
|
|
|
// args: Array<out Any> = emptyArray(),
|
|
|
|
// filter: suspend (SavedAccount) -> Boolean
|
|
|
|
//) {
|
|
|
|
// launchMain {
|
|
|
|
// val accountList = accountListWithFilter { _, a ->
|
|
|
|
// when {
|
|
|
|
// a.isPseudo && !type.bAllowPseudo -> false
|
|
|
|
// a.isMisskey && !type.bAllowMisskey -> false
|
|
|
|
// a.isMastodon && !type.bAllowMastodon -> false
|
|
|
|
// else -> filter(a)
|
|
|
|
// }
|
|
|
|
// }?.toMutableList() ?: return@launchMain
|
|
|
|
//
|
|
|
|
// pickAccount(
|
|
|
|
// accountListArg = accountList,
|
|
|
|
// bAuto = true,
|
|
|
|
// message = getString(
|
|
|
|
// R.string.account_picker_add_timeline_of,
|
|
|
|
// type.name1(applicationContext)
|
|
|
|
// )
|
|
|
|
// )?.let { ai ->
|
|
|
|
// when (type) {
|
|
|
|
// ColumnType.PROFILE ->
|
|
|
|
// ai.loginAccount?.id?.let { addColumn(pos, ai, type, it) }
|
|
|
|
//
|
|
|
|
// ColumnType.PROFILE_DIRECTORY ->
|
|
|
|
// addColumn(pos, ai, type, ai.apiHost)
|
|
|
|
//
|
|
|
|
// else ->
|
|
|
|
// addColumn(pos, ai, type, *args)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
// 指定アカウントで指定タンスのドメインタイムラインを開く
|
|
|
|
// https://fedibird.com/@noellabo/103266814160117397
|
|
|
|
fun ActMain.timelineDomain(
|
|
|
|
pos: Int,
|
|
|
|
accessInfo: SavedAccount,
|
2021-06-20 15:12:25 +02:00
|
|
|
host: Host,
|
2021-05-27 04:15:59 +02:00
|
|
|
) = addColumn(pos, accessInfo, ColumnType.DOMAIN_TIMELINE, host)
|
|
|
|
|
|
|
|
// 指定タンスのローカルタイムラインを開く
|
|
|
|
fun ActMain.timelineLocal(
|
|
|
|
pos: Int,
|
2021-06-20 15:12:25 +02:00
|
|
|
host: Host,
|
2021-05-27 04:15:59 +02:00
|
|
|
) {
|
|
|
|
launchMain {
|
|
|
|
// 指定タンスのアカウントを持ってるか?
|
2021-06-20 15:12:25 +02:00
|
|
|
val accountList = ArrayList<SavedAccount>()
|
2021-05-27 04:15:59 +02:00
|
|
|
for (a in SavedAccount.loadAccountList(applicationContext)) {
|
2021-06-20 15:12:25 +02:00
|
|
|
if (a.matchHost(host)) accountList.add(a)
|
2021-05-27 04:15:59 +02:00
|
|
|
}
|
|
|
|
|
2021-06-20 15:12:25 +02:00
|
|
|
if (accountList.isEmpty()) {
|
2021-05-27 04:15:59 +02:00
|
|
|
// 持ってないなら疑似アカウントを追加する
|
|
|
|
addPseudoAccount(host)?.let { ai ->
|
|
|
|
addColumn(pos, ai, ColumnType.LOCAL)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 持ってるならアカウントを選んで開く
|
2021-06-20 15:12:25 +02:00
|
|
|
SavedAccount.sort(accountList)
|
2021-05-27 04:15:59 +02:00
|
|
|
pickAccount(
|
|
|
|
bAllowPseudo = true,
|
|
|
|
bAuto = false,
|
|
|
|
message = getString(R.string.account_picker_add_timeline_of, host),
|
2021-06-20 15:12:25 +02:00
|
|
|
accountListArg = accountList
|
2021-05-27 04:15:59 +02:00
|
|
|
)?.let { addColumn(pos, it, ColumnType.LOCAL) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun ActMain.timelineAround(
|
2021-06-20 15:12:25 +02:00
|
|
|
accessInfo: SavedAccount,
|
2021-05-27 04:15:59 +02:00
|
|
|
pos: Int,
|
|
|
|
id: EntityId,
|
2021-06-20 15:12:25 +02:00
|
|
|
type: ColumnType,
|
|
|
|
) = addColumn(pos, accessInfo, type, id)
|
2021-05-27 04:15:59 +02:00
|
|
|
|
|
|
|
// 投稿を同期してstatusIdを調べてから指定アカウントでタイムラインを開く
|
|
|
|
private fun ActMain.timelineAroundByStatus(
|
2021-06-20 15:12:25 +02:00
|
|
|
accessInfo: SavedAccount,
|
2021-05-27 04:15:59 +02:00
|
|
|
pos: Int,
|
|
|
|
status: TootStatus,
|
2021-06-20 15:12:25 +02:00
|
|
|
type: ColumnType,
|
2021-05-27 04:15:59 +02:00
|
|
|
) {
|
|
|
|
launchMain {
|
|
|
|
var resultStatus: TootStatus? = null
|
2021-06-20 15:12:25 +02:00
|
|
|
runApiTask(accessInfo) { client ->
|
|
|
|
val pair = client.syncStatus(accessInfo, status)
|
2021-05-27 04:15:59 +02:00
|
|
|
resultStatus = pair.second
|
|
|
|
pair.first
|
|
|
|
}?.let { result ->
|
|
|
|
when (val localStatus = resultStatus) {
|
|
|
|
null -> showToast(true, result.error)
|
2021-06-20 15:12:25 +02:00
|
|
|
else -> timelineAround(accessInfo, pos, localStatus.id, type)
|
2021-05-27 04:15:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 指定タンスの指定投稿付近のタイムラインを開く。アカウント選択あり。
|
|
|
|
fun ActMain.timelineAroundByStatusAnotherAccount(
|
2021-06-20 15:12:25 +02:00
|
|
|
accessInfo: SavedAccount,
|
2021-05-27 04:15:59 +02:00
|
|
|
pos: Int,
|
|
|
|
host: Host?,
|
|
|
|
status: TootStatus?,
|
|
|
|
type: ColumnType,
|
2021-06-20 15:12:25 +02:00
|
|
|
allowPseudo: Boolean = true,
|
2021-05-27 04:15:59 +02:00
|
|
|
) {
|
|
|
|
host?.valid() ?: return
|
|
|
|
status ?: return
|
|
|
|
|
|
|
|
// 利用可能なアカウントを列挙する
|
2021-06-20 15:12:25 +02:00
|
|
|
val accountList1 = ArrayList<SavedAccount>() // 閲覧アカウントとホストが同じ
|
|
|
|
val accountList2 = ArrayList<SavedAccount>() // その他実アカウント
|
2021-05-27 04:15:59 +02:00
|
|
|
label@ for (a in SavedAccount.loadAccountList(this)) {
|
|
|
|
// Misskeyアカウントはステータスの同期が出来ないので選択させない
|
|
|
|
if (a.isNA || a.isMisskey) continue
|
|
|
|
when {
|
|
|
|
// 閲覧アカウントとホスト名が同じならステータスIDの変換が必要ない
|
2021-06-20 15:12:25 +02:00
|
|
|
a.matchHost(accessInfo) -> if (allowPseudo || !a.isPseudo) accountList1.add(a)
|
2021-05-27 04:15:59 +02:00
|
|
|
|
|
|
|
// 実アカウントならステータスを同期して同時間帯のTLを見れる
|
2021-06-20 15:12:25 +02:00
|
|
|
!a.isPseudo -> accountList2.add(a)
|
2021-05-27 04:15:59 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-20 15:12:25 +02:00
|
|
|
SavedAccount.sort(accountList1)
|
|
|
|
SavedAccount.sort(accountList2)
|
|
|
|
accountList1.addAll(accountList2)
|
2021-05-27 04:15:59 +02:00
|
|
|
|
2021-06-20 15:12:25 +02:00
|
|
|
if (accountList1.isEmpty()) {
|
2021-05-27 04:15:59 +02:00
|
|
|
showToast(false, R.string.missing_available_account)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
launchMain {
|
|
|
|
pickAccount(
|
|
|
|
bAuto = true,
|
|
|
|
message = "select account to read timeline",
|
2021-06-20 15:12:25 +02:00
|
|
|
accountListArg = accountList1
|
2021-05-27 04:15:59 +02:00
|
|
|
)?.let { ai ->
|
2021-06-20 15:12:25 +02:00
|
|
|
if (!ai.isNA && ai.matchHost(accessInfo)) {
|
2021-05-27 04:15:59 +02:00
|
|
|
timelineAround(ai, pos, status.id, type)
|
|
|
|
} else {
|
|
|
|
timelineAroundByStatus(ai, pos, status, type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-21 05:03:09 +02:00
|
|
|
|
|
|
|
fun ActMain.clickAroundAccountTL(accessInfo: SavedAccount, pos: Int, who: TootAccount, status: TootStatus?) =
|
|
|
|
timelineAroundByStatusAnotherAccount(
|
|
|
|
accessInfo,
|
|
|
|
pos,
|
|
|
|
who.apiHost,
|
|
|
|
status,
|
|
|
|
ColumnType.ACCOUNT_AROUND, allowPseudo = false
|
|
|
|
)
|
|
|
|
|
|
|
|
fun ActMain.clickAroundLTL(accessInfo: SavedAccount, pos: Int, who: TootAccount, status: TootStatus?) =
|
|
|
|
timelineAroundByStatusAnotherAccount(
|
|
|
|
accessInfo,
|
|
|
|
pos,
|
|
|
|
who.apiHost,
|
|
|
|
status,
|
|
|
|
ColumnType.LOCAL_AROUND
|
|
|
|
)
|
|
|
|
|
|
|
|
fun ActMain.clickAroundFTL(accessInfo: SavedAccount, pos: Int, who: TootAccount, status: TootStatus?) =
|
|
|
|
timelineAroundByStatusAnotherAccount(
|
|
|
|
accessInfo,
|
|
|
|
pos,
|
|
|
|
who.apiHost,
|
|
|
|
status,
|
|
|
|
ColumnType.FEDERATED_AROUND
|
|
|
|
)
|