diff --git a/nirvana-ios/Services/AuthSessionStore.swift b/nirvana-ios/Services/AuthSessionStore.swift index 1eb2b23..f0f25b2 100644 --- a/nirvana-ios/Services/AuthSessionStore.swift +++ b/nirvana-ios/Services/AuthSessionStore.swift @@ -386,25 +386,23 @@ extension AuthSessionStore { let currMessage = try queryDocumentSnapshot.data(as: Message.self) // print("new message received! \(currMessage!.sentTimestamp)") - DispatchQueue.main.async { - if currMessage != nil { // not really possible but just check - // if the user doesn't exist for the dictionary, then add it - // this means it's most likely someone new (never had user_friend relationship before) messaging for the user's inbox - // TODO: prolly want to make a call to get this sender user details for the inbox, but they should either be in the friendsDict or their are not a friend so won't be there - // also add in any messages where I am the sender - if currMessage!.senderId == currUserId { // if I am the sender - if self.relevantMessagesByUserDict[currMessage!.receiverId] == nil { - self.relevantMessagesByUserDict[currMessage!.receiverId] = [currMessage!] - } else { - self.relevantMessagesByUserDict[currMessage!.receiverId]?.append(currMessage!) - } + if currMessage != nil { // not really possible but just check + // if the user doesn't exist for the dictionary, then add it + // this means it's most likely someone new (never had user_friend relationship before) messaging for the user's inbox + // TODO: prolly want to make a call to get this sender user details for the inbox, but they should either be in the friendsDict or their are not a friend so won't be there + // also add in any messages where I am the sender + if currMessage!.senderId == currUserId { // if I am the sender + if self.relevantMessagesByUserDict[currMessage!.receiverId] == nil { + self.relevantMessagesByUserDict[currMessage!.receiverId] = [currMessage!] + } else { + self.relevantMessagesByUserDict[currMessage!.receiverId]?.append(currMessage!) } - else { // if I am receiving - if self.relevantMessagesByUserDict[currMessage!.senderId] == nil { - self.relevantMessagesByUserDict[currMessage!.senderId] = [currMessage!] - } else { - self.relevantMessagesByUserDict[currMessage!.senderId]?.append(currMessage!) - } + } + else { // if I am receiving + if self.relevantMessagesByUserDict[currMessage!.senderId] == nil { + self.relevantMessagesByUserDict[currMessage!.senderId] = [currMessage!] + } else { + self.relevantMessagesByUserDict[currMessage!.senderId]?.append(currMessage!) } } } diff --git a/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift b/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift index 746f69e..7881a3f 100644 --- a/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift +++ b/nirvana-ios/Views/InnerCircle/InnerCircleViewModel.swift @@ -282,8 +282,6 @@ extension InnerCircleViewModel { return } - print("current state of cached audio files: \(self.cachedPlayerItemsDict)") - // start playing if there are messages to listen to print("have \(AVPlayerItems.count) messages to play") @@ -308,6 +306,11 @@ extension InnerCircleViewModel { totalDuration = CMTimeAdd(totalDuration, item.asset.duration) } + // TODO: not hitting the last one/100% + // it either plays on time or there is a little lag on multiple items... + // offset this by adding 1 when it reaches the totalDuration as it's longer + totalDuration = CMTimeSubtract(totalDuration, CMTimeMakeWithSeconds(1, preferredTimescale: 1)) + var times = [NSValue]() // Set initial time to zero var currentTime = CMTime.zero @@ -320,8 +323,9 @@ extension InnerCircleViewModel { times.append(NSValue(time: currentTime)) } + + // Add time observer. Observe boundary time changes on the main queue. - // TODO: not hitting the last one/100% self.queuePlayer.addBoundaryTimeObserver(forTimes: times, queue: .main) { [weak self] in // Update UI self?.messagesListeningProgress += Float(Self.multiplier)