Backport #1038 : Mastodon's API doesn't have `/api/direct_messages.json`

This commit is contained in:
Michel Roux 2020-04-20 19:28:01 +02:00
parent b52e511b9a
commit d2e98524ac
2 changed files with 5 additions and 0 deletions

View File

@ -40,6 +40,9 @@ val AccountExtras.official: Boolean
return false
}
val AccountDetails.hasDm: Boolean
get() = type in arrayOf(AccountType.FANFOU, AccountType.TWITTER)
fun <T> AccountDetails.newMicroBlogInstance(context: Context, cls: Class<T>): T {
return credentials.newMicroBlogInstance(context, type, cls)
}

View File

@ -37,6 +37,7 @@ import org.mariotaku.sqliteqb.library.Expression
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_SHOW_NOTIFICATION
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.exception.APINotSupportedException
import org.mariotaku.twidere.extension.findFieldByTypes
import org.mariotaku.twidere.extension.model.*
import org.mariotaku.twidere.extension.model.api.target
@ -85,6 +86,7 @@ class GetMessagesTask(
}
val microBlog = details.newMicroBlogInstance(context, cls = MicroBlog::class.java)
val messages = try {
if (!details.hasDm) throw APINotSupportedException(details.type)
getMessages(microBlog, details, param, i)
} catch (e: MicroBlogException) {
return@forEachIndexed