1
0
mirror of https://github.com/tateisu/SubwayTooter synced 2025-01-28 01:29:23 +01:00

通知カラムのストリーミングでトゥート削除イベントを受け取った際に他カラムのトゥートも除去する

This commit is contained in:
tateisu 2018-03-21 14:18:19 +09:00
parent dca4e0742d
commit 9e32f98ae5
5 changed files with 259 additions and 148 deletions

2
.idea/misc.xml generated
View File

@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -12,8 +12,8 @@ android {
minSdkVersion 21
targetSdkVersion 27
versionCode 228
versionName "2.2.8"
versionCode 229
versionName "2.2.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

View File

@ -784,29 +784,35 @@ class Column(
}
}
// 自分のステータスを削除した時に呼ばれる
fun removeStatus(target_account : SavedAccount, status_id : Long) {
// ステータスが削除された時に呼ばれる
fun onStatusRemoved(tl_host : String, status_id : Long) {
if(target_account.host != access_info.host) return
val tmp_list = ArrayList<TimelineItem>(list_data.size)
for(o in list_data) {
if(o is TootStatus) {
if(status_id == o.id) continue
if(status_id == (o.reblog?.id ?: - 1L)) continue
if(is_dispose.get() || bInitialLoading || bRefreshLoading ) return
if(tl_host.equals(access_info.host, ignoreCase = true)) {
val tmp_list = ArrayList<TimelineItem>(list_data.size)
for(o in list_data) {
if(o is TootStatus) {
if(status_id == o.id) continue
if(status_id == (o.reblog?.id ?: - 1L)) continue
}else if(o is TootNotification) {
val s = o.status
if(s != null) {
if(status_id == s.id) continue
if(status_id == (s.reblog?.id ?: - 1L)) continue
}
}
tmp_list.add(o)
}
if(o is TootNotification) {
if(status_id == (o.status?.id ?: - 1L)) continue
if(status_id == (o.status?.reblog?.id ?: - 1L)) continue
if(tmp_list.size != list_data.size) {
list_data.clear()
list_data.addAll(tmp_list)
fireShowContent(reason = "removeStatus")
}
tmp_list.add(o)
}
if(tmp_list.size != list_data.size) {
list_data.clear()
list_data.addAll(tmp_list)
fireShowContent(reason = "removeStatus")
}
}
fun removeNotifications() {
@ -871,16 +877,16 @@ class Column(
}
fun onHideFavouriteNotification(acct : String) {
if( column_type != TYPE_NOTIFICATIONS) return
if(column_type != TYPE_NOTIFICATIONS) return
val tmp_list = ArrayList<TimelineItem>(list_data.size)
for(o in list_data) {
if(o is TootNotification && o.type != TootNotification.TYPE_MENTION ) {
if(o is TootNotification && o.type != TootNotification.TYPE_MENTION) {
val a = o.account
if( a!=null){
if(a != null) {
val a_acct = access_info.getFullAcct(a)
if( a_acct == acct) continue
if(a_acct == acct) continue
}
}
tmp_list.add(o)
@ -947,7 +953,7 @@ class Column(
}
TYPE_LIST_TL, TYPE_LIST_MEMBER -> {
if( item.id == profile_id) {
if(item.id == profile_id) {
this.list_info = item
fireShowColumnHeader()
}
@ -1099,8 +1105,8 @@ class Column(
}
if(dont_show_normal_toot) {
if( status.in_reply_to_id?.isEmpty() != false
&& status.reblog == null
if(status.in_reply_to_id?.isEmpty() != false
&& status.reblog == null
) return true
}
@ -1186,11 +1192,11 @@ class Column(
}
// ふぁぼ魔ミュート
when(item.type){
TootNotification.TYPE_REBLOG,TootNotification.TYPE_FAVOURITE,TootNotification.TYPE_FOLLOW ->{
when(item.type) {
TootNotification.TYPE_REBLOG, TootNotification.TYPE_FAVOURITE, TootNotification.TYPE_FOLLOW -> {
val who = item.account
if( who != null && favMuteSet?.contains( access_info.getFullAcct(who) ) == true){
PollingWorker.log.d("%s is in favMuteSet.",access_info.getFullAcct(who))
if(who != null && favMuteSet?.contains(access_info.getFullAcct(who)) == true) {
PollingWorker.log.d("%s is in favMuteSet.", access_info.getFullAcct(who))
return true
}
}
@ -1393,7 +1399,7 @@ class Column(
val result = client.request("/api/v1/instance")
val jsonObject = result?.jsonObject
if(jsonObject != null) {
instance_tmp = parseItem(::TootInstance, parser,jsonObject)
instance_tmp = parseItem(::TootInstance, parser, jsonObject)
}
return result
}
@ -1523,8 +1529,8 @@ class Column(
return result
}
internal fun parseNotifications( client : TootApiClient ) : TootApiResult? {
val path_base = makeNotificationUrl()
internal fun parseNotifications(client : TootApiClient) : TootApiResult? {
val path_base = makeNotificationUrl()
val time_start = SystemClock.elapsedRealtime()
val result = client.request(path_base)
@ -1692,7 +1698,7 @@ class Column(
TYPE_FAVOURITES -> return getStatuses(client, PATH_FAVOURITES)
TYPE_HASHTAG -> return getStatuses( client,makeHashtagUrl(hashtag) )
TYPE_HASHTAG -> return getStatuses(client, makeHashtagUrl(hashtag))
TYPE_REPORTS -> return parseReports(client, PATH_REPORTS)
@ -2271,8 +2277,8 @@ class Column(
return result
}
internal fun getNotificationList( client : TootApiClient ) : TootApiResult? {
val path_base = makeNotificationUrl()
internal fun getNotificationList(client : TootApiClient) : TootApiResult? {
val path_base = makeNotificationUrl()
val time_start = SystemClock.elapsedRealtime()
val delimiter = if(- 1 != path_base.indexOf('?')) '&' else '?'
val last_since_id = since_id
@ -2617,7 +2623,7 @@ class Column(
TYPE_FOLLOW_REQUESTS -> getAccountList(client, PATH_FOLLOW_REQUESTS)
TYPE_HASHTAG -> getStatusList( client,makeHashtagUrl(hashtag) )
TYPE_HASHTAG -> getStatusList(client, makeHashtagUrl(hashtag))
TYPE_SEARCH_MSP ->
if(! bBottom) {
@ -2926,8 +2932,8 @@ class Column(
return result
}
internal fun getNotificationList( client : TootApiClient ) : TootApiResult? {
val path_base = makeNotificationUrl()
internal fun getNotificationList(client : TootApiClient) : TootApiResult? {
val path_base = makeNotificationUrl()
val time_start = SystemClock.elapsedRealtime()
val delimiter = if(- 1 != path_base.indexOf('?')) '&' else '?'
@ -3072,7 +3078,7 @@ class Column(
TYPE_NOTIFICATIONS -> getNotificationList(client)
TYPE_HASHTAG -> getStatusList( client,makeHashtagUrl(hashtag) )
TYPE_HASHTAG -> getStatusList(client, makeHashtagUrl(hashtag))
TYPE_BOOSTED_BY -> getAccountList(
client,
@ -3438,31 +3444,22 @@ class Column(
}
}
private val onStreamingMessage = fun(event_type : String, item : Any?) {
private val onStreamingMessage = fun(item : TimelineItem) {
if(is_dispose.get()) return
if(item is Long) {
if("delete" == event_type) {
removeStatus(access_info, item)
if(item is TootNotification) {
if(column_type != TYPE_NOTIFICATIONS) return
if(isFiltered(item)) return
} else if(item is TootStatus) {
if(column_type == TYPE_NOTIFICATIONS) return
if(column_type == TYPE_LOCAL && item.account.acct.indexOf('@') != - 1) return
if(isFiltered(item)) return
if(this.enable_speech) {
App1.getAppState(context).addSpeech(item.reblog ?: item)
}
return
} else if(item is TimelineItem) {
if(item is TootNotification) {
if(column_type != TYPE_NOTIFICATIONS) return
if(isFiltered(item)) return
} else if(item is TootStatus) {
if(column_type == TYPE_NOTIFICATIONS) return
if(column_type == TYPE_LOCAL && item.account.acct.indexOf('@') != - 1) return
if(isFiltered(item)) return
if(this.enable_speech) {
App1.getAppState(context).addSpeech(item.reblog ?: item)
}
}
stream_data_queue.addFirst(item)
mergeStreamingMessage.run()
}
stream_data_queue.addFirst(item)
mergeStreamingMessage.run()
}
private val mergeStreamingMessage = object : Runnable {
@ -3604,10 +3601,10 @@ class Column(
}
}
private fun makeNotificationUrl():String{
return if(!dont_show_favourite && !dont_show_boost && !dont_show_follow && !dont_show_reply){
private fun makeNotificationUrl() : String {
return if(! dont_show_favourite && ! dont_show_boost && ! dont_show_follow && ! dont_show_reply) {
PATH_NOTIFICATIONS
}else {
} else {
val sb = StringBuilder(PATH_NOTIFICATIONS) // always contain "?limit=XX"
if(dont_show_favourite) sb.append("&exclude_types[]=favourite")
if(dont_show_boost) sb.append("&exclude_types[]=reblog")
@ -3616,28 +3613,30 @@ class Column(
sb.toString()
}
}
private fun makePublicLocalUrl():String{
return if( with_attachment){
private fun makePublicLocalUrl() : String {
return if(with_attachment) {
"$PATH_LOCAL&only_media=true" // mastodon 2.3 or later
}else{
} else {
PATH_LOCAL
}
}
private fun makePublicFederateUrl():String{
return if( with_attachment){
private fun makePublicFederateUrl() : String {
return if(with_attachment) {
"$PATH_FEDERATE&only_media=true"
}else{
} else {
PATH_FEDERATE
}
}
private fun makeHashtagUrl(
hashtag:String // 先頭の#を含まない
):String{
val path =String.format(Locale.JAPAN, PATH_HASHTAG, hashtag.encodePercent())
return if( with_attachment){
hashtag : String // 先頭の#を含まない
) : String {
val path = String.format(Locale.JAPAN, PATH_HASHTAG, hashtag.encodePercent())
return if(with_attachment) {
"$path&only_media=true"
}else{
} else {
path
}
}

View File

@ -15,6 +15,7 @@ import jp.juggler.subwaytooter.api.TootApiResult
import jp.juggler.subwaytooter.api.TootTask
import jp.juggler.subwaytooter.api.TootTaskRunner
import jp.juggler.subwaytooter.api.TootParser
import jp.juggler.subwaytooter.api.entity.TimelineItem
import jp.juggler.subwaytooter.api.entity.TootPayload
import jp.juggler.subwaytooter.table.SavedAccount
import jp.juggler.subwaytooter.util.LogCategory
@ -49,7 +50,7 @@ internal class StreamReader(
internal val bDisposed = AtomicBoolean()
internal val bListening = AtomicBoolean()
internal val socket = AtomicReference<WebSocket>(null)
internal val callback_list = LinkedList<(event_type : String, item : Any?) -> Unit>()
internal val callback_list = LinkedList<(item : TimelineItem) -> Unit>()
internal val parser : TootParser
init {
@ -72,7 +73,7 @@ internal class StreamReader(
}
@Synchronized
internal fun addCallback(stream_callback : (event_type : String, item : Any?) -> Unit) {
internal fun addCallback(stream_callback : (item : TimelineItem) -> Unit) {
for(c in callback_list) {
if(c === stream_callback) return
}
@ -80,7 +81,7 @@ internal class StreamReader(
}
@Synchronized
internal fun removeCallback(stream_callback : (event_type : String, item : Any?) -> Unit) {
internal fun removeCallback(stream_callback : (item : TimelineItem) -> Unit) {
val it = callback_list.iterator()
while(it.hasNext()) {
val c = it.next()
@ -111,21 +112,42 @@ internal class StreamReader(
}
val payload = TootPayload.parsePayload(parser, event, obj, text)
if(payload == null) {
log.d("onMessage: payload is null")
return
}
runOnMainLooper {
synchronized(this) {
if(bDisposed.get()) return@runOnMainLooper
for(callback in callback_list) {
try {
callback(event, payload)
} catch(ex : Throwable) {
log.trace(ex)
when(event) {
"delete" -> {
if(payload is Long) {
val tl_host = access_info.host
for(column in App1.getAppState(context).column_list) {
try {
column.onStatusRemoved(tl_host, payload)
} catch(ex : Throwable) {
log.trace(ex)
}
}
} else {
log.d("payload is not long. $payload")
}
}
else -> {
if(payload is TimelineItem) {
for(callback in callback_list) {
try {
callback(payload)
} catch(ex : Throwable) {
log.trace(ex)
}
}
} else {
log.d("payload is not TimelineItem. $payload")
}
}
}
}
}
} catch(ex : Throwable) {
@ -246,7 +268,7 @@ internal class StreamReader(
accessInfo : SavedAccount,
endPoint : String,
highlightTrie : WordTrieTree?,
streamCallback : (event_type : String, item : Any?) -> Unit
streamCallback : (item : TimelineItem) -> Unit
) {
val reader = prepareReader(accessInfo, endPoint, highlightTrie)
@ -261,7 +283,7 @@ internal class StreamReader(
fun unregister(
accessInfo : SavedAccount,
endPoint : String,
streamCallback : (event_type : String, item : Any?) -> Unit
streamCallback : (item : TimelineItem) -> Unit
) {
synchronized(reader_list) {
val it = reader_list.iterator()

View File

@ -33,7 +33,8 @@ object Action_Toot {
private val log = LogCategory("Action_Favourite")
private val reDetailedStatusTime = Pattern.compile("<a\\b[^>]*?\\bdetailed-status__datetime\\b[^>]*href=\"https://[^/]+/@[^/]+/(\\d+)\"")
private val reDetailedStatusTime =
Pattern.compile("<a\\b[^>]*?\\bdetailed-status__datetime\\b[^>]*href=\"https://[^/]+/@[^/]+/(\\d+)\"")
// アカウントを選んでお気に入り
fun favouriteFromAnotherAccount(
@ -89,8 +90,12 @@ object Action_Toot {
if(nCrossAccountMode == CROSS_ACCOUNT_REMOTE_INSTANCE) {
// 検索APIに他タンスのステータスのURLを投げると、自タンスのステータスを得られる
val status_url = arg_status.url
if( status_url?.isEmpty()!=false) return TootApiResult("missing status URL")
val path = String.format(Locale.JAPAN, Column.PATH_SEARCH, status_url.encodePercent()) + "&resolve=1"
if(status_url?.isEmpty() != false) return TootApiResult("missing status URL")
val path = String.format(
Locale.JAPAN,
Column.PATH_SEARCH,
status_url.encodePercent()
) + "&resolve=1"
result = client.request(path)
val jsonObject = result?.jsonObject ?: return result
@ -113,9 +118,11 @@ object Action_Toot {
}
val request_builder = Request.Builder()
.post(RequestBody.create(
TootApiClient.MEDIA_TYPE_FORM_URL_ENCODED, ""
))
.post(
RequestBody.create(
TootApiClient.MEDIA_TYPE_FORM_URL_ENCODED, ""
)
)
result = client.request(
"/api/v1/statuses/" + target_status.id + if(bSet) "/favourite" else "/unfavourite",
@ -155,16 +162,16 @@ object Action_Toot {
for(column in App1.getAppState(activity).column_list) {
column.findStatus(access_info.host, new_status.id){ account,status ->
column.findStatus(access_info.host, new_status.id) { account, status ->
// 同タンス別アカウントでもカウントは変化する
status.favourites_count = new_status.favourites_count
if(access_info.acct == account.acct ) {
if(access_info.acct == account.acct) {
// 同アカウントならfav状態を変化させる
status.favourited = new_status.favourited
}
true
}
}
@ -200,7 +207,13 @@ object Action_Toot {
accountListArg = makeAccountListNonPseudo(activity, who_host)
) { action_account ->
boost(
activity, action_account, status, calcCrossAccountMode(timeline_account, action_account), true, false, activity.boost_complete_callback
activity,
action_account,
status,
calcCrossAccountMode(timeline_account, action_account),
true,
false,
activity.boost_complete_callback
)
}
}
@ -221,26 +234,37 @@ object Action_Toot {
return
}
// // クロスアカウント操作ではないならステータス内容を使ったチェックを行える
// if(nCrossAccountMode == NOT_CROSS_ACCOUNT) {
// if(arg_status.reblogged) {
// if(App1.getAppState(activity).isBusyFav(access_info, arg_status) || arg_status.favourited) {
// // FAVがついているか、FAV操作中はBoostを外せない
// showToast(activity, false, R.string.cant_remove_boost_while_favourited)
// return
// }
// }
// }
// // クロスアカウント操作ではないならステータス内容を使ったチェックを行える
// if(nCrossAccountMode == NOT_CROSS_ACCOUNT) {
// if(arg_status.reblogged) {
// if(App1.getAppState(activity).isBusyFav(access_info, arg_status) || arg_status.favourited) {
// // FAVがついているか、FAV操作中はBoostを外せない
// showToast(activity, false, R.string.cant_remove_boost_while_favourited)
// return
// }
// }
// }
// 必要なら確認を出す
if(bSet && ! bConfirmed) {
DlgConfirm.open(
activity,
activity.getString(R.string.confirm_boost_from, AcctColor.getNickname(access_info.acct)),
activity.getString(
R.string.confirm_boost_from,
AcctColor.getNickname(access_info.acct)
),
object : DlgConfirm.Callback {
override fun onOK() {
boost(activity, access_info, arg_status, nCrossAccountMode, true, true, callback)
boost(
activity,
access_info,
arg_status,
nCrossAccountMode,
true,
true,
callback
)
}
override var isConfirmEnabled : Boolean
@ -268,9 +292,13 @@ object Action_Toot {
var target_status : TootStatus?
if(nCrossAccountMode == CROSS_ACCOUNT_REMOTE_INSTANCE) {
val status_url = arg_status.url
if( status_url?.isEmpty()!=false) return TootApiResult("missing status URL")
if(status_url?.isEmpty() != false) return TootApiResult("missing status URL")
// 検索APIに他タンスのステータスのURLを投げると、自タンスのステータスを得られる
val path = String.format(Locale.JAPAN, Column.PATH_SEARCH, status_url.encodePercent() ) + "&resolve=1"
val path = String.format(
Locale.JAPAN,
Column.PATH_SEARCH,
status_url.encodePercent()
) + "&resolve=1"
result = client.request(path)
val jsonObject = result?.jsonObject ?: return result
@ -291,12 +319,16 @@ object Action_Toot {
}
val request_builder = Request.Builder()
.post(RequestBody.create(
TootApiClient.MEDIA_TYPE_FORM_URL_ENCODED, ""
))
.post(
RequestBody.create(
TootApiClient.MEDIA_TYPE_FORM_URL_ENCODED, ""
)
)
result = client.request(
"/api/v1/statuses/" + target_status.id + if(bSet) "/reblog" else "/unreblog", request_builder)
"/api/v1/statuses/" + target_status.id + if(bSet) "/reblog" else "/unreblog",
request_builder
)
val jsonObject = result?.jsonObject
if(jsonObject != null) {
@ -304,7 +336,8 @@ object Action_Toot {
// reblogはreblogを表すStatusを返す
// unreblogはreblogしたStatusを返す
this.new_status = if(new_status?.reblog != null) new_status.reblog else new_status
this.new_status =
if(new_status?.reblog != null) new_status.reblog else new_status
}
return result
@ -336,12 +369,12 @@ object Action_Toot {
}
for(column in App1.getAppState(activity).column_list) {
column.findStatus(access_info.host, new_status.id){ account, status ->
column.findStatus(access_info.host, new_status.id) { account, status ->
// 同タンス別アカウントでもカウントは変化する
status.reblogs_count = new_status.reblogs_count
if(access_info.acct == account.acct ) {
if(access_info.acct == account.acct) {
// 同アカウントならreblog状態を変化させる
status.reblogged = new_status.reblogged
}
@ -372,7 +405,7 @@ object Action_Toot {
override fun background(client : TootApiClient) : TootApiResult? {
val request_builder = Request.Builder().delete()
return client.request("/api/v1/statuses/" + status_id, request_builder)
return client.request("/api/v1/statuses/$status_id", request_builder)
}
override fun handleResult(result : TootApiResult?) {
@ -381,7 +414,7 @@ object Action_Toot {
if(result.jsonObject != null) {
showToast(activity, false, R.string.delete_succeeded)
for(column in App1.getAppState(activity).column_list) {
column.removeStatus(access_info, status_id)
column.onStatusRemoved(access_info.host, status_id)
}
} else {
showToast(activity, false, result.error)
@ -440,7 +473,14 @@ object Action_Toot {
// 投稿元タンスでのIDはuriやURLから調べる
// pleromaではIDがuuidなので失敗する(その時はURLを検索してIDを見つける)
val status_id_original = TootStatus.findStatusIdFromUri(status.uri, status.url)
conversationOtherInstance(activity, pos, url, status_id_original, status.host_access, status.id)
conversationOtherInstance(
activity,
pos,
url,
status_id_original,
status.host_access,
status.id
)
}
}
}
@ -460,7 +500,12 @@ object Action_Toot {
val host_original = Uri.parse(url).authority
// 選択肢:ブラウザで表示する
dialog.addAction(activity.getString(R.string.open_web_on_host, host_original)) { App1.openCustomTab(activity, url) }
dialog.addAction(
activity.getString(
R.string.open_web_on_host,
host_original
)
) { App1.openCustomTab(activity, url) }
// トゥートの投稿元タンスにあるアカウント
val local_account_list = ArrayList<SavedAccount>()
@ -492,14 +537,18 @@ object Action_Toot {
// 同タンスのアカウントがないなら、疑似アカウントで開く選択肢
if(local_account_list.isEmpty()) {
if(status_id_original >= 0L) {
dialog.addAction(activity.getString(R.string.open_in_pseudo_account, "?@" + host_original)) {
dialog.addAction(
activity.getString(R.string.open_in_pseudo_account, "?@$host_original")
) {
val sa = addPseudoAccount(activity, host_original)
if(sa != null) {
conversationLocal(activity, pos, sa, status_id_original)
}
}
} else {
dialog.addAction(activity.getString(R.string.open_in_pseudo_account, "?@" + host_original)) {
dialog.addAction(
activity.getString(R.string.open_in_pseudo_account, "?@$host_original")
) {
val sa = addPseudoAccount(activity, host_original)
if(sa != null) {
conversationRemote(activity, pos, sa, url)
@ -511,19 +560,37 @@ object Action_Toot {
// ローカルアカウント
SavedAccount.sort(local_account_list)
for(a in local_account_list) {
dialog.addAction(AcctColor.getStringWithNickname(activity, R.string.open_in_account, a.acct)) { conversationLocal(activity, pos, a, status_id_original) }
dialog.addAction(
AcctColor.getStringWithNickname(
activity,
R.string.open_in_account,
a.acct
)
) { conversationLocal(activity, pos, a, status_id_original) }
}
// アクセスしたアカウント
SavedAccount.sort(access_account_list)
for(a in access_account_list) {
dialog.addAction(AcctColor.getStringWithNickname(activity, R.string.open_in_account, a.acct)) { conversationLocal(activity, pos, a, status_id_access) }
dialog.addAction(
AcctColor.getStringWithNickname(
activity,
R.string.open_in_account,
a.acct
)
) { conversationLocal(activity, pos, a, status_id_access) }
}
// その他の実アカウント
SavedAccount.sort(other_account_list)
for(a in other_account_list) {
dialog.addAction(AcctColor.getStringWithNickname(activity, R.string.open_in_account, a.acct)) { conversationRemote(activity, pos, a, url) }
dialog.addAction(
AcctColor.getStringWithNickname(
activity,
R.string.open_in_account,
a.acct
)
) { conversationRemote(activity, pos, a, url) }
}
dialog.show(activity, activity.getString(R.string.open_status_from))
@ -554,12 +621,17 @@ object Action_Toot {
}
if(local_status_id == - 1L) {
result = TootApiResult(activity.getString(R.string.status_id_conversion_failed))
result =
TootApiResult(activity.getString(R.string.status_id_conversion_failed))
}
}
} else {
// 検索APIに他タンスのステータスのURLを投げると、自タンスのステータスを得られる
val path = String.format(Locale.JAPAN, Column.PATH_SEARCH, remote_status_url.encodePercent()) + "&resolve=1"
val path = String.format(
Locale.JAPAN,
Column.PATH_SEARCH,
remote_status_url.encodePercent()
) + "&resolve=1"
result = client.request(path)
val jsonObject = result?.jsonObject
if(jsonObject != null) {
@ -570,7 +642,8 @@ object Action_Toot {
log.d("status id conversion %s => %s", remote_status_url, status.id)
}
if(local_status_id == - 1L) {
result = TootApiResult(activity.getString(R.string.status_id_conversion_failed))
result =
TootApiResult(activity.getString(R.string.status_id_conversion_failed))
}
}
}
@ -607,15 +680,18 @@ object Action_Toot {
val result : TootApiResult?
val request_builder = Request.Builder()
.post(RequestBody.create(
TootApiClient.MEDIA_TYPE_FORM_URL_ENCODED, ""
))
.post(
RequestBody.create(
TootApiClient.MEDIA_TYPE_FORM_URL_ENCODED, ""
)
)
result = client.request(
if(bSet)
"/api/v1/statuses/" + status.id + "/pin"
else
"/api/v1/statuses/" + status.id + "/unpin", request_builder)
"/api/v1/statuses/" + status.id + "/unpin", request_builder
)
new_status = TootParser(activity, access_info).status(result?.jsonObject)
@ -631,16 +707,20 @@ object Action_Toot {
// cancelled.
}
new_status != null ->{
new_status != null -> {
for(column in App1.getAppState(activity).column_list) {
if( access_info.acct == column.access_info.acct){
column.findStatus(access_info.host, new_status.id){_,status->
if(access_info.acct == column.access_info.acct) {
column.findStatus(
access_info.host,
new_status.id
) { _, status ->
status.pinned = bSet
true
}
}
}
}
else -> showToast(activity, true, result.error)
}
@ -696,7 +776,11 @@ object Action_Toot {
internal var local_status : TootStatus? = null
override fun background(client : TootApiClient) : TootApiResult? {
// 検索APIに他タンスのステータスのURLを投げると、自タンスのステータスを得られる
val path = String.format(Locale.JAPAN, Column.PATH_SEARCH,remote_status_url.encodePercent()) + "&resolve=1"
val path = String.format(
Locale.JAPAN,
Column.PATH_SEARCH,
remote_status_url.encodePercent()
) + "&resolve=1"
val result = client.request(path)
val jsonObject = result?.jsonObject
@ -707,7 +791,8 @@ object Action_Toot {
local_status = ls
log.d("status id conversion %s => %s", remote_status_url, ls.id)
}
local_status ?: return TootApiResult(activity.getString(R.string.status_id_conversion_failed))
local_status
?: return TootApiResult(activity.getString(R.string.status_id_conversion_failed))
}
return result
}
@ -743,7 +828,8 @@ object Action_Toot {
.post(RequestBody.create(TootApiClient.MEDIA_TYPE_FORM_URL_ENCODED, ""))
val result = client.request(
"/api/v1/statuses/" + status.id + if(bMute) "/mute" else "/unmute", request_builder
"/api/v1/statuses/" + status.id + if(bMute) "/mute" else "/unmute",
request_builder
)
local_status = TootParser(activity, access_info).status(result?.jsonObject)
@ -757,14 +843,18 @@ object Action_Toot {
val ls = local_status
if(ls != null) {
for(column in App1.getAppState(activity).column_list) {
if(access_info.acct == column.access_info.acct ) {
if(access_info.acct == column.access_info.acct) {
column.findStatus(access_info.host, ls.id) { _, status ->
status.muted = bMute
true
}
}
}
showToast(activity, true, if(bMute) R.string.mute_succeeded else R.string.unmute_succeeded)
showToast(
activity,
true,
if(bMute) R.string.mute_succeeded else R.string.unmute_succeeded
)
} else {
showToast(activity, true, result.error)
}