Skip to content

Commit

Permalink
[Twitter] ふぁぼ/あんふぁぼをTLに反映する
Browse files Browse the repository at this point in the history
refs #257
  • Loading branch information
shibafu528 committed Jul 16, 2019
1 parent 4ebe1c9 commit b33b9e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Yukari/src/main/java/shibafu/yukari/entity/ShadowUser.kt
@@ -0,0 +1,19 @@
package shibafu.yukari.entity

import shibafu.yukari.twitter.AuthUserRecord

/**
* 内部イベント処理用のUserスタブ
*/
class ShadowUser(userRecord: AuthUserRecord) : User {
override val id: Long = userRecord.NumericId
override val name: String = userRecord.Name
override val screenName: String = userRecord.ScreenName
override val isProtected: Boolean = false
override val profileImageUrl: String = userRecord.ProfileImageUrl
override val biggerProfileImageUrl: String = userRecord.ProfileImageUrl

override fun isMentionedTo(userRecord: AuthUserRecord): Boolean {
return false
}
}
12 changes: 11 additions & 1 deletion Yukari/src/main/java/shibafu/yukari/twitter/TwitterApi.kt
Expand Up @@ -8,6 +8,7 @@ import android.widget.Toast
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import shibafu.yukari.database.Provider
import shibafu.yukari.entity.ShadowUser
import shibafu.yukari.entity.Status
import shibafu.yukari.entity.StatusDraft
import shibafu.yukari.linkage.PostValidator
Expand Down Expand Up @@ -110,10 +111,13 @@ class TwitterApi : ProviderApi {
fun createFavorite(userRecord: AuthUserRecord, id: Long): Boolean {
val twitter = service.getTwitter(userRecord) ?: throw IllegalStateException("Twitterとの通信の準備に失敗しました")
try {
twitter.createFavorite(id)
val status = twitter.createFavorite(id)
Handler(Looper.getMainLooper()).post {
Toast.makeText(service.applicationContext, "ふぁぼりました (@" + userRecord.ScreenName + ")", Toast.LENGTH_SHORT).show()
}

service.timelineHub?.onFavorite(ShadowUser(userRecord), TwitterStatus(status, userRecord))

return true
} catch (e: TwitterException) {
e.printStackTrace()
Expand All @@ -131,6 +135,9 @@ class TwitterApi : ProviderApi {
Handler(Looper.getMainLooper()).post {
Toast.makeText(service.applicationContext, "ふぁぼりました (@" + userRecord.ScreenName + ")", Toast.LENGTH_SHORT).show()
}

service.timelineHub?.onFavorite(ShadowUser(userRecord), status)

return true
} catch (e: TwitterException) {
e.printStackTrace()
Expand All @@ -148,6 +155,9 @@ class TwitterApi : ProviderApi {
Handler(Looper.getMainLooper()).post {
Toast.makeText(service.applicationContext, "あんふぁぼしました (@" + userRecord.ScreenName + ")", Toast.LENGTH_SHORT).show()
}

service.timelineHub?.onUnfavorite(ShadowUser(userRecord), status)

return true
} catch (e: TwitterException) {
e.printStackTrace()
Expand Down

0 comments on commit b33b9e0

Please sign in to comment.