Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening a Thread now correctly marks it as read #1733

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ class ThreadFragment : Fragment() {
mainViewModel.toggleLightThemeForMessage.observe(viewLifecycleOwner, threadAdapter::toggleLightMode)
}

private fun observeThreadLive() = with(threadViewModel) {
private fun observeThreadLive() {

threadLive.observe(viewLifecycleOwner) { thread ->
threadViewModel.threadLive.observe(viewLifecycleOwner) { thread ->

if (thread == null) {
twoPaneViewModel.closeThread()
Expand All @@ -378,11 +378,6 @@ class ThreadFragment : Fragment() {
messagesLive.observe(viewLifecycleOwner) { (items, messagesToFetch) ->
SentryLog.i("UI", "Received ${items.count()} messages")

if (threadState.shouldMarkThreadAsSeen) {
threadState.shouldMarkThreadAsSeen = false
markThreadAsSeen()
}

if (items.isEmpty()) {
mainViewModel.deletedMessages.value = deletedMessagesUids
twoPaneViewModel.closeThread()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ThreadState {
val isCalendarEventExpandedMap: MutableMap<String, Boolean> = mutableMapOf()
val treatedMessagesForCalendarEvent: MutableSet<String> = mutableSetOf()
val cachedSplitBodies: MutableMap<String, SplitBody> = mutableMapOf()
var shouldMarkThreadAsSeen: Boolean = false
var hasBeenMarkedAsSeen: Boolean = false
var superCollapsedBlock: SuperCollapsedBlock? = null

fun reset() {
Expand All @@ -48,7 +48,7 @@ class ThreadState {
isCalendarEventExpandedMap.clear()
treatedMessagesForCalendarEvent.clear()
cachedSplitBodies.clear()
shouldMarkThreadAsSeen = false
hasBeenMarkedAsSeen = false
superCollapsedBlock = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,16 @@ class ThreadViewModel @Inject constructor(
}
}

threadState.shouldMarkThreadAsSeen = thread.unseenMessagesCount > 0
if (!threadState.hasBeenMarkedAsSeen) {
threadState.hasBeenMarkedAsSeen = true
if (thread.unseenMessagesCount > 0) markThreadAsSeen(thread)
}

emit(thread)
}

fun markThreadAsSeen() = viewModelScope.launch(ioCoroutineContext) {
threadLive.value?.let { sharedUtils.markAsSeen(mailbox, listOf(it)) }
private fun markThreadAsSeen(thread: Thread) = viewModelScope.launch(ioCoroutineContext) {
sharedUtils.markAsSeen(mailbox, listOf(thread))
}

private fun sendMatomoAndSentryAboutThreadMessagesCount(thread: Thread) {
Expand Down
Loading