Skip to content

Commit

Permalink
Merge pull request #1179 from davotoula/1172-hide-drafts-from-other-a…
Browse files Browse the repository at this point in the history
…ccounts-on-device

Hide drafts from other accounts on device
  • Loading branch information
vitorpamplona authored Nov 18, 2024
2 parents 3a566da + 4a590d6 commit accde86
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.ThreadAssembler
import com.vitorpamplona.amethyst.model.ThreadLevelCalculator
import com.vitorpamplona.quartz.utils.TimeUtils
import kotlinx.collections.immutable.toImmutableSet

@Immutable
class ThreadFeedFilter(
val account: Account,
val noteId: String,
private val noteId: String,
) : FeedFilter<Note>() {
override fun feedKey(): String = noteId

Expand All @@ -40,7 +41,14 @@ class ThreadFeedFilter(
val followingKeySet = account.liveKind3Follows.value.authors
val eventsToWatch = ThreadAssembler().findThreadFor(noteId) ?: return emptyList()

val eventsInHex = eventsToWatch.allNotes.map { it.idHex }.toSet()
// Filter out drafts made by other accounts on device
val filteredEvents =
eventsToWatch.allNotes
.filter { !it.isDraft() || (it.author?.pubkeyHex == account.userProfile().pubkeyHex) }
.toImmutableSet()
val filteredThreadInfo = ThreadAssembler.ThreadInfo(eventsToWatch.root, filteredEvents)

val eventsInHex = filteredThreadInfo.allNotes.map { it.idHex }.toSet()
val now = TimeUtils.now()

// Currently orders by date of each event, descending, at each level of the reply stack
Expand All @@ -57,6 +65,6 @@ class ThreadFeedFilter(
).signature
}

return eventsToWatch.allNotes.sortedWith(order)
return filteredThreadInfo.allNotes.sortedWith(order)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ fun RenderThreadFeed(
// In that case, this screen will open with 0-1 items, and the scrollToItem below
// will not change the state of the screen (too few items, scroll is not available)
// as the app loads the reaming of the thread the position of the reply changes
// and becuase there wasn't a possibility to scroll before and now there is one,
// and because there wasn't a possibility to scroll before and now there is one,
// the screen stays at the top. Once the thread has enough replies, the lazy column
// updates with new items correctly. It just needs a few items to start the scrool.
// updates with new items correctly. It just needs a few items to start the scroll.
//
// This hack allows the list 1 second to fill up with more
// records before setting up the position on the feed.
Expand Down Expand Up @@ -274,7 +274,6 @@ fun RenderThreadFeed(
val modifier =
Modifier
.drawReplyLevel(
note = item,
level = level,
color = MaterialTheme.colorScheme.placeholderText,
selected =
Expand Down Expand Up @@ -322,7 +321,6 @@ fun RenderThreadFeed(

// Creates a Zebra pattern where each bar is a reply level.
fun Modifier.drawReplyLevel(
note: Note,
level: State<Int>,
color: Color,
selected: Color,
Expand Down Expand Up @@ -484,14 +482,11 @@ private fun FullBleedNoteCompose(

Spacer(modifier = Modifier.height(10.dp))

if (noteEvent is BadgeDefinitionEvent) {
BadgeDisplay(baseNote = baseNote)
} else if (noteEvent is LongTextNoteEvent) {
RenderLongFormHeaderForThread(noteEvent)
} else if (noteEvent is WikiNoteEvent) {
RenderWikiHeaderForThread(noteEvent, accountViewModel, nav)
} else if (noteEvent is ClassifiedsEvent) {
RenderClassifiedsReaderForThread(noteEvent, baseNote, accountViewModel, nav)
when (noteEvent) {
is BadgeDefinitionEvent -> BadgeDisplay(baseNote = baseNote)
is LongTextNoteEvent -> RenderLongFormHeaderForThread(noteEvent)
is WikiNoteEvent -> RenderWikiHeaderForThread(noteEvent, accountViewModel, nav)
is ClassifiedsEvent -> RenderClassifiedsReaderForThread(noteEvent, baseNote, accountViewModel, nav)
}

Row(
Expand All @@ -512,11 +507,11 @@ private fun FullBleedNoteCompose(
nav = nav,
)
} else if (noteEvent is VideoEvent) {
VideoDisplay(baseNote, false, true, backgroundColor, false, accountViewModel, nav)
VideoDisplay(baseNote, makeItShort = false, canPreview = true, backgroundColor = backgroundColor, isFiniteHeight = false, accountViewModel = accountViewModel, nav = nav)
} else if (noteEvent is FileHeaderEvent) {
FileHeaderDisplay(baseNote, true, false, accountViewModel)
FileHeaderDisplay(baseNote, roundedCorner = true, isFiniteHeight = false, accountViewModel = accountViewModel)
} else if (noteEvent is FileStorageHeaderEvent) {
FileStorageHeaderDisplay(baseNote, true, false, accountViewModel)
FileStorageHeaderDisplay(baseNote, roundedCorner = true, isFiniteHeight = false, accountViewModel = accountViewModel)
} else if (noteEvent is PeopleListEvent) {
DisplayPeopleList(baseNote, backgroundColor, accountViewModel, nav)
} else if (noteEvent is AudioTrackEvent) {
Expand Down Expand Up @@ -563,9 +558,9 @@ private fun FullBleedNoteCompose(
} else if (noteEvent is GitRepositoryEvent) {
RenderGitRepositoryEvent(baseNote, accountViewModel, nav)
} else if (noteEvent is GitPatchEvent) {
RenderGitPatchEvent(baseNote, false, true, quotesLeft = 3, backgroundColor, accountViewModel, nav)
RenderGitPatchEvent(baseNote, makeItShort = false, canPreview = true, quotesLeft = 3, backgroundColor = backgroundColor, accountViewModel = accountViewModel, nav = nav)
} else if (noteEvent is GitIssueEvent) {
RenderGitIssueEvent(baseNote, false, true, quotesLeft = 3, backgroundColor, accountViewModel, nav)
RenderGitIssueEvent(baseNote, makeItShort = false, canPreview = true, quotesLeft = 3, backgroundColor = backgroundColor, accountViewModel = accountViewModel, nav = nav)
} else if (noteEvent is AppDefinitionEvent) {
RenderAppDefinition(baseNote, accountViewModel, nav)
} else if (noteEvent is DraftEvent) {
Expand Down Expand Up @@ -662,9 +657,8 @@ private fun FullBleedNoteCompose(
}
}

val noteEvent = baseNote.event
val zapSplits = remember(noteEvent) { noteEvent?.hasZapSplitSetup() ?: false }
if (zapSplits && noteEvent != null) {
val zapSplits = remember(noteEvent) { noteEvent.hasZapSplitSetup() }
if (zapSplits) {
Spacer(modifier = DoubleVertSpacer)
Row(
modifier = Modifier.padding(horizontal = 12.dp),
Expand All @@ -673,7 +667,7 @@ private fun FullBleedNoteCompose(
}
}

ReactionsRow(baseNote, true, true, editState, accountViewModel, nav)
ReactionsRow(baseNote, showReactionDetail = true, addPadding = true, editState = editState, accountViewModel = accountViewModel, nav = nav)
}
}

Expand Down Expand Up @@ -925,14 +919,14 @@ private fun RenderWikiHeaderForThreadPreview() {
RenderWikiHeaderForThread(noteEvent = event, accountViewModel = accountViewModel, nav)
RenderTextEvent(
baseNote!!,
false,
true,
makeItShort = false,
canPreview = true,
quotesLeft = 3,
unPackReply = false,
backgroundColor,
editState,
accountViewModel,
nav,
backgroundColor = backgroundColor,
editState = editState,
accountViewModel = accountViewModel,
nav = nav,
)
}
}
Expand Down

0 comments on commit accde86

Please sign in to comment.