mirror of
https://github.com/tateisu/SubwayTooter
synced 2025-02-06 05:33:50 +01:00
refactor. fix mute from pseudo account
This commit is contained in:
parent
80f3e4effe
commit
f33b3a84c5
@ -27,13 +27,13 @@ class TestTootAccount {
|
||||
// find from accessHost
|
||||
assertEquals(
|
||||
"",
|
||||
TootAccount.findHostFromUrl(null, LinkHelper.newLinkHelper(Host.parse("")), null).first
|
||||
TootAccount.findHostFromUrl(null, LinkHelper.create(Host.parse("")), null).first
|
||||
)
|
||||
assertEquals(
|
||||
"any string is allowed",
|
||||
TootAccount.findHostFromUrl(
|
||||
null,
|
||||
LinkHelper.newLinkHelper(Host.parse("any string is allowed")),
|
||||
LinkHelper.create(Host.parse("any string is allowed")),
|
||||
null
|
||||
).first
|
||||
)
|
||||
|
@ -26,7 +26,7 @@ class TestHtmlDecoder {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getTargetContext()
|
||||
|
||||
val options = DecodeOptions(appContext,LinkHelper.newLinkHelper(Host.parse("instance.test")))
|
||||
val options = DecodeOptions(appContext,LinkHelper.create(Host.parse("instance.test")))
|
||||
|
||||
val html = """
|
||||
日本語で楽しめるMastodonサーバを提供しています。
|
||||
|
@ -400,7 +400,7 @@ internal class DlgContextMenu(
|
||||
|
||||
if(access_info.isPseudo) {
|
||||
// 疑似アカミュートができたのでアカウントアクションを表示する
|
||||
showRelation(UserRelation())
|
||||
showRelation( relation)
|
||||
llAccountActionBar.visibility = View.VISIBLE
|
||||
ivFollowedBy.vg(false)
|
||||
btnFollow.setImageResource(R.drawable.ic_follow_plus)
|
||||
@ -690,7 +690,12 @@ internal class DlgContextMenu(
|
||||
access_info,
|
||||
bMute = false
|
||||
)
|
||||
else -> Action_User.muteConfirm(activity, access_info, who, access_info)
|
||||
else -> Action_User.muteConfirm(
|
||||
activity,
|
||||
access_info,
|
||||
who,
|
||||
access_info
|
||||
)
|
||||
}
|
||||
|
||||
R.id.btnBlock -> when {
|
||||
|
@ -1495,15 +1495,11 @@ internal class ItemViewHolder(
|
||||
ivOpenSticker.layoutParams = lp
|
||||
ivOpenSticker.setImageUrl(activity.pref, 0f, item.favicon)
|
||||
val colorBg = item.bgColor
|
||||
when {
|
||||
colorBg.isEmpty() -> {
|
||||
tvOpenSticker.background = null
|
||||
ivOpenSticker.background = null
|
||||
}
|
||||
|
||||
colorBg.size == 1 -> {
|
||||
tvOpenSticker.setBackgroundColor(colorBg.first())
|
||||
ivOpenSticker.setBackgroundColor(colorBg.first())
|
||||
when(colorBg.size) {
|
||||
1 -> {
|
||||
val c = colorBg.first()
|
||||
tvOpenSticker.setBackgroundColor(c)
|
||||
ivOpenSticker.setBackgroundColor(c)
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
@ -33,8 +33,7 @@ object Action_User {
|
||||
bMute : Boolean = true,
|
||||
bMuteNotification : Boolean = false
|
||||
) {
|
||||
val whoAcct = whoArg.acct
|
||||
|
||||
val whoAcct = whoAccessInfo.getFullAcct(whoArg)
|
||||
if(access_info.isMe(whoAcct)) {
|
||||
activity.showToast(false, R.string.it_is_you)
|
||||
return
|
||||
@ -46,71 +45,73 @@ object Action_User {
|
||||
var whoIdResult : EntityId? = null
|
||||
|
||||
override fun background(client : TootApiClient) : TootApiResult? {
|
||||
if(access_info.isPseudo)
|
||||
return if(whoAcct.ascii.contains('?')) {
|
||||
return if(access_info.isPseudo) {
|
||||
if(! whoAcct.isValidFull) {
|
||||
TootApiResult("can't mute pseudo acct ${whoAcct.pretty}")
|
||||
} else {
|
||||
val relation = UserRelation.loadPseudo(whoAcct)
|
||||
relation.muting = bMute
|
||||
relation.savePseudo(whoAcct.ascii)
|
||||
relationResult = relation
|
||||
whoIdResult = whoArg.id
|
||||
TootApiResult()
|
||||
}
|
||||
|
||||
val whoId = if(access_info.matchHost(whoAccessInfo)) {
|
||||
whoArg.id
|
||||
} else {
|
||||
val (result, accountRef) = client.syncAccountByAcct(access_info, whoAcct)
|
||||
accountRef?.get()?.id ?: return result
|
||||
}
|
||||
whoIdResult = whoId
|
||||
|
||||
return if(access_info.isMisskey) {
|
||||
client.request(
|
||||
when(bMute) {
|
||||
true -> "/api/mute/create"
|
||||
else -> "/api/mute/delete"
|
||||
},
|
||||
access_info.putMisskeyApiToken().apply {
|
||||
put("userId", whoId.toString())
|
||||
}.toPostRequestBuilder()
|
||||
)?.apply {
|
||||
if(jsonObject != null) {
|
||||
// 204 no content
|
||||
|
||||
// update user relation
|
||||
val ur = UserRelation.load(access_info.db_id, whoId)
|
||||
ur.muting = bMute
|
||||
saveUserRelationMisskey(
|
||||
access_info,
|
||||
whoId,
|
||||
TootParser(activity, access_info)
|
||||
)
|
||||
relationResult = ur
|
||||
}
|
||||
}else{
|
||||
val whoId = if(access_info.matchHost(whoAccessInfo)) {
|
||||
whoArg.id
|
||||
} else {
|
||||
val (result, accountRef) = client.syncAccountByAcct(access_info, whoAcct)
|
||||
accountRef?.get()?.id ?: return result
|
||||
}
|
||||
} else {
|
||||
client.request(
|
||||
"/api/v1/accounts/${whoId}/${if(bMute) "mute" else "unmute"}",
|
||||
when {
|
||||
! bMute -> "".toFormRequestBody()
|
||||
else ->
|
||||
jsonObject {
|
||||
put("notifications", bMuteNotification)
|
||||
}
|
||||
.toRequestBody()
|
||||
}.toPost()
|
||||
)?.apply {
|
||||
val jsonObject = jsonObject
|
||||
if(jsonObject != null) {
|
||||
relationResult = saveUserRelation(
|
||||
access_info,
|
||||
parseItem(
|
||||
::TootRelationShip,
|
||||
TootParser(activity, access_info),
|
||||
jsonObject
|
||||
whoIdResult = whoId
|
||||
|
||||
if(access_info.isMisskey) {
|
||||
client.request(
|
||||
when(bMute) {
|
||||
true -> "/api/mute/create"
|
||||
else -> "/api/mute/delete"
|
||||
},
|
||||
access_info.putMisskeyApiToken().apply {
|
||||
put("userId", whoId.toString())
|
||||
}.toPostRequestBuilder()
|
||||
)?.apply {
|
||||
if(jsonObject != null) {
|
||||
// 204 no content
|
||||
|
||||
// update user relation
|
||||
val ur = UserRelation.load(access_info.db_id, whoId)
|
||||
ur.muting = bMute
|
||||
saveUserRelationMisskey(
|
||||
access_info,
|
||||
whoId,
|
||||
TootParser(activity, access_info)
|
||||
)
|
||||
)
|
||||
relationResult = ur
|
||||
}
|
||||
}
|
||||
} else {
|
||||
client.request(
|
||||
"/api/v1/accounts/${whoId}/${if(bMute) "mute" else "unmute"}",
|
||||
when {
|
||||
! bMute -> "".toFormRequestBody()
|
||||
else ->
|
||||
jsonObject {
|
||||
put("notifications", bMuteNotification)
|
||||
}
|
||||
.toRequestBody()
|
||||
}.toPost()
|
||||
)?.apply {
|
||||
val jsonObject = jsonObject
|
||||
if(jsonObject != null) {
|
||||
relationResult = saveUserRelation(
|
||||
access_info,
|
||||
parseItem(
|
||||
::TootRelationShip,
|
||||
TootParser(activity, access_info),
|
||||
jsonObject
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,7 +132,7 @@ object Action_User {
|
||||
|
||||
for(column in App1.getAppState(activity).column_list) {
|
||||
if(column.access_info.isPseudo) {
|
||||
if(relation.muting) {
|
||||
if(relation.muting && column.type != ColumnType.PROFILE) {
|
||||
// ミュートしたユーザの情報はTLから消える
|
||||
column.removeAccountInTimelinePseudo(whoAcct)
|
||||
}
|
||||
|
@ -1,9 +0,0 @@
|
||||
package jp.juggler.subwaytooter.action
|
||||
|
||||
import jp.juggler.subwaytooter.api.TootApiResult
|
||||
import jp.juggler.subwaytooter.table.UserRelation
|
||||
|
||||
class RelationResult {
|
||||
var result : TootApiResult? = null
|
||||
var relation : UserRelation? = null
|
||||
}
|
@ -22,7 +22,7 @@ class TootParser(
|
||||
) {
|
||||
|
||||
val misskeyUserRelationMap = HashMap<EntityId, UserRelation>()
|
||||
val misskeyAccountDetailMap = HashMap<EntityId, TootAccount>()
|
||||
// val misskeyAccountDetailMap = HashMap<EntityId, TootAccount>()
|
||||
|
||||
val apiHost : Host?
|
||||
get() = linkHelper.apiHost
|
||||
|
@ -20,7 +20,7 @@ object OpenSticker {
|
||||
|
||||
private val reColor3 = """#($alnum)($alnum)($alnum)\b"""
|
||||
.asciiPattern(Pattern.CASE_INSENSITIVE)
|
||||
|
||||
|
||||
private fun parseHex(group : String?) : Int = group?.toInt(16) ?: 0
|
||||
|
||||
private fun String.parseColor() : Int? {
|
||||
@ -66,7 +66,6 @@ object OpenSticker {
|
||||
|
||||
val size = array.size
|
||||
|
||||
fun isEmpty() = size == 0
|
||||
fun first() = array.first()
|
||||
fun last() = array.last()
|
||||
|
||||
@ -92,7 +91,6 @@ object OpenSticker {
|
||||
.takeIf { it.isNotEmpty() }
|
||||
?.let { ColorBg(it) }
|
||||
|
||||
|
||||
class Default(
|
||||
val fontColor : Int,
|
||||
val bgColor : ColorBg
|
||||
|
@ -271,7 +271,7 @@ class JsonObject : LinkedHashMap<String, Any?>() {
|
||||
fun optDouble(name : String, defVal : Double = 0.0) = double(name) ?: defVal
|
||||
|
||||
fun stringOrThrow(name : String) = notEmptyOrThrow(name, string(name))
|
||||
fun isNull(name : String) = this[name] == null
|
||||
// fun isNull(name : String) = this[name] == null
|
||||
fun putNotNull(name : String, value : Any?) {
|
||||
if(value != null) put(name, value)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ fun Double.notZero() : Double? = if(this != .0) this else null
|
||||
|
||||
// usage: boolean.truth() ?: fallback()
|
||||
// equivalent: if(this != 0 ) this else null
|
||||
fun Boolean.truth() : Boolean? = if(this) this else null
|
||||
// fun Boolean.truth() : Boolean? = if(this) this else null
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// long
|
||||
|
@ -11,6 +11,7 @@
|
||||
android:layout_height="48dp"
|
||||
android:id="@+id/ivImage"
|
||||
android:background="#888"
|
||||
android:contentDescription="@string/image"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
@ -250,6 +250,7 @@
|
||||
android:layout_marginStart="4dp"
|
||||
android:id="@+id/btnPersonalNotesEdit"
|
||||
android:src="@drawable/ic_edit"
|
||||
android:contentDescription="@string/edit"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.woxthebox.draglistview.swipe.ListSwipeItem
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.woxthebox.draglistview.swipe.ListSwipeItem xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@ -12,28 +11,27 @@
|
||||
android:id="@+id/item_left"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignBottom="@+id/item_layout"
|
||||
android:layout_alignTop="@+id/item_layout"
|
||||
android:layout_alignBottom="@+id/item_layout"
|
||||
android:background="#0088ff"
|
||||
android:gravity="center"
|
||||
android:text="@string/app_name"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"/>
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_right"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignBottom="@+id/item_layout"
|
||||
android:layout_alignTop="@+id/item_layout"
|
||||
android:layout_alignBottom="@+id/item_layout"
|
||||
android:background="?attr/colorColumnListDeleteBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/delete"
|
||||
android:textColor="?attr/colorColumnListDeleteText"
|
||||
android:textSize="20sp"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
/>
|
||||
android:text="@string/delete"
|
||||
android:textColor="?attr/colorColumnListDeleteText"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/item_layout"
|
||||
@ -41,8 +39,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/column_list_selector"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivDragHandle"
|
||||
@ -53,38 +50,37 @@
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_order"
|
||||
android:visibility="gone"
|
||||
app:tint="?attr/colorVectorDrawable"
|
||||
/>
|
||||
app:tint="?attr/colorVectorDrawable" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_weight="1"
|
||||
android:textSize="20sp"
|
||||
android:minHeight="48dp"
|
||||
android:gravity="center_vertical|start"
|
||||
android:minHeight="48dp"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
/>
|
||||
android:textSize="20sp" />
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/ivSpeech"
|
||||
android:src="@drawable/ic_comment"
|
||||
android:tint="?attr/colorVectorDrawable"
|
||||
android:layout_marginEnd="4dp"
|
||||
/>
|
||||
<ImageButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/btnSound"
|
||||
android:src="@drawable/ic_volume_up"
|
||||
android:contentDescription="@string/check_sound"
|
||||
android:tint="?attr/colorVectorDrawable"
|
||||
android:layout_marginEnd="4dp"
|
||||
/>
|
||||
android:contentDescription="@string/speech"
|
||||
android:src="@drawable/ic_comment"
|
||||
android:tint="?attr/colorVectorDrawable" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnSound"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:contentDescription="@string/check_sound"
|
||||
android:src="@drawable/ic_volume_up"
|
||||
android:tint="?attr/colorVectorDrawable" />
|
||||
</LinearLayout>
|
||||
|
||||
</com.woxthebox.draglistview.swipe.ListSwipeItem>
|
||||
|
@ -1059,4 +1059,5 @@
|
||||
<string name="stop_notify_posts_from_this_user">Stop notify posts from this user</string>
|
||||
<string name="gap">Gap</string>
|
||||
<string name="powered_by_open_sticker">Using OpenSticker API.</string>
|
||||
<string name="speech">Speech</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user