From f1b3faf85f30f482f4cce55108d9bf2db35c2dec Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Mon, 24 Apr 2023 12:09:34 +0200 Subject: [PATCH] Show the follower's bio/note in a "followed you" notification (#3281) This makes the notification view for a follow request contain more info about the new follower, and makes the layout (of their name / username) consistent with other notifications that show names/usernames. --- app/lint.xml | 2 +- .../conversation/ConversationEntity.kt | 1 + .../notifications/FollowViewHolder.kt | 7 ++++++ .../timeline/TimelineTypeMappers.kt | 1 + .../tusky/entity/TimelineAccount.kt | 1 + app/src/main/res/layout/item_follow.xml | 22 ++++++++++++++++--- .../tusky/BottomSheetActivityTest.kt | 1 + .../keylesspalace/tusky/MainActivityTest.kt | 1 + .../tusky/StatusComparisonTest.kt | 4 ++-- .../tusky/components/timeline/StatusMocker.kt | 2 +- 10 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/lint.xml b/app/lint.xml index 0b77136c..1e7d6f84 100644 --- a/app/lint.xml +++ b/app/lint.xml @@ -29,7 +29,7 @@ Disable these for the time being. --> - + diff --git a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt index dae0f163..9c563191 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationEntity.kt @@ -64,6 +64,7 @@ data class ConversationAccountEntity( localUsername = localUsername, username = username, displayName = displayName, + note = "", url = "", avatar = avatar, emojis = emojis diff --git a/app/src/main/java/com/keylesspalace/tusky/components/notifications/FollowViewHolder.kt b/app/src/main/java/com/keylesspalace/tusky/components/notifications/FollowViewHolder.kt index 80cfeded..8cc93187 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/notifications/FollowViewHolder.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/notifications/FollowViewHolder.kt @@ -25,6 +25,7 @@ import com.keylesspalace.tusky.entity.TimelineAccount import com.keylesspalace.tusky.util.StatusDisplayOptions import com.keylesspalace.tusky.util.emojify import com.keylesspalace.tusky.util.loadAvatar +import com.keylesspalace.tusky.util.parseAsMastodonHtml import com.keylesspalace.tusky.util.unicodeWrap import com.keylesspalace.tusky.viewdata.NotificationViewData @@ -92,6 +93,12 @@ class FollowViewHolder( avatarRadius42dp, animateAvatars ) + + binding.notificationAccountNote.text = account.note.parseAsMastodonHtml().emojify( + account.emojis, + binding.notificationAccountNote, + animateEmojis + ) } private fun setupButtons(listener: NotificationActionListener, accountId: String) { diff --git a/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt b/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt index 04be236e..bdb3d64d 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/timeline/TimelineTypeMappers.kt @@ -63,6 +63,7 @@ fun TimelineAccountEntity.toAccount(gson: Gson): TimelineAccount { localUsername = localUsername, username = username, displayName = displayName, + note = "", url = url, avatar = avatar, bot = bot, diff --git a/app/src/main/java/com/keylesspalace/tusky/entity/TimelineAccount.kt b/app/src/main/java/com/keylesspalace/tusky/entity/TimelineAccount.kt index ba57abb9..f801d496 100644 --- a/app/src/main/java/com/keylesspalace/tusky/entity/TimelineAccount.kt +++ b/app/src/main/java/com/keylesspalace/tusky/entity/TimelineAccount.kt @@ -28,6 +28,7 @@ data class TimelineAccount( @SerializedName("display_name") val displayName: String?, // should never be null per Api definition, but some servers break the contract val url: String, val avatar: String, + val note: String, val bot: Boolean = false, val emojis: List? = emptyList() // nullable for backward compatibility ) { diff --git a/app/src/main/res/layout/item_follow.xml b/app/src/main/res/layout/item_follow.xml index 204c7dd4..bbd2b4e6 100644 --- a/app/src/main/res/layout/item_follow.xml +++ b/app/src/main/res/layout/item_follow.xml @@ -47,12 +47,14 @@ android:layout_marginTop="6dp" android:ellipsize="end" android:maxLines="1" + android:paddingEnd="@dimen/status_display_name_padding_end" android:textColor="?android:textColorPrimary" android:textSize="?attr/status_text_medium" android:textStyle="normal|bold" app:layout_constraintStart_toEndOf="@id/notification_avatar" app:layout_constraintTop_toBottomOf="@+id/notification_text" - tools:text="Test User" /> + tools:text="Test User" + tools:ignore="RtlSymmetry" /> + + diff --git a/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt b/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt index bbc5c930..18db7b63 100644 --- a/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt +++ b/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt @@ -56,6 +56,7 @@ class BottomSheetActivityTest { localUsername = "admin", username = "admin", displayName = "Ad Min", + note = "This is their bio", url = "http://mastodon.foo.bar/@User", avatar = "" ) diff --git a/app/src/test/java/com/keylesspalace/tusky/MainActivityTest.kt b/app/src/test/java/com/keylesspalace/tusky/MainActivityTest.kt index 73ce0c1f..6af56fd6 100644 --- a/app/src/test/java/com/keylesspalace/tusky/MainActivityTest.kt +++ b/app/src/test/java/com/keylesspalace/tusky/MainActivityTest.kt @@ -100,6 +100,7 @@ class MainActivityTest { localUsername = "connyduck", username = "connyduck@mastodon.example", displayName = "Conny Duck", + note = "This is their bio", url = "https://mastodon.example/@ConnyDuck", avatar = "https://mastodon.example/system/accounts/avatars/000/150/486/original/ab27d7ddd18a10ea.jpg" ), diff --git a/app/src/test/java/com/keylesspalace/tusky/StatusComparisonTest.kt b/app/src/test/java/com/keylesspalace/tusky/StatusComparisonTest.kt index 3086036a..1498d3d7 100644 --- a/app/src/test/java/com/keylesspalace/tusky/StatusComparisonTest.kt +++ b/app/src/test/java/com/keylesspalace/tusky/StatusComparisonTest.kt @@ -33,8 +33,8 @@ class StatusComparisonTest { } @Test - fun `accounts with different notes in json - should be equal because notes are not relevant for timelines`() { - assertEquals(createStatus(note = "Test"), createStatus(note = "Test 123456")) + fun `accounts with different notes in json - should not be equal`() { + assertNotEquals(createStatus(note = "Test"), createStatus(note = "Test 123456")) } private val gson = Gson() diff --git a/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt b/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt index 28288497..839b16df 100644 --- a/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt +++ b/app/src/test/java/com/keylesspalace/tusky/components/timeline/StatusMocker.kt @@ -5,7 +5,6 @@ import com.keylesspalace.tusky.db.TimelineStatusWithAccount import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.entity.TimelineAccount import com.keylesspalace.tusky.viewdata.StatusViewData -import java.util.ArrayList import java.util.Date private val fixedDate = Date(1638889052000) @@ -26,6 +25,7 @@ fun mockStatus( localUsername = "connyduck", username = "connyduck@mastodon.example", displayName = "Conny Duck", + note = "This is their bio", url = "https://mastodon.example/@ConnyDuck", avatar = "https://mastodon.example/system/accounts/avatars/000/150/486/original/ab27d7ddd18a10ea.jpg" ),