Merge pull request #1317 from Linkid/mastodon_pin_unpin

Mastodon: add pin / unpin toots
This commit is contained in:
Tlaster 2020-05-25 10:26:13 +08:00 committed by GitHub
commit ea37aee5a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 4 deletions

View File

@ -69,4 +69,10 @@ public interface StatusesResources {
@POST("/v1/statuses/{id}/unfavourite") @POST("/v1/statuses/{id}/unfavourite")
Status unfavouriteStatus(@Path("id") String id) throws MicroBlogException; Status unfavouriteStatus(@Path("id") String id) throws MicroBlogException;
@POST("/v1/statuses/{id}/pin")
Status pinStatus(@Path("id") String id) throws MicroBlogException;
@POST("/v1/statuses/{id}/unpin")
Status unpinStatus(@Path("id") String id) throws MicroBlogException;
} }

View File

@ -103,6 +103,11 @@ public class Status {
*/ */
@JsonField(name = "sensitive") @JsonField(name = "sensitive")
boolean sensitive; boolean sensitive;
/**
* Whether the authenticated user has pinned the status
*/
@JsonField(name = "pinned")
boolean pinned;
/** /**
* If not empty, warning text that should be displayed before the actual content * If not empty, warning text that should be displayed before the actual content
*/ */
@ -194,6 +199,10 @@ public class Status {
return sensitive; return sensitive;
} }
public boolean isPinned() {
return pinned;
}
public String getSpoilerText() { public String getSpoilerText() {
return spoilerText; return spoilerText;
} }
@ -251,6 +260,7 @@ public class Status {
", reblogged=" + reblogged + ", reblogged=" + reblogged +
", favourited=" + favourited + ", favourited=" + favourited +
", sensitive=" + sensitive + ", sensitive=" + sensitive +
", pinned=" + pinned +
", spoilerText='" + spoilerText + '\'' + ", spoilerText='" + spoilerText + '\'' +
", visibility='" + visibility + '\'' + ", visibility='" + visibility + '\'' +
", mediaAttachments=" + Arrays.toString(mediaAttachments) + ", mediaAttachments=" + Arrays.toString(mediaAttachments) +

View File

@ -22,8 +22,12 @@ package org.mariotaku.twidere.task.status
import android.content.Context import android.content.Context
import android.widget.Toast import android.widget.Toast
import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlog
import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.mastodon.Mastodon
import org.mariotaku.microblog.library.twitter.model.PinTweetResult import org.mariotaku.microblog.library.twitter.model.PinTweetResult
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.exception.APINotSupportedException
import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.newMicroBlogInstance
import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.AccountDetails
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
@ -37,10 +41,21 @@ import org.mariotaku.twidere.task.AbsAccountRequestTask
class PinStatusTask(context: Context, accountKey: UserKey, val id: String) : AbsAccountRequestTask<Any?, class PinStatusTask(context: Context, accountKey: UserKey, val id: String) : AbsAccountRequestTask<Any?,
PinTweetResult, Any?>(context, accountKey) { PinTweetResult, Any?>(context, accountKey) {
@Throws(MicroBlogException::class)
override fun onExecute(account: AccountDetails, params: Any?): PinTweetResult { override fun onExecute(account: AccountDetails, params: Any?): PinTweetResult {
when (account.type) {
AccountType.MASTODON -> {
val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java)
return mastodon.pinStatus(id)
}
AccountType.TWITTER -> {
val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java) val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java)
return twitter.pinTweet(id) return twitter.pinTweet(id)
} }
else -> {
throw APINotSupportedException(account.type)
}
}
override fun onSucceed(callback: Any?, result: PinTweetResult) { override fun onSucceed(callback: Any?, result: PinTweetResult) {
super.onSucceed(callback, result) super.onSucceed(callback, result)

View File

@ -22,6 +22,8 @@ package org.mariotaku.twidere.task.status
import android.content.Context import android.content.Context
import android.widget.Toast import android.widget.Toast
import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlog
import org.mariotaku.microblog.library.MicroBlogException
import org.mariotaku.microblog.library.mastodon.Mastodon
import org.mariotaku.microblog.library.twitter.model.PinTweetResult import org.mariotaku.microblog.library.twitter.model.PinTweetResult
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.newMicroBlogInstance
@ -29,6 +31,8 @@ import org.mariotaku.twidere.model.AccountDetails
import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.UserKey
import org.mariotaku.twidere.model.event.StatusPinEvent import org.mariotaku.twidere.model.event.StatusPinEvent
import org.mariotaku.twidere.task.AbsAccountRequestTask import org.mariotaku.twidere.task.AbsAccountRequestTask
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.exception.APINotSupportedException
/** /**
* Created by mariotaku on 2017/4/28. * Created by mariotaku on 2017/4/28.
@ -37,10 +41,21 @@ import org.mariotaku.twidere.task.AbsAccountRequestTask
class UnpinStatusTask(context: Context, accountKey: UserKey, val id: String) : AbsAccountRequestTask<Any?, class UnpinStatusTask(context: Context, accountKey: UserKey, val id: String) : AbsAccountRequestTask<Any?,
PinTweetResult, Any?>(context, accountKey) { PinTweetResult, Any?>(context, accountKey) {
@Throws(MicroBlogException::class)
override fun onExecute(account: AccountDetails, params: Any?): PinTweetResult { override fun onExecute(account: AccountDetails, params: Any?): PinTweetResult {
when (account.type) {
AccountType.MASTODON -> {
val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java)
return mastodon.unpinStatus(id)
}
AccountType.TWITTER -> {
val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java) val twitter = account.newMicroBlogInstance(context, MicroBlog::class.java)
return twitter.unpinTweet(id) return twitter.unpinTweet(id)
} }
else -> {
throw APINotSupportedException(account.type)
}
}
override fun onSucceed(callback: Any?, result: PinTweetResult) { override fun onSucceed(callback: Any?, result: PinTweetResult) {
super.onSucceed(callback, result) super.onSucceed(callback, result)