/api/v1/follows の廃止にともなう変更2
This commit is contained in:
parent
4e47b6027e
commit
905a855bd2
|
@ -4,10 +4,7 @@ import jp.juggler.subwaytooter.ActMain
|
||||||
import jp.juggler.subwaytooter.App1
|
import jp.juggler.subwaytooter.App1
|
||||||
import jp.juggler.subwaytooter.R
|
import jp.juggler.subwaytooter.R
|
||||||
import jp.juggler.subwaytooter.api.*
|
import jp.juggler.subwaytooter.api.*
|
||||||
import jp.juggler.subwaytooter.api.entity.EntityId
|
import jp.juggler.subwaytooter.api.entity.*
|
||||||
import jp.juggler.subwaytooter.api.entity.TootAccount
|
|
||||||
import jp.juggler.subwaytooter.api.entity.TootRelationShip
|
|
||||||
import jp.juggler.subwaytooter.api.entity.parseList
|
|
||||||
import jp.juggler.subwaytooter.dialog.DlgConfirm
|
import jp.juggler.subwaytooter.dialog.DlgConfirm
|
||||||
import jp.juggler.subwaytooter.table.SavedAccount
|
import jp.juggler.subwaytooter.table.SavedAccount
|
||||||
import jp.juggler.util.*
|
import jp.juggler.util.*
|
||||||
|
@ -40,10 +37,10 @@ object Action_ListMember {
|
||||||
TootTaskRunner(activity).run(access_info, object : TootTask {
|
TootTaskRunner(activity).run(access_info, object : TootTask {
|
||||||
override fun background(client : TootApiClient) : TootApiResult? {
|
override fun background(client : TootApiClient) : TootApiResult? {
|
||||||
|
|
||||||
var result : TootApiResult?
|
|
||||||
|
|
||||||
val parser = TootParser(activity, access_info)
|
val parser = TootParser(activity, access_info)
|
||||||
|
|
||||||
|
var userId = local_who.id
|
||||||
|
|
||||||
return if(access_info.isMisskey) {
|
return if(access_info.isMisskey) {
|
||||||
// misskeyのリストはフォロー無関係
|
// misskeyのリストはフォロー無関係
|
||||||
|
|
||||||
|
@ -55,37 +52,24 @@ object Action_ListMember {
|
||||||
// 204 no content
|
// 204 no content
|
||||||
} else {
|
} else {
|
||||||
if(bFollow) {
|
if(bFollow) {
|
||||||
val relation : TootRelationShip?
|
|
||||||
if(access_info.isLocalUser(local_who)) {
|
|
||||||
|
|
||||||
result = client.request(
|
// リモートユーザの解決
|
||||||
"/api/v1/accounts/" + local_who.id + "/follow",
|
if(! access_info.isLocalUser(local_who)) {
|
||||||
|
val (r2, ar) = client.syncAccountByAcct(access_info, local_who.acct)
|
||||||
|
val user = ar?.get() ?: return r2
|
||||||
|
userId = user.id
|
||||||
|
}
|
||||||
|
|
||||||
|
val result = client.request(
|
||||||
|
"/api/v1/accounts/$userId/follow",
|
||||||
"".toRequestBody().toPost()
|
"".toRequestBody().toPost()
|
||||||
|
) ?: return null
|
||||||
|
|
||||||
|
val relation = saveUserRelation(
|
||||||
|
access_info,
|
||||||
|
parseItem(::TootRelationShip, parser, result.jsonObject)
|
||||||
)
|
)
|
||||||
} else {
|
?: return TootApiResult("parse error.")
|
||||||
// リモートフォローする
|
|
||||||
result = client.request(
|
|
||||||
"/api/v1/follows",
|
|
||||||
"uri=${local_who.acct.encodePercent()}".toRequestBody().toPost()
|
|
||||||
)
|
|
||||||
|
|
||||||
val jsonObject = result?.jsonObject ?: return result
|
|
||||||
|
|
||||||
val a = parser.account(jsonObject)
|
|
||||||
?: return result.setError("parse error.")
|
|
||||||
|
|
||||||
// リモートフォローの後にリレーションシップを取得しなおす
|
|
||||||
result = client.request("/api/v1/accounts/relationships?id[]=" + a.id)
|
|
||||||
}
|
|
||||||
val jsonArray = result?.jsonArray ?: return result
|
|
||||||
|
|
||||||
val relation_list = parseList(::TootRelationShip, parser, jsonArray)
|
|
||||||
relation = if(relation_list.isEmpty()) null else relation_list[0]
|
|
||||||
|
|
||||||
if(relation == null) {
|
|
||||||
return TootApiResult("parse error.")
|
|
||||||
}
|
|
||||||
saveUserRelation(access_info, relation)
|
|
||||||
|
|
||||||
if(! relation.following) {
|
if(! relation.following) {
|
||||||
if(relation.requested) {
|
if(relation.requested) {
|
||||||
|
@ -101,12 +85,14 @@ object Action_ListMember {
|
||||||
|
|
||||||
client.request(
|
client.request(
|
||||||
"/api/v1/lists/$list_id/accounts",
|
"/api/v1/lists/$list_id/accounts",
|
||||||
JSONObject().put(
|
JSONObject().apply {
|
||||||
|
put(
|
||||||
"account_ids",
|
"account_ids",
|
||||||
JSONArray().put(
|
JSONArray().apply {
|
||||||
local_who.id.toString()
|
put(userId.toString())
|
||||||
)
|
}
|
||||||
)
|
)
|
||||||
|
}
|
||||||
.toPostRequestBuilder()
|
.toPostRequestBuilder()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -191,11 +177,11 @@ object Action_ListMember {
|
||||||
client.request(
|
client.request(
|
||||||
"/api/users/lists/pull",
|
"/api/users/lists/pull",
|
||||||
access_info.putMisskeyApiToken()
|
access_info.putMisskeyApiToken()
|
||||||
.put("listId",list_id.toString())
|
.put("listId", list_id.toString())
|
||||||
.put("userId",local_who.id.toString())
|
.put("userId", local_who.id.toString())
|
||||||
.toPostRequestBuilder()
|
.toPostRequestBuilder()
|
||||||
)
|
)
|
||||||
}else{
|
} else {
|
||||||
client.request(
|
client.request(
|
||||||
"/api/v1/lists/${list_id}/accounts?account_ids[]=${local_who.id}",
|
"/api/v1/lists/${list_id}/accounts?account_ids[]=${local_who.id}",
|
||||||
Request.Builder().delete()
|
Request.Builder().delete()
|
||||||
|
|
Loading…
Reference in New Issue