トゥート検索から 「別アカウントでプロフを開く」でMisskeyアカウントを選択した時の挙動を改善

This commit is contained in:
tateisu 2018-08-27 15:12:58 +09:00
parent 7f3ba1749c
commit 418259ded9
3 changed files with 81 additions and 27 deletions

View File

@ -235,6 +235,32 @@ object Action_User {
var who_local : TootAccount? = null var who_local : TootAccount? = null
override fun background(client : TootApiClient) : TootApiResult? { override fun background(client : TootApiClient) : TootApiResult? {
if( access_info.isMisskey){
val acct = TootAccount.getAcctFromUrl(who_url)
?: return TootApiResult("can't find acct from $who_url")
val delm = acct.indexOf('@')
val params = access_info.putMisskeyApiToken(JSONObject())
if(delm!=-1){
params.put("username",acct.substring(0,delm))
params.put("host",acct.substring(delm+1))
}else{
params.put("username",acct)
}
val result = client.request("/api/users/show",params.toPostRequestBuilder())
val jsonObject = result?.jsonObject
if(jsonObject != null) {
val tmp = TootParser(activity, access_info).account(jsonObject)
if(tmp != null){
who_local = tmp
} else {
return TootApiResult(activity.getString(R.string.user_id_conversion_failed))
}
}
return result
}else{
val path = String.format( val path = String.format(
Locale.JAPAN, Locale.JAPAN,
Column.PATH_SEARCH, Column.PATH_SEARCH,
@ -253,6 +279,8 @@ object Action_User {
} }
return result return result
}
} }
override fun handleResult(result : TootApiResult?) { override fun handleResult(result : TootApiResult?) {

View File

@ -310,6 +310,7 @@ open class TootAccount(parser : TootParser, src : JSONObject) {
@Suppress("HasPlatformType") @Suppress("HasPlatformType")
val reAccountUrl = val reAccountUrl =
Pattern.compile("\\Ahttps://([A-Za-z0-9.-]+)/@([A-Za-z0-9_]+(?:@[A-Za-z0-9][A-Za-z0-9.-]+?[A-Za-z0-9])?)(?:\\z|[?#])") Pattern.compile("\\Ahttps://([A-Za-z0-9.-]+)/@([A-Za-z0-9_]+(?:@[A-Za-z0-9][A-Za-z0-9.-]+?[A-Za-z0-9])?)(?:\\z|[?#])")
fun getAcctFromUrl(url:String):String?{ fun getAcctFromUrl(url:String):String?{
val m = TootAccount.reAccountUrl.matcher(url) val m = TootAccount.reAccountUrl.matcher(url)
if(m.find()){ if(m.find()){

View File

@ -36,8 +36,10 @@ import jp.juggler.subwaytooter.table.SavedAccount
import jp.juggler.subwaytooter.util.NetworkEmojiInvalidator import jp.juggler.subwaytooter.util.NetworkEmojiInvalidator
import jp.juggler.subwaytooter.util.encodePercent import jp.juggler.subwaytooter.util.encodePercent
import jp.juggler.subwaytooter.util.showToast import jp.juggler.subwaytooter.util.showToast
import jp.juggler.subwaytooter.util.toPostRequestBuilder
import jp.juggler.subwaytooter.view.MyListView import jp.juggler.subwaytooter.view.MyListView
import jp.juggler.subwaytooter.view.MyNetworkImageView import jp.juggler.subwaytooter.view.MyNetworkImageView
import org.json.JSONObject
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
class DlgListMember( class DlgListMember(
@ -187,7 +189,29 @@ class DlgListMember(
override fun background(client : TootApiClient) : TootApiResult? { override fun background(client : TootApiClient) : TootApiResult? {
// リストに追加したいアカウントの自タンスでのアカウントIDを取得する // リストに追加したいアカウントの自タンスでのアカウントIDを取得する
local_who = null local_who = null
var result = client.request("/api/v1/search?resolve=true&q=" + target_user_full_acct.encodePercent())
if( list_owner.isMisskey){
val acct = target_user_full_acct
val delm = acct.indexOf('@')
val params = list_owner.putMisskeyApiToken(JSONObject())
if(delm!=-1){
params.put("username",acct.substring(0,delm))
params.put("host",acct.substring(delm+1))
}else{
params.put("username",acct)
}
val result = client.request("/api/users/show",params.toPostRequestBuilder())
val jsonObject = result?.jsonObject
if(jsonObject != null) {
val tmp = TootParser(activity, list_owner).account(jsonObject)
if(tmp != null){
local_who = tmp
}
}
}else{
val result = client.request("/api/v1/search?resolve=true&q=" + target_user_full_acct.encodePercent())
val jsonObject = result?.jsonObject ?: return result val jsonObject = result?.jsonObject ?: return result
@ -201,12 +225,13 @@ class DlgListMember(
} }
} }
} }
}
val local_who = this@DlgListMember.local_who val local_who = this@DlgListMember.local_who
?: return TootApiResult(activity.getString(R.string.account_sync_failed)) ?: return TootApiResult(activity.getString(R.string.account_sync_failed))
// リスト登録状況を取得 // リスト登録状況を取得
result = client.request("/api/v1/accounts/" + local_who .id + "/lists") var result = client.request("/api/v1/accounts/" + local_who .id + "/lists")
var jsonArray = result?.jsonArray ?:return result var jsonArray = result?.jsonArray ?:return result
// 結果を解釈する // 結果を解釈する