decent place but still buggy
This commit is contained in:
@@ -380,10 +380,11 @@ extension AuthSessionStore {
|
||||
//optimize this? but also saving on memory and same db reads
|
||||
self.relevantMessagesByUserDict.removeAll()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.messagesArr = documents.compactMap { (queryDocumentSnapshot) -> Message? in
|
||||
do {
|
||||
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
|
||||
@@ -406,8 +407,6 @@ extension AuthSessionStore {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.objectWillChange.send()
|
||||
}
|
||||
|
||||
return currMessage
|
||||
@@ -418,6 +417,8 @@ extension AuthSessionStore {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
self.listenersActive = true
|
||||
|
||||
// adding listeners to be able to deinit later
|
||||
|
||||
@@ -79,7 +79,7 @@ class InnerCircleViewModel: NSObject, ObservableObject {
|
||||
@Published var isRecording : Bool = false
|
||||
|
||||
@Published var messagesListeningProgress: Float = 1.0
|
||||
static let multiplier: Float64 = 0.05
|
||||
static let multiplier: Float64 = 0.01
|
||||
|
||||
let audioSession = AVAudioSession.sharedInstance()
|
||||
|
||||
@@ -259,7 +259,7 @@ extension InnerCircleViewModel {
|
||||
self.stopPlayingAnyAudio()
|
||||
|
||||
// reset progress
|
||||
self.messagesListeningProgress = Float(Self.multiplier * 2)
|
||||
self.messagesListeningProgress = Float(0)
|
||||
|
||||
var AVPlayerItems: [AVPlayerItem] = []
|
||||
for url in audioUrls {
|
||||
@@ -319,8 +319,6 @@ extension InnerCircleViewModel {
|
||||
currentTime = currentTime + interval
|
||||
times.append(NSValue(time: currentTime))
|
||||
}
|
||||
// this last one to make sure we get a full loop
|
||||
times.append(NSValue(time: totalDuration))
|
||||
|
||||
// Add time observer. Observe boundary time changes on the main queue.
|
||||
// TODO: not hitting the last one/100%
|
||||
@@ -369,7 +367,7 @@ extension InnerCircleViewModel {
|
||||
// }
|
||||
|
||||
func cacheIncomingMessages(friendMessagesDict: [String: [Message]]) {
|
||||
// need way of making this get called whenever there are messages that come in but do all this in the background...onreceive of new messages, check if we already have it cached, and if not, then download
|
||||
// TODO: not firing for some reason onreceive of new data or not including new data
|
||||
guard let userId = AuthSessionStore.getCurrentUserId() else {return}
|
||||
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
@@ -392,6 +390,7 @@ extension InnerCircleViewModel {
|
||||
if let audioUrl = URL(string: message.audioDataUrl) { // check if it's a valid url
|
||||
if !self.cachedPlayerItemsDict.keys.contains(message.audioDataUrl) {
|
||||
// save to play from mem later
|
||||
|
||||
let task = URLSession.shared.dataTask(with: audioUrl) {[weak self] (data, response, error) in
|
||||
guard let data = data else { return }
|
||||
print(data)
|
||||
|
||||
Reference in New Issue
Block a user