Tweaked the logic so the unreadMarker will appear via global search

pull/751/head
Morgan Pretty 2 years ago
parent f07313c7ac
commit 54fc75cd85

@ -63,7 +63,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
init(threadId: String, threadVariant: SessionThread.Variant, focusedInteractionInfo: Interaction.TimestampInfo?) { init(threadId: String, threadVariant: SessionThread.Variant, focusedInteractionInfo: Interaction.TimestampInfo?) {
typealias InitialData = ( typealias InitialData = (
targetInteractionInfo: Interaction.TimestampInfo?, initialUnreadInteractionInfo: Interaction.TimestampInfo?,
threadIsBlocked: Bool, threadIsBlocked: Bool,
currentUserIsClosedGroupMember: Bool?, currentUserIsClosedGroupMember: Bool?,
openGroupPermissions: OpenGroup.Permissions?, openGroupPermissions: OpenGroup.Permissions?,
@ -76,15 +76,13 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
// If we have a specified 'focusedInteractionInfo' then use that, otherwise retrieve the oldest // If we have a specified 'focusedInteractionInfo' then use that, otherwise retrieve the oldest
// unread interaction and start focused around that one // unread interaction and start focused around that one
let targetInteractionInfo: Interaction.TimestampInfo? = (focusedInteractionInfo != nil ? focusedInteractionInfo : let initialUnreadInteractionInfo: Interaction.TimestampInfo? = try Interaction
try Interaction .select(.id, .timestampMs)
.select(.id, .timestampMs) .filter(interaction[.wasRead] == false)
.filter(interaction[.wasRead] == false) .filter(interaction[.threadId] == threadId)
.filter(interaction[.threadId] == threadId) .order(interaction[.timestampMs].asc)
.order(interaction[.timestampMs].asc) .asRequest(of: Interaction.TimestampInfo.self)
.asRequest(of: Interaction.TimestampInfo.self) .fetchOne(db)
.fetchOne(db)
)
let threadIsBlocked: Bool = (threadVariant != .contact ? false : let threadIsBlocked: Bool = (threadVariant != .contact ? false :
try Contact try Contact
.filter(id: threadId) .filter(id: threadId)
@ -114,7 +112,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
) )
return ( return (
targetInteractionInfo, initialUnreadInteractionInfo,
threadIsBlocked, threadIsBlocked,
currentUserIsClosedGroupMember, currentUserIsClosedGroupMember,
openGroupPermissions, openGroupPermissions,
@ -124,14 +122,9 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
self.threadId = threadId self.threadId = threadId
self.initialThreadVariant = threadVariant self.initialThreadVariant = threadVariant
self.focusedInteractionInfo = initialData?.targetInteractionInfo self.focusedInteractionInfo = (focusedInteractionInfo ?? initialData?.initialUnreadInteractionInfo)
self.focusBehaviour = (focusedInteractionInfo == nil ? .none : .highlight) self.focusBehaviour = (focusedInteractionInfo == nil ? .none : .highlight)
self.initialUnreadInteractionId = (focusedInteractionInfo == nil ? self.initialUnreadInteractionId = initialData?.initialUnreadInteractionInfo?.id
// If we didn't provide a 'focusedInteractionInfo' then 'initialData?.targetInteractionInfo?.id' will be
// the oldest unread interaction
initialData?.targetInteractionInfo?.id :
nil
)
self.threadData = SessionThreadViewModel( self.threadData = SessionThreadViewModel(
threadId: threadId, threadId: threadId,
threadVariant: threadVariant, threadVariant: threadVariant,
@ -159,7 +152,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
DispatchQueue.global(qos: .userInitiated).async { [weak self] in DispatchQueue.global(qos: .userInitiated).async { [weak self] in
// If we don't have a `initialFocusedInfo` then default to `.pageBefore` (it'll query // If we don't have a `initialFocusedInfo` then default to `.pageBefore` (it'll query
// from a `0` offset) // from a `0` offset)
guard let initialFocusedInfo: Interaction.TimestampInfo = initialData?.targetInteractionInfo else { guard let initialFocusedInfo: Interaction.TimestampInfo = (focusedInteractionInfo ?? initialData?.initialUnreadInteractionInfo) else {
self?.pagedDataObserver?.load(.pageBefore) self?.pagedDataObserver?.load(.pageBefore)
return return
} }
@ -683,6 +676,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
// Then setup the state for the new audio // Then setup the state for the new audio
currentPlayingInteraction.mutate { $0 = viewModel.id } currentPlayingInteraction.mutate { $0 = viewModel.id }
let currentPlaybackTime: TimeInterval? = playbackInfo.wrappedValue[viewModel.id]?.progress
audioPlayer.mutate { [weak self] player in audioPlayer.mutate { [weak self] player in
// Note: We clear the delegate and explicitly set to nil here as when the OWSAudioPlayer // Note: We clear the delegate and explicitly set to nil here as when the OWSAudioPlayer
// gets deallocated it triggers state changes which cause UI bugs when auto-playing // gets deallocated it triggers state changes which cause UI bugs when auto-playing
@ -695,7 +689,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
delegate: self delegate: self
) )
audioPlayer.play() audioPlayer.play()
audioPlayer.setCurrentTime(playbackInfo.wrappedValue[viewModel.id]?.progress ?? 0) audioPlayer.setCurrentTime(currentPlaybackTime ?? 0)
player = audioPlayer player = audioPlayer
} }
} }

Loading…
Cancel
Save