2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter.table
|
|
|
|
|
|
|
|
import android.content.ContentValues
|
|
|
|
import android.content.Context
|
|
|
|
import android.database.Cursor
|
|
|
|
import android.database.sqlite.SQLiteDatabase
|
|
|
|
import android.provider.BaseColumns
|
|
|
|
import jp.juggler.subwaytooter.App1
|
2021-02-09 23:25:06 +01:00
|
|
|
import jp.juggler.subwaytooter.Pref
|
|
|
|
import jp.juggler.subwaytooter.R
|
2020-12-11 18:30:10 +01:00
|
|
|
import jp.juggler.subwaytooter.notification.PollingWorker
|
2018-08-20 02:07:55 +02:00
|
|
|
import jp.juggler.subwaytooter.api.TootApiClient
|
2018-12-25 12:54:41 +01:00
|
|
|
import jp.juggler.subwaytooter.api.TootApiResult
|
2018-01-21 17:47:13 +01:00
|
|
|
import jp.juggler.subwaytooter.api.TootParser
|
2020-02-02 15:19:57 +01:00
|
|
|
import jp.juggler.subwaytooter.api.entity.*
|
2019-10-22 20:21:03 +02:00
|
|
|
import jp.juggler.subwaytooter.util.LinkHelper
|
2018-12-01 00:02:18 +01:00
|
|
|
import jp.juggler.util.*
|
2018-08-20 19:37:42 +02:00
|
|
|
import java.util.*
|
2021-02-09 23:25:06 +01:00
|
|
|
import kotlin.math.max
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
class SavedAccount(
|
2018-01-10 16:47:35 +01:00
|
|
|
val db_id : Long,
|
2020-02-01 19:28:16 +01:00
|
|
|
acctArg : String,
|
2020-09-07 14:20:11 +02:00
|
|
|
apiHostArg : String? = null,
|
2020-09-29 19:44:56 +02:00
|
|
|
apDomainArg : String? = null,
|
2020-01-07 09:03:32 +01:00
|
|
|
var token_info : JsonObject? = null,
|
2018-08-16 21:58:30 +02:00
|
|
|
var loginAccount : TootAccount? = null, // 疑似アカウントではnull
|
2019-10-22 20:21:03 +02:00
|
|
|
override val misskeyVersion : Int = 0
|
2018-01-21 13:51:10 +01:00
|
|
|
) : LinkHelper {
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2020-09-07 14:20:11 +02:00
|
|
|
// SavedAccountのロード時にhostを供給する必要があった
|
|
|
|
override val apiHost : Host
|
|
|
|
// fun findAcct(url : String?) : String? = null
|
|
|
|
// fun colorFromAcct(acct : String?) : AcctColor? = null
|
|
|
|
|
|
|
|
override val apDomain : Host
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
val username : String
|
2018-01-21 17:47:13 +01:00
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
val acct : Acct
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-08-20 19:37:42 +02:00
|
|
|
var visibility : TootVisibility = TootVisibility.Public
|
2018-01-04 19:52:25 +01:00
|
|
|
var confirm_boost : Boolean = false
|
2018-04-17 14:41:22 +02:00
|
|
|
var confirm_favourite : Boolean = false
|
2018-04-20 12:43:09 +02:00
|
|
|
var confirm_unboost : Boolean = false
|
|
|
|
var confirm_unfavourite : Boolean = false
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
var dont_hide_nsfw : Boolean = false
|
|
|
|
var dont_show_timeout : Boolean = false
|
|
|
|
|
|
|
|
var notification_mention : Boolean = false
|
|
|
|
var notification_boost : Boolean = false
|
|
|
|
var notification_favourite : Boolean = false
|
|
|
|
var notification_follow : Boolean = false
|
2019-12-16 16:56:27 +01:00
|
|
|
var notification_follow_request : Boolean = false
|
2018-08-30 08:51:32 +02:00
|
|
|
var notification_reaction : Boolean = false
|
|
|
|
var notification_vote : Boolean = false
|
2020-09-20 04:51:15 +02:00
|
|
|
var notification_post : Boolean = false
|
2018-01-04 19:52:25 +01:00
|
|
|
var sound_uri = ""
|
|
|
|
|
|
|
|
var confirm_follow : Boolean = false
|
|
|
|
var confirm_follow_locked : Boolean = false
|
|
|
|
var confirm_unfollow : Boolean = false
|
|
|
|
var confirm_post : Boolean = false
|
|
|
|
|
|
|
|
var notification_tag : String? = null
|
2019-08-25 10:04:34 +02:00
|
|
|
private var register_key : String? = null
|
|
|
|
private var register_time : Long = 0
|
2018-08-04 20:56:51 +02:00
|
|
|
var default_text : String = ""
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
var default_sensitive = false
|
|
|
|
var expand_cw = false
|
|
|
|
|
2019-08-12 05:32:39 +02:00
|
|
|
var max_toot_chars = 0
|
|
|
|
|
2019-10-22 20:21:03 +02:00
|
|
|
var last_notification_error : String? = null
|
2019-12-17 18:58:49 +01:00
|
|
|
var last_subscription_error : String? = null
|
2019-12-18 08:52:55 +01:00
|
|
|
var last_push_endpoint : String? = null
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
var image_resize: String? = null
|
|
|
|
var image_max_megabytes : String? = null
|
|
|
|
var movie_max_megabytes : String? = null
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
init {
|
2020-02-02 15:19:57 +01:00
|
|
|
val tmpAcct = Acct.parse(acctArg)
|
|
|
|
this.username = tmpAcct.username
|
2018-01-10 16:47:35 +01:00
|
|
|
if(username.isEmpty()) throw RuntimeException("missing username in acct")
|
2020-09-29 19:44:56 +02:00
|
|
|
|
|
|
|
val tmpApiHost = apiHostArg?.notEmpty()?.let { Host.parse(it) }
|
|
|
|
val tmpApDomain = apDomainArg?.notEmpty()?.let { Host.parse(it) }
|
2020-09-07 14:20:11 +02:00
|
|
|
|
|
|
|
this.apiHost = tmpApiHost ?: tmpApDomain ?: tmpAcct.host ?: error("missing apiHost")
|
|
|
|
this.apDomain = tmpApDomain ?: tmpApiHost ?: tmpAcct.host ?: error("missing apDomain")
|
2021-02-05 00:51:45 +01:00
|
|
|
|
2020-09-07 14:20:11 +02:00
|
|
|
this.acct = tmpAcct.followHost(apDomain)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
constructor(context : Context, cursor : Cursor) : this(
|
2020-09-07 14:20:11 +02:00
|
|
|
db_id = cursor.getLong(COL_ID), // db_id
|
|
|
|
acctArg = cursor.getString(COL_USER), // acct
|
|
|
|
apiHostArg = cursor.getStringOrNull(COL_HOST), // host
|
|
|
|
apDomainArg = cursor.getStringOrNull(COL_DOMAIN), // host
|
|
|
|
misskeyVersion = cursor.getInt(COL_MISSKEY_VERSION)
|
2018-01-10 16:47:35 +01:00
|
|
|
) {
|
2019-08-25 10:04:34 +02:00
|
|
|
val strAccount = cursor.getString(COL_ACCOUNT)
|
2020-01-08 03:57:10 +01:00
|
|
|
val jsonAccount = strAccount.decodeJsonObject()
|
2019-12-17 18:58:49 +01:00
|
|
|
|
2020-01-08 03:57:10 +01:00
|
|
|
loginAccount = if(jsonAccount["id"] == null) {
|
2019-08-25 10:04:34 +02:00
|
|
|
null // 疑似アカウント
|
2018-08-20 19:37:42 +02:00
|
|
|
} else {
|
2019-08-25 10:04:34 +02:00
|
|
|
TootParser(
|
2018-08-20 02:07:55 +02:00
|
|
|
context,
|
2020-09-21 00:00:04 +02:00
|
|
|
LinkHelper.create(
|
2020-09-07 14:20:11 +02:00
|
|
|
apiHostArg = this@SavedAccount.apiHost,
|
2020-09-29 19:44:56 +02:00
|
|
|
apDomainArg = this@SavedAccount.apDomain,
|
2020-09-07 14:20:11 +02:00
|
|
|
misskeyVersion = misskeyVersion
|
|
|
|
)
|
2018-08-20 02:07:55 +02:00
|
|
|
).account(jsonAccount)
|
2019-08-25 10:04:34 +02:00
|
|
|
?: error("missing loginAccount for $strAccount")
|
2018-01-10 16:47:35 +01:00
|
|
|
}
|
2018-08-20 02:07:55 +02:00
|
|
|
|
2018-10-30 20:29:00 +01:00
|
|
|
val sv = cursor.getStringOrNull(COL_VISIBILITY)
|
2019-12-17 18:58:49 +01:00
|
|
|
visibility = TootVisibility.parseSavedVisibility(sv) ?: TootVisibility.Public
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
confirm_boost = cursor.getBoolean(COL_CONFIRM_BOOST)
|
|
|
|
confirm_favourite = cursor.getBoolean(COL_CONFIRM_FAVOURITE)
|
|
|
|
confirm_unboost = cursor.getBoolean(COL_CONFIRM_UNBOOST)
|
|
|
|
confirm_unfavourite = cursor.getBoolean(COL_CONFIRM_UNFAVOURITE)
|
|
|
|
confirm_follow = cursor.getBoolean(COL_CONFIRM_FOLLOW)
|
|
|
|
confirm_follow_locked = cursor.getBoolean(COL_CONFIRM_FOLLOW_LOCKED)
|
|
|
|
confirm_unfollow = cursor.getBoolean(COL_CONFIRM_UNFOLLOW)
|
|
|
|
confirm_post = cursor.getBoolean(COL_CONFIRM_POST)
|
2018-10-30 20:29:00 +01:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
notification_mention = cursor.getBoolean(COL_NOTIFICATION_MENTION)
|
|
|
|
notification_boost = cursor.getBoolean(COL_NOTIFICATION_BOOST)
|
|
|
|
notification_favourite = cursor.getBoolean(COL_NOTIFICATION_FAVOURITE)
|
|
|
|
notification_follow = cursor.getBoolean(COL_NOTIFICATION_FOLLOW)
|
|
|
|
notification_follow_request = cursor.getBoolean(COL_NOTIFICATION_FOLLOW_REQUEST)
|
|
|
|
notification_reaction = cursor.getBoolean(COL_NOTIFICATION_REACTION)
|
|
|
|
notification_vote = cursor.getBoolean(COL_NOTIFICATION_VOTE)
|
2020-09-20 04:51:15 +02:00
|
|
|
notification_post = cursor.getBoolean(COL_NOTIFICATION_POST)
|
2019-10-22 20:21:03 +02:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
dont_hide_nsfw = cursor.getBoolean(COL_DONT_HIDE_NSFW)
|
|
|
|
dont_show_timeout = cursor.getBoolean(COL_DONT_SHOW_TIMEOUT)
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
notification_tag = cursor.getStringOrNull(COL_NOTIFICATION_TAG)
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
register_key = cursor.getStringOrNull(COL_REGISTER_KEY)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
register_time = cursor.getLong(COL_REGISTER_TIME)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-01-08 03:57:10 +01:00
|
|
|
token_info = cursor.getString(COL_TOKEN).decodeJsonObject()
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
sound_uri = cursor.getString(COL_SOUND_URI)
|
2018-08-04 20:56:51 +02:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
default_text = cursor.getStringOrNull(COL_DEFAULT_TEXT) ?: ""
|
2019-10-22 20:21:03 +02:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
default_sensitive = cursor.getBoolean(COL_DEFAULT_SENSITIVE)
|
|
|
|
expand_cw = cursor.getBoolean(COL_EXPAND_CW)
|
|
|
|
max_toot_chars = cursor.getInt(COL_MAX_TOOT_CHARS)
|
2018-08-16 21:58:30 +02:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
last_notification_error = cursor.getStringOrNull(COL_LAST_NOTIFICATION_ERROR)
|
|
|
|
last_subscription_error = cursor.getStringOrNull(COL_LAST_SUBSCRIPTION_ERROR)
|
2019-12-18 08:52:55 +01:00
|
|
|
last_push_endpoint = cursor.getStringOrNull(COL_LAST_PUSH_ENDPOINT)
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
image_resize = cursor.getStringOrNull(COL_IMAGE_RESIZE)
|
|
|
|
image_max_megabytes = cursor.getStringOrNull(COL_IMAGE_MAX_MEGABYTES)
|
|
|
|
movie_max_megabytes = cursor.getStringOrNull(COL_MOVIE_MAX_MEGABYTES)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
val isNA : Boolean
|
2020-02-02 15:19:57 +01:00
|
|
|
get() = acct == Acct.UNKNOWN
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
val isPseudo : Boolean
|
|
|
|
get() = username == "?"
|
|
|
|
|
|
|
|
fun delete() {
|
|
|
|
try {
|
2018-08-04 20:56:51 +02:00
|
|
|
App1.database.delete(table, "$COL_ID=?", arrayOf(db_id.toString()))
|
2018-01-04 19:52:25 +01:00
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
throw RuntimeException("SavedAccount.delete failed.", ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
fun updateTokenInfo(tokenInfoArg : JsonObject?) {
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
if(db_id == INVALID_DB_ID) throw RuntimeException("updateTokenInfo: missing db_id")
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
val token_info = tokenInfoArg ?: JsonObject()
|
2018-01-04 19:52:25 +01:00
|
|
|
this.token_info = token_info
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
val cv = ContentValues()
|
|
|
|
cv.put(COL_TOKEN, token_info.toString())
|
2018-08-04 20:56:51 +02:00
|
|
|
App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun saveSetting() {
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
if(db_id == INVALID_DB_ID) throw RuntimeException("saveSetting: missing db_id")
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
val cv = ContentValues()
|
2018-08-20 19:37:42 +02:00
|
|
|
cv.put(COL_VISIBILITY, visibility.id.toString())
|
2018-01-10 16:47:35 +01:00
|
|
|
cv.put(COL_CONFIRM_BOOST, confirm_boost.b2i())
|
2018-04-17 14:41:22 +02:00
|
|
|
cv.put(COL_CONFIRM_FAVOURITE, confirm_favourite.b2i())
|
2018-04-20 12:43:09 +02:00
|
|
|
cv.put(COL_CONFIRM_UNBOOST, confirm_unboost.b2i())
|
|
|
|
cv.put(COL_CONFIRM_UNFAVOURITE, confirm_unfavourite.b2i())
|
2018-08-20 19:37:42 +02:00
|
|
|
|
2018-01-10 16:47:35 +01:00
|
|
|
cv.put(COL_DONT_HIDE_NSFW, dont_hide_nsfw.b2i())
|
|
|
|
cv.put(COL_DONT_SHOW_TIMEOUT, dont_show_timeout.b2i())
|
|
|
|
cv.put(COL_NOTIFICATION_MENTION, notification_mention.b2i())
|
|
|
|
cv.put(COL_NOTIFICATION_BOOST, notification_boost.b2i())
|
|
|
|
cv.put(COL_NOTIFICATION_FAVOURITE, notification_favourite.b2i())
|
|
|
|
cv.put(COL_NOTIFICATION_FOLLOW, notification_follow.b2i())
|
2019-12-16 16:56:27 +01:00
|
|
|
cv.put(COL_NOTIFICATION_FOLLOW_REQUEST, notification_follow_request.b2i())
|
2018-08-30 08:51:32 +02:00
|
|
|
cv.put(COL_NOTIFICATION_REACTION, notification_reaction.b2i())
|
|
|
|
cv.put(COL_NOTIFICATION_VOTE, notification_vote.b2i())
|
2020-09-20 04:51:15 +02:00
|
|
|
cv.put(COL_NOTIFICATION_POST, notification_post.b2i())
|
2018-01-10 16:47:35 +01:00
|
|
|
|
|
|
|
cv.put(COL_CONFIRM_FOLLOW, confirm_follow.b2i())
|
|
|
|
cv.put(COL_CONFIRM_FOLLOW_LOCKED, confirm_follow_locked.b2i())
|
|
|
|
cv.put(COL_CONFIRM_UNFOLLOW, confirm_unfollow.b2i())
|
|
|
|
cv.put(COL_CONFIRM_POST, confirm_post.b2i())
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
cv.put(COL_SOUND_URI, sound_uri)
|
2018-08-04 20:56:51 +02:00
|
|
|
cv.put(COL_DEFAULT_TEXT, default_text)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
cv.put(COL_DEFAULT_SENSITIVE, default_sensitive.b2i())
|
|
|
|
cv.put(COL_EXPAND_CW, expand_cw.b2i())
|
2019-10-22 20:21:03 +02:00
|
|
|
cv.put(COL_MAX_TOOT_CHARS, max_toot_chars)
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
cv.putOrNull(COL_IMAGE_RESIZE,image_resize)
|
|
|
|
cv.putOrNull(COL_IMAGE_MAX_MEGABYTES, image_max_megabytes)
|
|
|
|
cv.putOrNull(COL_MOVIE_MAX_MEGABYTES, movie_max_megabytes)
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
// UIからは更新しない
|
|
|
|
// notification_tag
|
|
|
|
// register_key
|
|
|
|
|
2018-08-04 20:56:51 +02:00
|
|
|
App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2019-10-22 20:21:03 +02:00
|
|
|
// fun saveNotificationTag() {
|
|
|
|
// if(db_id == INVALID_DB_ID)
|
|
|
|
// throw RuntimeException("SavedAccount.saveNotificationTag missing db_id")
|
|
|
|
//
|
|
|
|
// val cv = ContentValues()
|
|
|
|
// cv.put(COL_NOTIFICATION_TAG, notification_tag)
|
|
|
|
//
|
|
|
|
// App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// fun saveRegisterKey() {
|
|
|
|
// if(db_id == INVALID_DB_ID)
|
|
|
|
// throw RuntimeException("SavedAccount.saveRegisterKey missing db_id")
|
|
|
|
//
|
|
|
|
// val cv = ContentValues()
|
|
|
|
// cv.put(COL_REGISTER_KEY, register_key)
|
|
|
|
// cv.put(COL_REGISTER_TIME, register_time)
|
|
|
|
//
|
|
|
|
// App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
|
|
|
// }
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// onResumeの時に設定を読み直す
|
|
|
|
fun reloadSetting(context : Context) {
|
2018-04-17 14:41:22 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
if(db_id == INVALID_DB_ID)
|
|
|
|
throw RuntimeException("SavedAccount.reloadSetting missing db_id")
|
2018-04-17 14:41:22 +02:00
|
|
|
|
|
|
|
// DBから削除されてるかもしれない
|
2018-01-04 19:52:25 +01:00
|
|
|
val b = loadAccount(context, db_id) ?: return
|
2018-04-17 14:41:22 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
this.visibility = b.visibility
|
|
|
|
this.confirm_boost = b.confirm_boost
|
2018-04-17 14:41:22 +02:00
|
|
|
this.confirm_favourite = b.confirm_favourite
|
2018-04-20 12:43:09 +02:00
|
|
|
this.confirm_unboost = b.confirm_unboost
|
|
|
|
this.confirm_unfavourite = b.confirm_unfavourite
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
this.dont_hide_nsfw = b.dont_hide_nsfw
|
|
|
|
this.dont_show_timeout = b.dont_show_timeout
|
|
|
|
this.token_info = b.token_info
|
2018-08-30 08:51:32 +02:00
|
|
|
this.notification_mention = b.notification_mention
|
2018-01-04 19:52:25 +01:00
|
|
|
this.notification_boost = b.notification_boost
|
|
|
|
this.notification_favourite = b.notification_favourite
|
|
|
|
this.notification_follow = b.notification_follow
|
2019-12-16 16:56:27 +01:00
|
|
|
this.notification_follow_request = b.notification_follow_request
|
2018-08-30 08:51:32 +02:00
|
|
|
this.notification_reaction = b.notification_reaction
|
|
|
|
this.notification_vote = b.notification_vote
|
2020-09-20 04:51:15 +02:00
|
|
|
this.notification_post = b.notification_post
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
this.notification_tag = b.notification_tag
|
2018-08-04 20:56:51 +02:00
|
|
|
this.default_text = b.default_text
|
2019-06-04 01:24:54 +02:00
|
|
|
this.default_sensitive = b.default_sensitive
|
|
|
|
this.expand_cw = b.expand_cw
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
this.sound_uri = b.sound_uri
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
this.image_resize = b.image_resize
|
|
|
|
this.image_max_megabytes = b.image_max_megabytes
|
|
|
|
this.movie_max_megabytes = b.movie_max_megabytes
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
fun getFullAcct(who : TootAccount?) = getFullAcct(who?.acct)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
fun isRemoteUser(who : TootAccount) : Boolean = ! isLocalUser(who.acct)
|
|
|
|
fun isLocalUser(who : TootAccount?) : Boolean = isLocalUser(who?.acct)
|
|
|
|
private fun isLocalUser(acct : Acct?) : Boolean {
|
2018-01-04 19:52:25 +01:00
|
|
|
acct ?: return false
|
2020-09-07 14:20:11 +02:00
|
|
|
return acct.host == null || acct.host == this.apDomain
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
|
|
|
// fun isRemoteUser(acct : String) : Boolean {
|
|
|
|
// return ! isLocalUser(acct)
|
|
|
|
// }
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
fun isMe(who : TootAccount?) : Boolean = isMe(who?.acct)
|
2020-09-29 19:44:56 +02:00
|
|
|
// fun isMe(who_acct : String) : Boolean = isMe(Acct.parse(who_acct))
|
|
|
|
|
|
|
|
fun isMe(who_acct : Acct?) : Boolean {
|
|
|
|
who_acct ?: return false
|
|
|
|
if(who_acct.username != this.acct.username) return false
|
2020-02-02 15:19:57 +01:00
|
|
|
return who_acct.host == null || who_acct.host == this.acct.host
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2020-09-29 19:44:56 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
fun supplyBaseUrl(url : String?) : String? {
|
|
|
|
return when {
|
|
|
|
url == null || url.isEmpty() -> return null
|
2020-09-07 14:20:11 +02:00
|
|
|
url[0] == '/' -> "https://${apiHost.ascii}$url"
|
2018-01-04 19:52:25 +01:00
|
|
|
else -> url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-07 14:20:11 +02:00
|
|
|
fun isNicoru(account : TootAccount?) : Boolean = account?.apiHost == Host.FRIENDS_NICO
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-04-17 14:41:22 +02:00
|
|
|
companion object : TableCompanion {
|
2020-09-29 19:44:56 +02:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
private val log = LogCategory("SavedAccount")
|
|
|
|
|
|
|
|
const val table = "access_info"
|
|
|
|
|
|
|
|
private const val COL_ID = BaseColumns._ID
|
|
|
|
private const val COL_HOST = "h"
|
2020-09-07 14:20:11 +02:00
|
|
|
private const val COL_DOMAIN = "d"
|
2018-01-04 19:52:25 +01:00
|
|
|
private const val COL_USER = "u"
|
|
|
|
private const val COL_ACCOUNT = "a"
|
|
|
|
private const val COL_TOKEN = "t"
|
|
|
|
|
|
|
|
private const val COL_VISIBILITY = "visibility"
|
|
|
|
private const val COL_CONFIRM_BOOST = "confirm_boost"
|
|
|
|
private const val COL_DONT_HIDE_NSFW = "dont_hide_nsfw"
|
2019-12-17 18:58:49 +01:00
|
|
|
|
|
|
|
private const val COL_NOTIFICATION_MENTION = "notification_mention" // スキーマ2
|
|
|
|
private const val COL_NOTIFICATION_BOOST = "notification_boost" // スキーマ2
|
|
|
|
private const val COL_NOTIFICATION_FAVOURITE = "notification_favourite" // スキーマ2
|
|
|
|
private const val COL_NOTIFICATION_FOLLOW = "notification_follow" // スキーマ2
|
|
|
|
private const val COL_NOTIFICATION_FOLLOW_REQUEST = "notification_follow_request" // スキーマ44
|
|
|
|
private const val COL_NOTIFICATION_REACTION = "notification_reaction" // スキーマ33
|
|
|
|
private const val COL_NOTIFICATION_VOTE = "notification_vote" // スキーマ33
|
2020-09-20 04:51:15 +02:00
|
|
|
private const val COL_NOTIFICATION_POST = "notification_post" // スキーマ57
|
2019-12-17 18:58:49 +01:00
|
|
|
|
|
|
|
private const val COL_CONFIRM_FOLLOW = "confirm_follow" // スキーマ10
|
|
|
|
private const val COL_CONFIRM_FOLLOW_LOCKED = "confirm_follow_locked" // スキーマ10
|
|
|
|
private const val COL_CONFIRM_UNFOLLOW = "confirm_unfollow" // スキーマ10
|
|
|
|
private const val COL_CONFIRM_POST = "confirm_post" // スキーマ10
|
|
|
|
private const val COL_CONFIRM_FAVOURITE = "confirm_favourite" // スキーマ23
|
|
|
|
private const val COL_CONFIRM_UNBOOST = "confirm_unboost" // スキーマ24
|
|
|
|
private const val COL_CONFIRM_UNFAVOURITE = "confirm_unfavourite" // スキーマ24
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// スキーマ13から
|
|
|
|
const val COL_NOTIFICATION_TAG = "notification_server"
|
|
|
|
|
|
|
|
// スキーマ14から
|
|
|
|
const val COL_REGISTER_KEY = "register_key"
|
|
|
|
const val COL_REGISTER_TIME = "register_time"
|
|
|
|
|
|
|
|
// スキーマ16から
|
|
|
|
private const val COL_SOUND_URI = "sound_uri"
|
|
|
|
|
|
|
|
// スキーマ18から
|
|
|
|
private const val COL_DONT_SHOW_TIMEOUT = "dont_show_timeout"
|
|
|
|
|
2018-08-04 20:56:51 +02:00
|
|
|
// スキーマ27から
|
|
|
|
private const val COL_DEFAULT_TEXT = "default_text"
|
|
|
|
|
2018-08-16 21:58:30 +02:00
|
|
|
// スキーマ28から
|
2019-04-25 04:06:41 +02:00
|
|
|
private const val COL_MISSKEY_VERSION = "is_misskey" // カラム名がおかしいのは、昔はboolean扱いだったから
|
|
|
|
// 0: not misskey
|
|
|
|
// 1: old(v10) misskey
|
|
|
|
// 11: misskey v11
|
2018-08-20 19:37:42 +02:00
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
private const val COL_DEFAULT_SENSITIVE = "default_sensitive"
|
|
|
|
private const val COL_EXPAND_CW = "expand_cw"
|
2019-08-12 05:32:39 +02:00
|
|
|
private const val COL_MAX_TOOT_CHARS = "max_toot_chars"
|
2018-08-30 08:51:32 +02:00
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
private const val COL_LAST_NOTIFICATION_ERROR = "last_notification_error" // スキーマ42
|
|
|
|
private const val COL_LAST_SUBSCRIPTION_ERROR = "last_subscription_error" // スキーマ45
|
2019-12-18 08:52:55 +01:00
|
|
|
private const val COL_LAST_PUSH_ENDPOINT = "last_push_endpoint" // スキーマ46
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
private const val COL_IMAGE_RESIZE = "image_resize" // スキーマ59
|
|
|
|
private const val COL_IMAGE_MAX_MEGABYTES = "image_max_megabytes" // スキーマ59
|
|
|
|
private const val COL_MOVIE_MAX_MEGABYTES = "movie_max_megabytes" // スキーマ59
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
/////////////////////////////////
|
|
|
|
// login information
|
|
|
|
const val INVALID_DB_ID = - 1L
|
|
|
|
|
|
|
|
// アプリデータのインポート時に呼ばれる
|
|
|
|
fun onDBDelete(db : SQLiteDatabase) {
|
|
|
|
try {
|
2018-04-17 14:41:22 +02:00
|
|
|
db.execSQL("drop table if exists $table")
|
2018-01-04 19:52:25 +01:00
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-16 15:13:34 +01:00
|
|
|
override fun onDBCreate(db : SQLiteDatabase) {
|
2018-01-04 19:52:25 +01:00
|
|
|
db.execSQL(
|
2018-04-17 14:41:22 +02:00
|
|
|
"create table if not exists $table"
|
|
|
|
+ "($COL_ID INTEGER PRIMARY KEY"
|
|
|
|
+ ",$COL_USER text not null"
|
|
|
|
+ ",$COL_HOST text not null"
|
|
|
|
+ ",$COL_ACCOUNT text not null"
|
|
|
|
+ ",$COL_TOKEN text not null"
|
|
|
|
+ ",$COL_VISIBILITY text"
|
|
|
|
+ ",$COL_CONFIRM_BOOST integer default 1"
|
|
|
|
+ ",$COL_DONT_HIDE_NSFW integer default 0"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// 以下はDBスキーマ2で追加
|
2018-04-17 14:41:22 +02:00
|
|
|
+ ",$COL_NOTIFICATION_MENTION integer default 1"
|
|
|
|
+ ",$COL_NOTIFICATION_BOOST integer default 1"
|
|
|
|
+ ",$COL_NOTIFICATION_FAVOURITE integer default 1"
|
|
|
|
+ ",$COL_NOTIFICATION_FOLLOW integer default 1"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// 以下はDBスキーマ10で更新
|
2018-04-17 14:41:22 +02:00
|
|
|
+ ",$COL_CONFIRM_FOLLOW integer default 1"
|
|
|
|
+ ",$COL_CONFIRM_FOLLOW_LOCKED integer default 1"
|
|
|
|
+ ",$COL_CONFIRM_UNFOLLOW integer default 1"
|
|
|
|
+ ",$COL_CONFIRM_POST integer default 1"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// 以下はDBスキーマ13で更新
|
2018-04-17 14:41:22 +02:00
|
|
|
+ ",$COL_NOTIFICATION_TAG text default ''"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// 以下はDBスキーマ14で更新
|
2018-04-17 14:41:22 +02:00
|
|
|
+ ",$COL_REGISTER_KEY text default ''"
|
|
|
|
+ ",$COL_REGISTER_TIME integer default 0"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// 以下はDBスキーマ16で更新
|
2018-04-17 14:41:22 +02:00
|
|
|
+ ",$COL_SOUND_URI text default ''"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// 以下はDBスキーマ18で更新
|
2018-04-17 14:41:22 +02:00
|
|
|
+ ",$COL_DONT_SHOW_TIMEOUT integer default 0"
|
|
|
|
|
|
|
|
// 以下はDBスキーマ23で更新
|
|
|
|
+ ",$COL_CONFIRM_FAVOURITE integer default 1"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-04-20 12:43:09 +02:00
|
|
|
// 以下はDBスキーマ24で更新
|
|
|
|
+ ",$COL_CONFIRM_UNBOOST integer default 1"
|
|
|
|
+ ",$COL_CONFIRM_UNFAVOURITE integer default 1"
|
|
|
|
|
2018-08-04 20:56:51 +02:00
|
|
|
// 以下はDBスキーマ27で更新
|
|
|
|
+ ",$COL_DEFAULT_TEXT text default ''"
|
|
|
|
|
2018-08-16 21:58:30 +02:00
|
|
|
// 以下はDBスキーマ28で更新
|
2019-04-25 04:06:41 +02:00
|
|
|
+ ",$COL_MISSKEY_VERSION integer default 0"
|
2018-08-30 08:51:32 +02:00
|
|
|
|
|
|
|
// スキーマ33から
|
|
|
|
+ ",$COL_NOTIFICATION_REACTION integer default 1"
|
|
|
|
+ ",$COL_NOTIFICATION_VOTE integer default 1"
|
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
// スキーマ37から
|
|
|
|
+ ",$COL_DEFAULT_SENSITIVE integer default 0"
|
|
|
|
+ ",$COL_EXPAND_CW integer default 0"
|
|
|
|
|
2019-08-12 05:32:39 +02:00
|
|
|
// スキーマ39から
|
|
|
|
+ ",$COL_MAX_TOOT_CHARS integer default 0"
|
|
|
|
|
2019-10-22 20:21:03 +02:00
|
|
|
// スキーマ42から
|
|
|
|
+ ",$COL_LAST_NOTIFICATION_ERROR text"
|
|
|
|
|
2019-12-16 16:56:27 +01:00
|
|
|
// スキーマ44から
|
|
|
|
+ ",$COL_NOTIFICATION_FOLLOW_REQUEST integer default 1"
|
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
// スキーマ45から
|
|
|
|
+ ",$COL_LAST_SUBSCRIPTION_ERROR text"
|
|
|
|
|
2019-12-18 08:52:55 +01:00
|
|
|
// スキーマ46から
|
|
|
|
+ ",$COL_LAST_PUSH_ENDPOINT text"
|
|
|
|
|
2020-09-20 04:51:15 +02:00
|
|
|
// スキーマ56から
|
2020-09-07 14:20:11 +02:00
|
|
|
+ ",$COL_DOMAIN text"
|
|
|
|
|
2020-09-20 04:51:15 +02:00
|
|
|
// スキーマ57から
|
|
|
|
+ ",$COL_NOTIFICATION_POST integer default 1"
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
// スキーマ59から
|
|
|
|
+ ",$COL_IMAGE_RESIZE text default null"
|
|
|
|
+ ",$COL_IMAGE_MAX_MEGABYTES text default null"
|
|
|
|
+ ",$COL_MOVIE_MAX_MEGABYTES text default null"
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
+ ")"
|
|
|
|
)
|
2018-04-17 14:41:22 +02:00
|
|
|
db.execSQL("create index if not exists ${table}_user on ${table}(u)")
|
|
|
|
db.execSQL("create index if not exists ${table}_host on ${table}(h,u)")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2018-03-16 15:13:34 +01:00
|
|
|
override fun onDBUpgrade(db : SQLiteDatabase, oldVersion : Int, newVersion : Int) {
|
2018-01-04 19:52:25 +01:00
|
|
|
if(oldVersion < 2 && newVersion >= 2) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column notification_mention integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column notification_boost integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column notification_favourite integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column notification_follow integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(oldVersion < 10 && newVersion >= 10) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_CONFIRM_FOLLOW integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_CONFIRM_FOLLOW_LOCKED integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_CONFIRM_UNFOLLOW integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_CONFIRM_POST integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(oldVersion < 13 && newVersion >= 13) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_NOTIFICATION_TAG text default ''")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(oldVersion < 14 && newVersion >= 14) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_REGISTER_KEY text default ''")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_REGISTER_TIME integer default 0")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(oldVersion < 16 && newVersion >= 16) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_SOUND_URI text default ''")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if(oldVersion < 18 && newVersion >= 18) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_DONT_SHOW_TIMEOUT integer default 0")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-04-17 14:41:22 +02:00
|
|
|
if(oldVersion < 23 && newVersion >= 23) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_CONFIRM_FAVOURITE integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-04-20 12:43:09 +02:00
|
|
|
if(oldVersion < 24 && newVersion >= 24) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_CONFIRM_UNFAVOURITE integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_CONFIRM_UNBOOST integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-08-04 20:56:51 +02:00
|
|
|
if(oldVersion < 27 && newVersion >= 27) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_DEFAULT_TEXT text default ''")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-08-16 21:58:30 +02:00
|
|
|
if(oldVersion < 28 && newVersion >= 28) {
|
|
|
|
try {
|
2019-04-25 04:06:41 +02:00
|
|
|
db.execSQL("alter table $table add column $COL_MISSKEY_VERSION integer default 0")
|
2018-08-16 21:58:30 +02:00
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 19:44:56 +02:00
|
|
|
|
2018-08-30 08:51:32 +02:00
|
|
|
if(oldVersion < 33 && newVersion >= 33) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_NOTIFICATION_REACTION integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_NOTIFICATION_VOTE integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
2019-06-04 01:24:54 +02:00
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 19:44:56 +02:00
|
|
|
|
2019-06-04 01:24:54 +02:00
|
|
|
if(oldVersion < 38 && newVersion >= 38) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_DEFAULT_SENSITIVE integer default 0")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_EXPAND_CW integer default 0")
|
|
|
|
} catch(ex : Throwable) {
|
2018-08-30 08:51:32 +02:00
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-08-12 05:32:39 +02:00
|
|
|
|
|
|
|
if(oldVersion < 39 && newVersion >= 39) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_MAX_TOOT_CHARS integer default 0")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2019-10-22 20:21:03 +02:00
|
|
|
|
|
|
|
if(oldVersion < 42 && newVersion >= 42) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_LAST_NOTIFICATION_ERROR text")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2019-12-16 16:56:27 +01:00
|
|
|
|
|
|
|
if(oldVersion < 44 && newVersion >= 44) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_NOTIFICATION_FOLLOW_REQUEST integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2019-12-17 18:58:49 +01:00
|
|
|
|
|
|
|
if(oldVersion < 45 && newVersion >= 45) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_LAST_SUBSCRIPTION_ERROR text")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2019-12-18 08:52:55 +01:00
|
|
|
if(oldVersion < 46 && newVersion >= 46) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_LAST_PUSH_ENDPOINT text")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2020-09-07 14:20:11 +02:00
|
|
|
if(oldVersion < 56 && newVersion >= 56) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_DOMAIN text")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2020-09-20 04:51:15 +02:00
|
|
|
if(oldVersion < 57 && newVersion >= 57) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_NOTIFICATION_POST integer default 1")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-02-09 23:25:06 +01:00
|
|
|
if(oldVersion < 59 && newVersion >= 59) {
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_IMAGE_RESIZE text default null")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_IMAGE_MAX_MEGABYTES text default null")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
db.execSQL("alter table $table add column $COL_MOVIE_MAX_MEGABYTES text default null")
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
val defaultResizeConfig = ResizeConfig(ResizeType.LongSide, 1280)
|
|
|
|
|
|
|
|
internal val resizeConfigList = arrayOf(
|
|
|
|
ResizeConfig(ResizeType.None, 0),
|
|
|
|
|
|
|
|
ResizeConfig(ResizeType.LongSide, 640),
|
|
|
|
ResizeConfig(ResizeType.LongSide, 800),
|
|
|
|
ResizeConfig(ResizeType.LongSide, 1024),
|
|
|
|
ResizeConfig(ResizeType.LongSide, 1280),
|
|
|
|
ResizeConfig(ResizeType.LongSide, 1600),
|
|
|
|
ResizeConfig(ResizeType.LongSide, 2048),
|
|
|
|
|
|
|
|
ResizeConfig(ResizeType.SquarePixel, 640),
|
|
|
|
ResizeConfig(ResizeType.SquarePixel, 800),
|
|
|
|
ResizeConfig(ResizeType.SquarePixel, 1024),
|
|
|
|
ResizeConfig(ResizeType.SquarePixel, 1280),
|
|
|
|
ResizeConfig(ResizeType.SquarePixel, 1440, R.string.size_1920_1080),
|
|
|
|
ResizeConfig(ResizeType.SquarePixel, 1600),
|
|
|
|
ResizeConfig(ResizeType.SquarePixel, 2048)
|
|
|
|
)
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
// 横断検索用の、何とも紐ついていないアカウント
|
|
|
|
// 保存しない。
|
|
|
|
val na : SavedAccount by lazy {
|
2018-01-10 16:47:35 +01:00
|
|
|
val dst = SavedAccount(- 1L, "?@?")
|
2018-01-04 19:52:25 +01:00
|
|
|
dst.notification_follow = false
|
2019-12-16 16:56:27 +01:00
|
|
|
dst.notification_follow_request = false
|
2018-01-04 19:52:25 +01:00
|
|
|
dst.notification_favourite = false
|
|
|
|
dst.notification_boost = false
|
|
|
|
dst.notification_mention = false
|
2018-08-30 08:51:32 +02:00
|
|
|
dst.notification_reaction = false
|
|
|
|
dst.notification_vote = false
|
2020-09-20 04:51:15 +02:00
|
|
|
dst.notification_post = false
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
dst
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun parse(context : Context, cursor : Cursor) : SavedAccount? {
|
|
|
|
return try {
|
|
|
|
SavedAccount(context, cursor)
|
2018-01-10 16:47:35 +01:00
|
|
|
} catch(ex : Throwable) {
|
2018-01-04 19:52:25 +01:00
|
|
|
log.trace(ex)
|
2018-01-10 16:47:35 +01:00
|
|
|
log.e(ex, "parse failed.")
|
2018-01-04 19:52:25 +01:00
|
|
|
null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun insert(
|
|
|
|
acct : String,
|
2020-09-07 14:20:11 +02:00
|
|
|
host : String,
|
2020-09-29 19:44:56 +02:00
|
|
|
domain : String?,
|
2020-01-07 09:03:32 +01:00
|
|
|
account : JsonObject,
|
|
|
|
token : JsonObject,
|
2019-04-25 04:06:41 +02:00
|
|
|
misskeyVersion : Int = 0
|
2018-01-04 19:52:25 +01:00
|
|
|
) : Long {
|
|
|
|
try {
|
|
|
|
val cv = ContentValues()
|
|
|
|
cv.put(COL_USER, acct)
|
2020-09-07 14:20:11 +02:00
|
|
|
cv.put(COL_HOST, host)
|
2020-09-29 19:44:56 +02:00
|
|
|
cv.putOrNull(COL_DOMAIN, domain)
|
2018-01-04 19:52:25 +01:00
|
|
|
cv.put(COL_ACCOUNT, account.toString())
|
|
|
|
cv.put(COL_TOKEN, token.toString())
|
2019-04-25 04:06:41 +02:00
|
|
|
cv.put(COL_MISSKEY_VERSION, misskeyVersion)
|
2018-01-04 19:52:25 +01:00
|
|
|
return App1.database.insert(table, null, cv)
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
throw RuntimeException("SavedAccount.insert failed.", ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-25 10:04:34 +02:00
|
|
|
private const val REGISTER_KEY_UNREGISTERED = "unregistered"
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
fun clearRegistrationCache() {
|
|
|
|
val cv = ContentValues()
|
|
|
|
cv.put(COL_REGISTER_KEY, REGISTER_KEY_UNREGISTERED)
|
|
|
|
cv.put(COL_REGISTER_TIME, 0L)
|
|
|
|
App1.database.update(table, cv, null, null)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun loadAccount(context : Context, db_id : Long) : SavedAccount? {
|
|
|
|
try {
|
2018-01-21 17:47:13 +01:00
|
|
|
App1.database.query(
|
|
|
|
table,
|
|
|
|
null,
|
2018-08-04 20:56:51 +02:00
|
|
|
"$COL_ID=?",
|
2018-01-21 17:47:13 +01:00
|
|
|
arrayOf(db_id.toString()),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
)
|
2018-01-10 16:47:35 +01:00
|
|
|
.use { cursor ->
|
2018-01-04 19:52:25 +01:00
|
|
|
if(cursor.moveToFirst()) {
|
|
|
|
return parse(context, cursor)
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
log.e("moveToFirst failed. db_id=$db_id")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "loadAccount failed.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
fun loadAccountList(context : Context) : ArrayList<SavedAccount> {
|
|
|
|
val result = ArrayList<SavedAccount>()
|
|
|
|
try {
|
2019-08-25 10:04:34 +02:00
|
|
|
App1.database.query(
|
|
|
|
table,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
.use { cursor ->
|
|
|
|
while(cursor.moveToNext()) {
|
|
|
|
val a = parse(context, cursor)
|
2018-01-10 16:47:35 +01:00
|
|
|
if(a != null) result.add(a)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "loadAccountList failed.")
|
2020-09-29 19:44:56 +02:00
|
|
|
context.showToast(true, ex.withCaption("(SubwayTooter) broken in-app database?"))
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
fun loadByTag(context : Context, tag : String) : ArrayList<SavedAccount> {
|
|
|
|
val result = ArrayList<SavedAccount>()
|
|
|
|
try {
|
2018-01-21 17:47:13 +01:00
|
|
|
App1.database.query(
|
|
|
|
table,
|
|
|
|
null,
|
2018-08-04 20:56:51 +02:00
|
|
|
"$COL_NOTIFICATION_TAG=?",
|
2018-01-21 17:47:13 +01:00
|
|
|
arrayOf(tag),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
)
|
2018-01-10 16:47:35 +01:00
|
|
|
.use { cursor ->
|
2018-01-04 19:52:25 +01:00
|
|
|
while(cursor.moveToNext()) {
|
|
|
|
val a = parse(context, cursor)
|
2018-01-10 16:47:35 +01:00
|
|
|
if(a != null) result.add(a)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "loadByTag failed.")
|
|
|
|
throw RuntimeException("SavedAccount.loadByTag failed.", ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
fun loadAccountByAcct(context : Context, full_acct : String) : SavedAccount? {
|
|
|
|
try {
|
2018-01-21 17:47:13 +01:00
|
|
|
App1.database.query(
|
|
|
|
table,
|
|
|
|
null,
|
2018-08-04 20:56:51 +02:00
|
|
|
"$COL_USER=?",
|
2018-01-21 17:47:13 +01:00
|
|
|
arrayOf(full_acct),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
)
|
2018-01-10 16:47:35 +01:00
|
|
|
.use { cursor ->
|
2018-01-04 19:52:25 +01:00
|
|
|
if(cursor.moveToNext()) {
|
|
|
|
return parse(context, cursor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "loadAccountByAcct failed.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
fun hasRealAccount() : Boolean {
|
|
|
|
try {
|
2018-01-21 17:47:13 +01:00
|
|
|
App1.database.query(
|
|
|
|
table,
|
|
|
|
null,
|
2018-08-04 20:56:51 +02:00
|
|
|
"$COL_USER NOT LIKE '?@%'",
|
2018-01-21 17:47:13 +01:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
"1"
|
|
|
|
)
|
2018-01-10 16:47:35 +01:00
|
|
|
.use { cursor ->
|
2018-01-04 19:52:25 +01:00
|
|
|
if(cursor.moveToNext()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "hasNonPseudoAccount failed.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
val count : Long
|
|
|
|
get() {
|
|
|
|
try {
|
|
|
|
App1.database.query(table, arrayOf("count(*)"), null, null, null, null, null)
|
2018-01-10 16:47:35 +01:00
|
|
|
.use { cursor ->
|
2018-01-04 19:52:25 +01:00
|
|
|
if(cursor.moveToNext()) {
|
|
|
|
return cursor.getLong(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "getCount failed.")
|
|
|
|
throw RuntimeException("SavedAccount.getCount failed.", ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0L
|
|
|
|
}
|
|
|
|
|
2020-09-29 19:44:56 +02:00
|
|
|
fun isNicoru(acct : Acct) : Boolean {
|
2020-02-02 15:19:57 +01:00
|
|
|
return acct.host == Host.FRIENDS_NICO
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2020-09-29 19:44:56 +02:00
|
|
|
// private fun charAtLower(src : CharSequence, pos : Int) : Char {
|
|
|
|
// val c = src[pos]
|
|
|
|
// return if(c >= 'a' && c <= 'z') c - ('a' - 'A') else c
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Suppress("SameParameterValue")
|
|
|
|
// private fun host_match(
|
|
|
|
// a : CharSequence,
|
|
|
|
// a_startArg : Int,
|
|
|
|
// b : CharSequence,
|
|
|
|
// b_startArg : Int
|
|
|
|
// ) : Boolean {
|
|
|
|
// var a_start = a_startArg
|
|
|
|
// var b_start = b_startArg
|
|
|
|
//
|
|
|
|
// val a_end = a.length
|
|
|
|
// val b_end = b.length
|
|
|
|
//
|
|
|
|
// var a_remain = a_end - a_start
|
|
|
|
// val b_remain = b_end - b_start
|
|
|
|
//
|
|
|
|
// // 文字数が違う
|
|
|
|
// if(a_remain != b_remain) return false
|
|
|
|
//
|
|
|
|
// // 文字数がゼロ
|
|
|
|
// if(a_remain <= 0) return true
|
|
|
|
//
|
|
|
|
// // 末尾の文字が違う
|
|
|
|
// if(charAtLower(a, a_end - 1) != charAtLower(b, b_end - 1)) return false
|
|
|
|
//
|
|
|
|
// // 先頭からチェック
|
|
|
|
// while(a_remain -- > 0) {
|
|
|
|
// if(charAtLower(a, a_start ++) != charAtLower(b, b_start ++)) return false
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return true
|
|
|
|
// }
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
private val account_comparator = Comparator<SavedAccount> { a, b ->
|
|
|
|
var i : Int
|
|
|
|
|
|
|
|
// NA > !NA
|
2018-01-10 16:47:35 +01:00
|
|
|
i = a.isNA.b2i() - b.isNA.b2i()
|
2018-01-04 19:52:25 +01:00
|
|
|
if(i != 0) return@Comparator i
|
|
|
|
|
|
|
|
// pseudo > real
|
2018-01-10 16:47:35 +01:00
|
|
|
i = a.isPseudo.b2i() - b.isPseudo.b2i()
|
2018-01-04 19:52:25 +01:00
|
|
|
if(i != 0) return@Comparator i
|
|
|
|
|
2020-02-01 14:26:57 +01:00
|
|
|
val sa = AcctColor.getNickname(a)
|
|
|
|
val sb = AcctColor.getNickname(b)
|
2018-01-04 19:52:25 +01:00
|
|
|
sa.compareTo(sb, ignoreCase = true)
|
|
|
|
}
|
|
|
|
|
2018-08-20 02:07:55 +02:00
|
|
|
fun sort(account_list : MutableList<SavedAccount>) {
|
2018-01-04 19:52:25 +01:00
|
|
|
Collections.sort(account_list, account_comparator)
|
|
|
|
}
|
2018-01-10 16:47:35 +01:00
|
|
|
|
2019-10-22 20:21:03 +02:00
|
|
|
fun sweepBuggieData() {
|
2019-08-25 10:04:34 +02:00
|
|
|
// https://github.com/tateisu/SubwayTooter/issues/107
|
|
|
|
// COL_ACCOUNTの内容がおかしければ削除する
|
2019-10-22 20:21:03 +02:00
|
|
|
|
2019-08-25 10:04:34 +02:00
|
|
|
val list = ArrayList<Long>()
|
|
|
|
try {
|
|
|
|
App1.database.query(
|
|
|
|
table,
|
|
|
|
null,
|
|
|
|
"$COL_ACCOUNT like ?",
|
|
|
|
arrayOf("jp.juggler.subwaytooter.api.entity.TootAccount@%"),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
).use { cursor ->
|
|
|
|
while(cursor.moveToNext()) {
|
|
|
|
list.add(cursor.getLong(COL_ID))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "sweepBuggieData failed.")
|
|
|
|
}
|
2019-10-22 20:21:03 +02:00
|
|
|
|
|
|
|
list.forEach {
|
2019-08-25 10:04:34 +02:00
|
|
|
try {
|
2019-10-22 20:21:03 +02:00
|
|
|
App1.database.delete(table, "$COL_ID=?", arrayOf(it.toString()))
|
2019-08-25 10:04:34 +02:00
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
log.e(ex, "sweepBuggieData failed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fun getAccessToken() : String? {
|
2020-01-08 04:23:45 +01:00
|
|
|
return token_info?.string("access_token")
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2018-08-30 08:51:32 +02:00
|
|
|
|
2018-08-25 02:29:24 +02:00
|
|
|
val misskeyApiToken : String?
|
2020-01-08 04:23:45 +01:00
|
|
|
get() = token_info?.string(TootApiClient.KEY_API_KEY_MISSKEY)
|
2018-08-30 08:51:32 +02:00
|
|
|
|
2020-01-07 09:03:32 +01:00
|
|
|
fun putMisskeyApiToken(params : JsonObject = JsonObject()) : JsonObject {
|
2018-08-25 02:29:24 +02:00
|
|
|
val apiKey = misskeyApiToken
|
2020-01-07 09:03:32 +01:00
|
|
|
if(apiKey?.isNotEmpty() == true) params["i"] = apiKey
|
2018-08-20 02:07:55 +02:00
|
|
|
return params
|
|
|
|
}
|
|
|
|
|
2018-08-30 08:51:32 +02:00
|
|
|
fun canNotificationShowing(type : String?) = when(type) {
|
|
|
|
|
|
|
|
TootNotification.TYPE_MENTION,
|
|
|
|
TootNotification.TYPE_REPLY -> notification_mention
|
|
|
|
|
|
|
|
TootNotification.TYPE_REBLOG,
|
|
|
|
TootNotification.TYPE_RENOTE,
|
|
|
|
TootNotification.TYPE_QUOTE -> notification_boost
|
|
|
|
|
|
|
|
TootNotification.TYPE_FAVOURITE -> notification_favourite
|
|
|
|
|
|
|
|
TootNotification.TYPE_FOLLOW,
|
|
|
|
TootNotification.TYPE_UNFOLLOW -> notification_follow
|
|
|
|
|
2019-12-16 16:56:27 +01:00
|
|
|
TootNotification.TYPE_FOLLOW_REQUEST,
|
2020-02-16 09:13:11 +01:00
|
|
|
TootNotification.TYPE_FOLLOW_REQUEST_MISSKEY,
|
|
|
|
TootNotification.TYPE_FOLLOW_REQUEST_ACCEPTED_MISSKEY -> notification_follow_request
|
2019-12-16 16:56:27 +01:00
|
|
|
|
2018-08-30 08:51:32 +02:00
|
|
|
TootNotification.TYPE_REACTION -> notification_reaction
|
|
|
|
|
2020-02-16 09:13:11 +01:00
|
|
|
TootNotification.TYPE_VOTE,
|
|
|
|
TootNotification.TYPE_POLL,
|
|
|
|
TootNotification.TYPE_POLL_VOTE_MISSKEY -> notification_vote
|
2018-08-30 08:51:32 +02:00
|
|
|
|
2020-09-20 04:51:15 +02:00
|
|
|
TootNotification.TYPE_STATUS -> notification_post
|
|
|
|
|
2018-08-30 08:51:32 +02:00
|
|
|
else -> false
|
|
|
|
}
|
|
|
|
|
2019-10-22 20:21:03 +02:00
|
|
|
val isConfirmed : Boolean
|
|
|
|
get() {
|
2018-12-25 12:54:41 +01:00
|
|
|
val myId = this.loginAccount?.id
|
2019-01-29 02:56:24 +01:00
|
|
|
return myId != EntityId.CONFIRMING
|
2018-12-25 12:54:41 +01:00
|
|
|
}
|
|
|
|
|
2020-12-08 21:24:42 +01:00
|
|
|
suspend fun checkConfirmed(context : Context, client : TootApiClient) : TootApiResult? {
|
2018-12-25 12:54:41 +01:00
|
|
|
try {
|
|
|
|
val myId = this.loginAccount?.id
|
2019-10-22 20:21:03 +02:00
|
|
|
if(db_id != INVALID_DB_ID && myId == EntityId.CONFIRMING) {
|
2018-12-25 12:54:41 +01:00
|
|
|
val accessToken = getAccessToken()
|
|
|
|
if(accessToken != null) {
|
2019-04-25 04:06:41 +02:00
|
|
|
val result = client.getUserCredential(accessToken)
|
2019-10-22 20:21:03 +02:00
|
|
|
if(result == null || result.error != null) return result
|
2018-12-25 12:54:41 +01:00
|
|
|
val ta = TootParser(context, this).account(result.jsonObject)
|
|
|
|
if(ta != null) {
|
|
|
|
this.loginAccount = ta
|
|
|
|
val cv = ContentValues()
|
2019-10-22 20:21:03 +02:00
|
|
|
cv.put(COL_ACCOUNT, result.jsonObject.toString())
|
2018-12-25 12:54:41 +01:00
|
|
|
App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
|
|
|
PollingWorker.queueUpdateNotification(context)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TootApiResult()
|
2019-10-22 20:21:03 +02:00
|
|
|
} catch(ex : Throwable) {
|
2018-12-25 12:54:41 +01:00
|
|
|
log.trace(ex)
|
|
|
|
return TootApiResult(ex.withCaption("account confirmation failed."))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
fun updateNotificationError(text : String?) {
|
2019-12-18 08:52:55 +01:00
|
|
|
this.last_notification_error = text
|
2020-09-29 19:44:56 +02:00
|
|
|
if(db_id != INVALID_DB_ID) {
|
2019-12-18 08:52:55 +01:00
|
|
|
val cv = ContentValues()
|
|
|
|
when(text) {
|
|
|
|
null -> cv.putNull(COL_LAST_NOTIFICATION_ERROR)
|
|
|
|
else -> cv.put(COL_LAST_NOTIFICATION_ERROR, text)
|
|
|
|
}
|
|
|
|
App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
2019-10-22 20:21:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 18:58:49 +01:00
|
|
|
fun updateSubscriptionError(text : String?) {
|
2019-12-18 08:52:55 +01:00
|
|
|
this.last_subscription_error = text
|
2020-09-29 19:44:56 +02:00
|
|
|
if(db_id != INVALID_DB_ID) {
|
2019-12-18 08:52:55 +01:00
|
|
|
val cv = ContentValues()
|
|
|
|
when(text) {
|
|
|
|
null -> cv.putNull(COL_LAST_SUBSCRIPTION_ERROR)
|
|
|
|
else -> cv.put(COL_LAST_SUBSCRIPTION_ERROR, text)
|
|
|
|
}
|
|
|
|
App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun updateLastPushEndpoint(text : String?) {
|
|
|
|
this.last_push_endpoint = text
|
2020-09-29 19:44:56 +02:00
|
|
|
if(db_id != INVALID_DB_ID) {
|
2019-12-18 08:52:55 +01:00
|
|
|
val cv = ContentValues()
|
|
|
|
when(text) {
|
|
|
|
null -> cv.putNull(COL_LAST_PUSH_ENDPOINT)
|
|
|
|
else -> cv.put(COL_LAST_PUSH_ENDPOINT, text)
|
|
|
|
}
|
|
|
|
App1.database.update(table, cv, "$COL_ID=?", arrayOf(db_id.toString()))
|
2019-12-17 18:58:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 19:28:16 +01:00
|
|
|
override fun equals(other : Any?) : Boolean =
|
|
|
|
when(other) {
|
2020-02-02 15:19:57 +01:00
|
|
|
is SavedAccount -> acct == other.acct
|
2020-02-01 19:28:16 +01:00
|
|
|
else -> false
|
|
|
|
}
|
|
|
|
|
2020-02-02 15:19:57 +01:00
|
|
|
override fun hashCode() : Int = acct.hashCode()
|
2021-02-09 23:25:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
fun getResizeConfig() =
|
|
|
|
resizeConfigList.find { it.spec == this.image_resize } ?: defaultResizeConfig
|
|
|
|
|
|
|
|
fun getMovieMaxBytes(ti:TootInstance) = 1000000 * max(
|
|
|
|
1,
|
|
|
|
this.movie_max_megabytes?.toIntOrNull()
|
|
|
|
?: if( ti.instanceType == TootInstance.InstanceType.Pixelfed) 15 else 40
|
|
|
|
)
|
|
|
|
|
|
|
|
fun getImageMaxBytes(ti:TootInstance) = 1000000 * max(
|
|
|
|
1,
|
|
|
|
this.image_max_megabytes?.toIntOrNull()
|
|
|
|
?: if( ti.instanceType == TootInstance.InstanceType.Pixelfed) 15 else 8
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|