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 1 commit
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 @@ -361,6 +361,11 @@ class ThreadFragment : Fragment() {
return@observe
}

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

binding.iconFavorite.apply {
setIconResource(if (thread.isFavorite) R.drawable.ic_star_filled else R.drawable.ic_star)
val color = if (thread.isFavorite) {
Expand All @@ -378,11 +383,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 shouldMarkThreadAsSeen: Boolean? = null
var superCollapsedBlock: SuperCollapsedBlock? = null

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

threadState.shouldMarkThreadAsSeen = thread.unseenMessagesCount > 0
if (threadState.shouldMarkThreadAsSeen == null) threadState.shouldMarkThreadAsSeen = thread.unseenMessagesCount > 0

emit(thread)
}

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

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