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)
// 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!)
}
}
}
@@ -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)