From d2e98524aca2fdd4bd30f3fdb0aee88cbbcb0b34 Mon Sep 17 00:00:00 2001 From: Michel Roux Date: Mon, 20 Apr 2020 19:28:01 +0200 Subject: [PATCH] Backport #1038 : Mastodon's API doesn't have `/api/direct_messages.json` --- .../twidere/extension/model/AccountDetailsExtensions.kt | 3 +++ .../mariotaku/twidere/task/twitter/message/GetMessagesTask.kt | 2 ++ 2 files changed, 5 insertions(+) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt index 4007130fb..073998137 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/AccountDetailsExtensions.kt @@ -40,6 +40,9 @@ val AccountExtras.official: Boolean return false } +val AccountDetails.hasDm: Boolean + get() = type in arrayOf(AccountType.FANFOU, AccountType.TWITTER) + fun AccountDetails.newMicroBlogInstance(context: Context, cls: Class): T { return credentials.newMicroBlogInstance(context, type, cls) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt index b294b2b42..4765f3e36 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/message/GetMessagesTask.kt @@ -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