good enough fix for the problems

This commit is contained in:
talksik
2022-01-03 19:45:35 -08:00
parent 4f4e5ba397
commit e1735bb8ed
2 changed files with 23 additions and 21 deletions
+16 -18
View File
@@ -386,25 +386,23 @@ extension AuthSessionStore {
let currMessage = try queryDocumentSnapshot.data(as: Message.self) let currMessage = try queryDocumentSnapshot.data(as: Message.self)
// print("new message received! \(currMessage!.sentTimestamp)") // print("new message received! \(currMessage!.sentTimestamp)")
DispatchQueue.main.async { if currMessage != nil { // not really possible but just check
if currMessage != nil { // not really possible but just check // if the user doesn't exist for the dictionary, then add it
// 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
// 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
// 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
// also add in any messages where I am the sender if currMessage!.senderId == currUserId { // if I am the sender
if currMessage!.senderId == currUserId { // if I am the sender if self.relevantMessagesByUserDict[currMessage!.receiverId] == nil {
if self.relevantMessagesByUserDict[currMessage!.receiverId] == nil { self.relevantMessagesByUserDict[currMessage!.receiverId] = [currMessage!]
self.relevantMessagesByUserDict[currMessage!.receiverId] = [currMessage!] } else {
} else { self.relevantMessagesByUserDict[currMessage!.receiverId]?.append(currMessage!)
self.relevantMessagesByUserDict[currMessage!.receiverId]?.append(currMessage!)
}
} }
else { // if I am receiving }
if self.relevantMessagesByUserDict[currMessage!.senderId] == nil { else { // if I am receiving
self.relevantMessagesByUserDict[currMessage!.senderId] = [currMessage!] if self.relevantMessagesByUserDict[currMessage!.senderId] == nil {
} else { self.relevantMessagesByUserDict[currMessage!.senderId] = [currMessage!]
self.relevantMessagesByUserDict[currMessage!.senderId]?.append(currMessage!) } else {
} self.relevantMessagesByUserDict[currMessage!.senderId]?.append(currMessage!)
} }
} }
} }
@@ -282,8 +282,6 @@ extension InnerCircleViewModel {
return return
} }
print("current state of cached audio files: \(self.cachedPlayerItemsDict)")
// start playing if there are messages to listen to // start playing if there are messages to listen to
print("have \(AVPlayerItems.count) messages to play") print("have \(AVPlayerItems.count) messages to play")
@@ -308,6 +306,11 @@ extension InnerCircleViewModel {
totalDuration = CMTimeAdd(totalDuration, item.asset.duration) 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]() var times = [NSValue]()
// Set initial time to zero // Set initial time to zero
var currentTime = CMTime.zero var currentTime = CMTime.zero
@@ -320,8 +323,9 @@ extension InnerCircleViewModel {
times.append(NSValue(time: currentTime)) times.append(NSValue(time: currentTime))
} }
// Add time observer. Observe boundary time changes on the main queue. // 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 self.queuePlayer.addBoundaryTimeObserver(forTimes: times, queue: .main) { [weak self] in
// Update UI // Update UI
self?.messagesListeningProgress += Float(Self.multiplier) self?.messagesListeningProgress += Float(Self.multiplier)