Amethyst:
- drop muted-thread reactions/zaps from notifications feed - SecurityFiltersScreen lists muted threads with unmute action - MutedThreadsFeedFilter for settings screen - add Mute thread entry to long-press dropdown - add Mute thread entry to quick-action sheet - add mute-thread string resources - AccountViewModel.muteThread/unmuteThread/isThreadMutedFor - drop muted-thread events before Android push dispatch - FilterByListParams drops muted-thread notes - Account.isAcceptable drops muted-thread notes - Account.muteThread/unmuteThread + resolveThreadRoot + isThreadMuted - MuteListDecryptionCache exposes mutedThreadIdSet helper - MuteListState supports hideThread/showThread - HiddenUsersState exposes muted-thread root ids
This commit is contained in:
@@ -167,6 +167,7 @@ import com.vitorpamplona.quartz.nip03Timestamp.OtsResolver
|
||||
import com.vitorpamplona.quartz.nip04Dm.PrivateDMCache
|
||||
import com.vitorpamplona.quartz.nip04Dm.messages.PrivateDmEvent
|
||||
import com.vitorpamplona.quartz.nip09Deletions.DeletionEvent
|
||||
import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent
|
||||
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
|
||||
import com.vitorpamplona.quartz.nip10Notes.content.findHashtags
|
||||
import com.vitorpamplona.quartz.nip10Notes.content.findNostrUris
|
||||
@@ -2836,6 +2837,21 @@ class Account(
|
||||
sendMyPublicAndPrivateOutbox(muteList.showWords(words))
|
||||
}
|
||||
|
||||
suspend fun muteThread(rootHex: HexKey) {
|
||||
sendMyPublicAndPrivateOutbox(muteList.hideThread(rootHex))
|
||||
}
|
||||
|
||||
suspend fun unmuteThread(rootHex: HexKey) {
|
||||
muteList.showThread(rootHex)?.let { sendMyPublicAndPrivateOutbox(it) }
|
||||
}
|
||||
|
||||
fun resolveThreadRoot(note: Note): HexKey {
|
||||
val ev = note.event
|
||||
return (ev as? BaseThreadedEvent)?.root()?.eventId ?: note.idHex
|
||||
}
|
||||
|
||||
fun isThreadMuted(rootHex: HexKey): Boolean = hiddenUsers.flow.value.isThreadMuted(rootHex)
|
||||
|
||||
suspend fun requestDVMContentDiscovery(
|
||||
dvmPublicKey: User,
|
||||
onReady: (event: NIP90ContentDiscoveryRequestEvent, relays: Set<NormalizedRelayUrl>) -> Unit,
|
||||
@@ -2970,6 +2986,7 @@ class Account(
|
||||
}
|
||||
|
||||
override fun isAcceptable(note: Note): Boolean {
|
||||
if (isThreadMuted(resolveThreadRoot(note))) return false
|
||||
return note.author?.let { isAcceptable(it) } ?: true &&
|
||||
// if user hasn't hided this author
|
||||
isAcceptableDirect(note) &&
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.vitorpamplona.amethyst.commons.model.LiveHiddenUsers
|
||||
import com.vitorpamplona.amethyst.model.AccountSettings
|
||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.EventTag
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.MuteTag
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.UserTag
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.WordTag
|
||||
@@ -56,6 +57,7 @@ class HiddenUsersState(
|
||||
): LiveHiddenUsers {
|
||||
val hiddenUsers = blockList.mapNotNullTo(mutableSetOf()) { if (it is UserTag) it.pubKey else null } + muteList.mapNotNull { if (it is UserTag) it.pubKey else null }
|
||||
val hiddenWords = blockList.mapNotNullTo(mutableSetOf()) { if (it is WordTag) it.word else null } + muteList.mapNotNull { if (it is WordTag) it.word else null }
|
||||
val mutedThreads = muteList.mapNotNullTo(mutableSetOf()) { if (it is EventTag) it.eventId else null }
|
||||
|
||||
return LiveHiddenUsers(
|
||||
showSensitiveContent = showSensitiveContent,
|
||||
@@ -66,6 +68,7 @@ class HiddenUsersState(
|
||||
spammers = transientHiddenUsers,
|
||||
hiddenWords = hiddenWords,
|
||||
maxHashtagLimit = maxHashtagLimit,
|
||||
mutedThreads = mutedThreads,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.model.nip51Lists.muteList
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip51Lists.PrivateTagArrayEventCache
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.MuteListEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.mutedThreadIdSet
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.mutedUserIdSet
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.mutedUsers
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.mutedUsersAndWords
|
||||
@@ -44,6 +45,8 @@ class MuteListDecryptionCache(
|
||||
|
||||
fun cachedWordSet(event: MuteListEvent) = cachedPrivateLists.mergeTagListPrecached(event).mutedWordSet()
|
||||
|
||||
fun cachedThreadIdSet(event: MuteListEvent) = cachedPrivateLists.mergeTagListPrecached(event).mutedThreadIdSet()
|
||||
|
||||
suspend fun mutedUsersAndWords(event: MuteListEvent) = cachedPrivateLists.mergeTagList(event).mutedUsersAndWords()
|
||||
|
||||
suspend fun mutedUsers(event: MuteListEvent) = cachedPrivateLists.mergeTagList(event).mutedUsers()
|
||||
@@ -53,4 +56,6 @@ class MuteListDecryptionCache(
|
||||
suspend fun mutedWords(event: MuteListEvent) = cachedPrivateLists.mergeTagList(event).mutedWords()
|
||||
|
||||
suspend fun mutedWordSet(event: MuteListEvent) = cachedPrivateLists.mergeTagList(event).mutedWordSet()
|
||||
|
||||
suspend fun mutedThreadIdSet(event: MuteListEvent) = cachedPrivateLists.mergeTagList(event).mutedThreadIdSet()
|
||||
}
|
||||
|
||||
+33
@@ -24,8 +24,10 @@ import com.vitorpamplona.amethyst.model.AccountSettings
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.NoteState
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.MuteListEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.EventTag
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.MuteTag
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.UserTag
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.tags.WordTag
|
||||
@@ -139,6 +141,37 @@ class MuteListState(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun hideThread(rootHex: HexKey): MuteListEvent {
|
||||
val muteList = getMuteList()
|
||||
return if (muteList != null) {
|
||||
MuteListEvent.add(
|
||||
earlierVersion = muteList,
|
||||
mute = EventTag(rootHex),
|
||||
isPrivate = true,
|
||||
signer = signer,
|
||||
)
|
||||
} else {
|
||||
MuteListEvent.create(
|
||||
mute = EventTag(rootHex),
|
||||
isPrivate = true,
|
||||
signer = signer,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun showThread(rootHex: HexKey): MuteListEvent? {
|
||||
val muteList = getMuteList()
|
||||
return if (muteList != null) {
|
||||
MuteListEvent.remove(
|
||||
earlierVersion = muteList,
|
||||
mute = EventTag(rootHex),
|
||||
signer = signer,
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun showUsers(pubkeys: List<String>): MuteListEvent? {
|
||||
if (pubkeys.isEmpty()) return null
|
||||
val muteList = getMuteList() ?: return null
|
||||
|
||||
+12
@@ -604,6 +604,9 @@ class EventNotificationConsumer(
|
||||
|
||||
Log.d(TAG) { "Notify ZapRequest $noteZapRequest zapped $noteZapped" }
|
||||
|
||||
// Drop zaps on muted threads, hidden authors, etc.
|
||||
if (!account.isAcceptable(noteZapped)) return
|
||||
|
||||
if ((event.amount ?: BigDecimal.ZERO) < BigDecimal.TEN) return
|
||||
|
||||
Log.d(TAG, "Notify Amount Bigger than 10")
|
||||
@@ -720,6 +723,9 @@ class EventNotificationConsumer(
|
||||
val reactedPostId = event.originalPost().firstOrNull() ?: return
|
||||
val reactedNote = LocalCache.checkGetOrCreateNote(reactedPostId)
|
||||
|
||||
// Drop reactions on muted threads, hidden authors, etc.
|
||||
if (reactedNote != null && !account.isAcceptable(reactedNote)) return
|
||||
|
||||
val author = LocalCache.getOrCreateUser(event.pubKey)
|
||||
val user = author.toBestDisplayName()
|
||||
val userPicture = author.profilePicture()
|
||||
@@ -832,6 +838,9 @@ class EventNotificationConsumer(
|
||||
) {
|
||||
val replyNote = LocalCache.getNoteIfExists(event.id) ?: return
|
||||
|
||||
// Drop events from muted threads, hidden authors, etc.
|
||||
if (!account.isAcceptable(replyNote)) return
|
||||
|
||||
val author = LocalCache.getOrCreateUser(event.pubKey)
|
||||
val user = author.toBestDisplayName()
|
||||
val userPicture = author.profilePicture()
|
||||
@@ -890,6 +899,9 @@ class EventNotificationConsumer(
|
||||
// Age + self-author gates run centrally in dispatchForAccount.
|
||||
val note = LocalCache.getNoteIfExists(event.id) ?: return
|
||||
|
||||
// Drop events from muted threads, hidden authors, etc.
|
||||
if (!account.isAcceptable(note)) return
|
||||
|
||||
val author = LocalCache.getOrCreateUser(event.pubKey)
|
||||
val user = author.toBestDisplayName()
|
||||
val userPicture = author.profilePicture()
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.hashtags.countHashtags
|
||||
import com.vitorpamplona.quartz.nip10Notes.BaseThreadedEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.MuteListEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.peopleList.PeopleListEvent
|
||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
||||
@@ -43,6 +44,12 @@ class FilterByListParams(
|
||||
) {
|
||||
fun isNotHidden(userHex: String) = !(hiddenLists.hiddenUsers.contains(userHex) || hiddenLists.spammers.contains(userHex))
|
||||
|
||||
fun isNotInMutedThread(noteEvent: Event): Boolean {
|
||||
if (hiddenLists.mutedThreads.isEmpty()) return true
|
||||
val rootId = (noteEvent as? BaseThreadedEvent)?.root()?.eventId ?: noteEvent.id
|
||||
return !hiddenLists.mutedThreads.contains(rootId)
|
||||
}
|
||||
|
||||
fun isNotInTheFuture(noteEvent: Event) = noteEvent.createdAt <= now
|
||||
|
||||
fun hasExcessiveHashtags(noteEvent: Event) = hiddenLists.maxHashtagLimit > 0 && noteEvent.countHashtags() > hiddenLists.maxHashtagLimit
|
||||
@@ -84,6 +91,7 @@ class FilterByListParams(
|
||||
comingFrom: List<NormalizedRelayUrl>,
|
||||
) = (applyTopFilter(comingFrom, noteEvent)) &&
|
||||
(isHiddenList || isNotHidden(noteEvent.pubKey)) &&
|
||||
isNotInMutedThread(noteEvent) &&
|
||||
isNotInTheFuture(noteEvent) &&
|
||||
!hasExcessiveHashtags(noteEvent)
|
||||
|
||||
|
||||
@@ -326,6 +326,27 @@ fun CardBody(
|
||||
showBlockAlertDialog.value = true
|
||||
}
|
||||
}
|
||||
|
||||
VerticalDivider(color = primaryLight)
|
||||
|
||||
val isMuted = accountViewModel.isThreadMutedFor(note)
|
||||
NoteQuickActionItem(
|
||||
MaterialSymbols.AutoMirrored.VolumeOff,
|
||||
stringRes(
|
||||
if (isMuted) {
|
||||
R.string.quick_action_unmute_thread
|
||||
} else {
|
||||
R.string.quick_action_mute_thread
|
||||
},
|
||||
),
|
||||
) {
|
||||
if (isMuted) {
|
||||
accountViewModel.unmuteThread(note)
|
||||
} else {
|
||||
accountViewModel.muteThread(note)
|
||||
}
|
||||
onDismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalDivider(
|
||||
|
||||
@@ -335,6 +335,18 @@ fun NoteDropDownMenu(
|
||||
|
||||
// Moderation section
|
||||
M3ActionSection {
|
||||
val isThreadMuted = accountViewModel.isThreadMutedFor(note)
|
||||
M3ActionRow(
|
||||
icon = MaterialSymbols.AutoMirrored.VolumeOff,
|
||||
text = stringRes(if (isThreadMuted) R.string.quick_action_unmute_thread else R.string.quick_action_mute_thread),
|
||||
) {
|
||||
if (isThreadMuted) {
|
||||
accountViewModel.unmuteThread(note)
|
||||
} else {
|
||||
accountViewModel.muteThread(note)
|
||||
}
|
||||
onDismiss()
|
||||
}
|
||||
if (state.isLoggedUser) {
|
||||
M3ActionRow(icon = MaterialSymbols.Delete, text = stringRes(R.string.request_deletion), isDestructive = true) {
|
||||
accountViewModel.delete(note)
|
||||
|
||||
+1
@@ -138,6 +138,7 @@ class AccountFeedContentStates(
|
||||
account.hiddenUsers.flow.collect {
|
||||
dmKnown.invalidateData()
|
||||
dmNew.invalidateData()
|
||||
notifications.invalidateData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -1238,6 +1238,26 @@ class AccountViewModel(
|
||||
|
||||
fun showWords(words: List<String>) = launchSigner { account.showWords(words) }
|
||||
|
||||
fun muteThread(note: Note) {
|
||||
launchSigner {
|
||||
account.muteThread(account.resolveThreadRoot(note))
|
||||
}
|
||||
}
|
||||
|
||||
fun unmuteThread(note: Note) {
|
||||
launchSigner {
|
||||
account.unmuteThread(account.resolveThreadRoot(note))
|
||||
}
|
||||
}
|
||||
|
||||
fun unmuteThread(rootHex: HexKey) {
|
||||
launchSigner {
|
||||
account.unmuteThread(rootHex)
|
||||
}
|
||||
}
|
||||
|
||||
fun isThreadMutedFor(note: Note): Boolean = account.isThreadMuted(account.resolveThreadRoot(note))
|
||||
|
||||
fun createStatus(newStatus: String) = launchSigner { account.createStatus(newStatus) }
|
||||
|
||||
fun updateStatus(
|
||||
|
||||
+14
@@ -225,6 +225,20 @@ class NotificationFeedFilter(
|
||||
}
|
||||
}
|
||||
|
||||
// Drop reactions/zaps/reposts whose target post is in a muted thread.
|
||||
// The inner-note renderer would otherwise show a misleading
|
||||
// "This post was hidden because it mentions your hidden users or words"
|
||||
// placeholder for muted-thread targets (regression from Task 6's
|
||||
// Note.isHiddenFor extension).
|
||||
if (noteEvent is ReactionEvent || noteEvent is LnZapEvent ||
|
||||
noteEvent is RepostEvent || noteEvent is GenericRepostEvent
|
||||
) {
|
||||
val target = it.replyTo?.lastOrNull()
|
||||
if (target != null && account.isThreadMuted(account.resolveThreadRoot(target))) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Chess events bypass the follow filter — opponents may not be followed
|
||||
val isChessEvent = noteEvent is LiveChessGameAcceptEvent || noteEvent is LiveChessMoveEvent
|
||||
|
||||
|
||||
+138
-1
@@ -78,6 +78,8 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.commons.ui.feeds.FeedState
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.WarningType
|
||||
import com.vitorpamplona.amethyst.model.parseWarningType
|
||||
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.account.observeAccountIsHiddenWord
|
||||
@@ -104,6 +106,7 @@ import com.vitorpamplona.amethyst.ui.screen.UserFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.dal.HiddenAccountsFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.dal.HiddenWordsFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.dal.MutedThreadsFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.dal.SpammerAccountsFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.stringRes
|
||||
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||
@@ -141,16 +144,23 @@ fun SecurityFiltersScreen(
|
||||
factory = SpammerAccountsFeedViewModel.Factory(accountViewModel.account),
|
||||
)
|
||||
|
||||
val mutedThreadsFeedViewModel: MutedThreadsFeedViewModel =
|
||||
viewModel(
|
||||
factory = MutedThreadsFeedViewModel.Factory(accountViewModel.account),
|
||||
)
|
||||
|
||||
WatchAccountAndBlockList(accountViewModel = accountViewModel) {
|
||||
hiddenFeedViewModel.invalidateData()
|
||||
spammerFeedViewModel.invalidateData()
|
||||
hiddenWordsFeedViewModel.invalidateData()
|
||||
mutedThreadsFeedViewModel.invalidateData()
|
||||
}
|
||||
|
||||
SecurityFiltersScreen(
|
||||
hiddenFeedViewModel,
|
||||
hiddenWordsFeedViewModel,
|
||||
spammerFeedViewModel,
|
||||
mutedThreadsFeedViewModel,
|
||||
accountViewModel,
|
||||
nav,
|
||||
)
|
||||
@@ -162,6 +172,7 @@ fun SecurityFiltersScreen(
|
||||
hiddenFeedViewModel: HiddenAccountsFeedViewModel,
|
||||
hiddenWordsViewModel: HiddenWordsFeedViewModel,
|
||||
spammerFeedViewModel: SpammerAccountsFeedViewModel,
|
||||
mutedThreadsFeedViewModel: MutedThreadsFeedViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
@@ -175,6 +186,7 @@ fun SecurityFiltersScreen(
|
||||
hiddenWordsViewModel.invalidateData()
|
||||
hiddenFeedViewModel.invalidateData()
|
||||
spammerFeedViewModel.invalidateData()
|
||||
mutedThreadsFeedViewModel.invalidateData()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +194,7 @@ fun SecurityFiltersScreen(
|
||||
onDispose { lifeCycleOwner.lifecycle.removeObserver(observer) }
|
||||
}
|
||||
|
||||
val pagerState = rememberPagerState { 3 }
|
||||
val pagerState = rememberPagerState { 4 }
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
var selectedUsers by remember { mutableStateOf(setOf<String>()) }
|
||||
@@ -258,6 +270,11 @@ fun SecurityFiltersScreen(
|
||||
onClick = { coroutineScope.launch { pagerState.animateScrollToPage(2) } },
|
||||
text = { Text(text = stringRes(R.string.hidden_words)) },
|
||||
)
|
||||
Tab(
|
||||
selected = pagerState.currentPage == 3,
|
||||
onClick = { coroutineScope.launch { pagerState.animateScrollToPage(3) } },
|
||||
text = { Text(text = stringRes(R.string.settings_muted_threads_title)) },
|
||||
)
|
||||
}
|
||||
HorizontalPager(state = pagerState) { page ->
|
||||
when (page) {
|
||||
@@ -289,6 +306,13 @@ fun SecurityFiltersScreen(
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
3 -> {
|
||||
MutedThreadsFeed(
|
||||
viewModel = mutedThreadsFeedViewModel,
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -801,3 +825,116 @@ private fun SelectableHiddenUsersList(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MutedThreadsFeed(
|
||||
viewModel: MutedThreadsFeedViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
RefresheableBox(viewModel, false) {
|
||||
val feedState by viewModel.feedState.feedContent.collectAsStateWithLifecycle()
|
||||
|
||||
CrossfadeIfEnabled(
|
||||
targetState = feedState,
|
||||
animationSpec = tween(durationMillis = 100),
|
||||
accountViewModel = accountViewModel,
|
||||
) { state ->
|
||||
when (state) {
|
||||
is FeedState.Empty -> {
|
||||
Column(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.padding(10.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center,
|
||||
) {
|
||||
Text(text = stringRes(R.string.settings_muted_threads_empty))
|
||||
}
|
||||
}
|
||||
|
||||
is FeedState.FeedError -> {
|
||||
FeedError(state.errorMessage) { viewModel.invalidateData() }
|
||||
}
|
||||
|
||||
is FeedState.Loading -> {
|
||||
LoadingFeed()
|
||||
}
|
||||
|
||||
is FeedState.Loaded -> {
|
||||
val items by state.feed.collectAsStateWithLifecycle()
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
contentPadding = rememberFeedContentPadding(FeedPadding),
|
||||
state = listState,
|
||||
) {
|
||||
itemsIndexed(items.list, key = { _, item -> item.idHex }) { _, note ->
|
||||
MutedThreadRow(note = note, accountViewModel = accountViewModel)
|
||||
HorizontalDivider(thickness = DividerThickness)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MutedThreadRow(
|
||||
note: Note,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
val event = note.event
|
||||
|
||||
Row(
|
||||
modifier =
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = Size15dp, vertical = Size10dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
if (event == null) {
|
||||
Text(
|
||||
text = stringRes(R.string.settings_muted_threads_unknown, note.idHex.take(12) + "…"),
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
} else {
|
||||
val authorName = note.author?.metadataOrNull()?.bestName()
|
||||
if (authorName != null) {
|
||||
Text(
|
||||
text = authorName,
|
||||
fontWeight = FontWeight.Bold,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text =
|
||||
event.content
|
||||
.lines()
|
||||
.firstOrNull()
|
||||
?.trim() ?: "",
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier.padding(start = 3.dp),
|
||||
onClick = { accountViewModel.unmuteThread(note) },
|
||||
shape = ButtonBorder,
|
||||
colors =
|
||||
ButtonDefaults.buttonColors(
|
||||
containerColor = MaterialTheme.colorScheme.primary,
|
||||
),
|
||||
contentPadding = ButtonPadding,
|
||||
) {
|
||||
Text(text = stringRes(R.string.action_unmute), color = Color.White)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.dal
|
||||
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.ui.dal.FeedFilter
|
||||
|
||||
class MutedThreadsFeedFilter(
|
||||
val account: Account,
|
||||
) : FeedFilter<Note>() {
|
||||
override fun feedKey(): String = account.userProfile().pubkeyHex
|
||||
|
||||
override fun showHiddenKey(): Boolean = true
|
||||
|
||||
override fun feed(): List<Note> =
|
||||
account.hiddenUsers.flow.value.mutedThreads
|
||||
.mapNotNull { LocalCache.getNoteIfExists(it) ?: LocalCache.getOrCreateNote(it) }
|
||||
.sortedByDescending { it.createdAt() }
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.dal
|
||||
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.ui.screen.AndroidFeedViewModel
|
||||
|
||||
@Stable
|
||||
class MutedThreadsFeedViewModel(
|
||||
val account: Account,
|
||||
) : AndroidFeedViewModel(MutedThreadsFeedFilter(account)) {
|
||||
class Factory(
|
||||
val account: Account,
|
||||
) : ViewModelProvider.Factory {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = MutedThreadsFeedViewModel(account) as T
|
||||
}
|
||||
}
|
||||
@@ -401,6 +401,8 @@
|
||||
<string name="quick_action_block_dialog_btn">Block</string>
|
||||
<string name="quick_action_delete_dialog_btn">Delete</string>
|
||||
<string name="quick_action_block">Block</string>
|
||||
<string name="quick_action_mute_thread">Mute thread</string>
|
||||
<string name="quick_action_unmute_thread">Unmute thread</string>
|
||||
<string name="quick_action_report">Report</string>
|
||||
<string name="quick_action_delete_button">Delete</string>
|
||||
<string name="quick_action_dont_show_again_button">Don\'t show again</string>
|
||||
@@ -1449,6 +1451,7 @@
|
||||
|
||||
<string name="muted_button">Muted. Click to unmute</string>
|
||||
<string name="mute_button">Sound on. Click to mute</string>
|
||||
<string name="action_unmute">Unmute</string>
|
||||
<string name="skip_back">Skip back %d seconds</string>
|
||||
<string name="skip_forward">Skip forward %d seconds</string>
|
||||
<string name="picture_in_picture">Picture-in-Picture</string>
|
||||
@@ -1606,6 +1609,9 @@
|
||||
|
||||
<string name="hidden_words">Hidden Words</string>
|
||||
<string name="hide_new_word_label">Hide new word or sentence</string>
|
||||
<string name="settings_muted_threads_title">Muted threads</string>
|
||||
<string name="settings_muted_threads_empty">No muted threads</string>
|
||||
<string name="settings_muted_threads_unknown">Unknown thread · %1$s</string>
|
||||
<string name="automatically_show_profile_picture">Profile Picture</string>
|
||||
<string name="automatically_show_profile_picture_description">Show Profile pictures</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user