decent place but still buggy
This commit is contained in:
@@ -380,42 +380,43 @@ extension AuthSessionStore {
|
|||||||
//optimize this? but also saving on memory and same db reads
|
//optimize this? but also saving on memory and same db reads
|
||||||
self.relevantMessagesByUserDict.removeAll()
|
self.relevantMessagesByUserDict.removeAll()
|
||||||
|
|
||||||
self.messagesArr = documents.compactMap { (queryDocumentSnapshot) -> Message? in
|
DispatchQueue.main.async {
|
||||||
do {
|
self.messagesArr = documents.compactMap { (queryDocumentSnapshot) -> Message? in
|
||||||
let currMessage = try queryDocumentSnapshot.data(as: Message.self)
|
do {
|
||||||
// print("new message received! \(currMessage!.sentTimestamp)")
|
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
|
DispatchQueue.main.async {
|
||||||
// if the user doesn't exist for the dictionary, then add it
|
if currMessage != nil { // not really possible but just check
|
||||||
// this means it's most likely someone new (never had user_friend relationship before) messaging for the user's inbox
|
// if the user doesn't exist for the dictionary, then add it
|
||||||
// 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
|
// this means it's most likely someone new (never had user_friend relationship before) messaging for the user's inbox
|
||||||
// also add in any messages where I am the sender
|
// 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
|
||||||
if currMessage!.senderId == currUserId { // if I am the sender
|
// also add in any messages where I am the sender
|
||||||
if self.relevantMessagesByUserDict[currMessage!.receiverId] == nil {
|
if currMessage!.senderId == currUserId { // if I am the sender
|
||||||
self.relevantMessagesByUserDict[currMessage!.receiverId] = [currMessage!]
|
if self.relevantMessagesByUserDict[currMessage!.receiverId] == nil {
|
||||||
} else {
|
self.relevantMessagesByUserDict[currMessage!.receiverId] = [currMessage!]
|
||||||
self.relevantMessagesByUserDict[currMessage!.receiverId]?.append(currMessage!)
|
} else {
|
||||||
|
self.relevantMessagesByUserDict[currMessage!.receiverId]?.append(currMessage!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else { // if I am receiving
|
||||||
else { // if I am receiving
|
if self.relevantMessagesByUserDict[currMessage!.senderId] == nil {
|
||||||
if self.relevantMessagesByUserDict[currMessage!.senderId] == nil {
|
self.relevantMessagesByUserDict[currMessage!.senderId] = [currMessage!]
|
||||||
self.relevantMessagesByUserDict[currMessage!.senderId] = [currMessage!]
|
} else {
|
||||||
} else {
|
self.relevantMessagesByUserDict[currMessage!.senderId]?.append(currMessage!)
|
||||||
self.relevantMessagesByUserDict[currMessage!.senderId]?.append(currMessage!)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.objectWillChange.send()
|
return currMessage
|
||||||
|
} catch {
|
||||||
|
print(error)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
return currMessage
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
}
|
||||||
return nil
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.listenersActive = true
|
self.listenersActive = true
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class InnerCircleViewModel: NSObject, ObservableObject {
|
|||||||
@Published var isRecording : Bool = false
|
@Published var isRecording : Bool = false
|
||||||
|
|
||||||
@Published var messagesListeningProgress: Float = 1.0
|
@Published var messagesListeningProgress: Float = 1.0
|
||||||
static let multiplier: Float64 = 0.05
|
static let multiplier: Float64 = 0.01
|
||||||
|
|
||||||
let audioSession = AVAudioSession.sharedInstance()
|
let audioSession = AVAudioSession.sharedInstance()
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ extension InnerCircleViewModel {
|
|||||||
self.stopPlayingAnyAudio()
|
self.stopPlayingAnyAudio()
|
||||||
|
|
||||||
// reset progress
|
// reset progress
|
||||||
self.messagesListeningProgress = Float(Self.multiplier * 2)
|
self.messagesListeningProgress = Float(0)
|
||||||
|
|
||||||
var AVPlayerItems: [AVPlayerItem] = []
|
var AVPlayerItems: [AVPlayerItem] = []
|
||||||
for url in audioUrls {
|
for url in audioUrls {
|
||||||
@@ -319,8 +319,6 @@ extension InnerCircleViewModel {
|
|||||||
currentTime = currentTime + interval
|
currentTime = currentTime + interval
|
||||||
times.append(NSValue(time: currentTime))
|
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.
|
// Add time observer. Observe boundary time changes on the main queue.
|
||||||
// TODO: not hitting the last one/100%
|
// TODO: not hitting the last one/100%
|
||||||
@@ -369,7 +367,7 @@ extension InnerCircleViewModel {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
func cacheIncomingMessages(friendMessagesDict: [String: [Message]]) {
|
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}
|
guard let userId = AuthSessionStore.getCurrentUserId() else {return}
|
||||||
|
|
||||||
DispatchQueue.global(qos: .background).async {
|
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 let audioUrl = URL(string: message.audioDataUrl) { // check if it's a valid url
|
||||||
if !self.cachedPlayerItemsDict.keys.contains(message.audioDataUrl) {
|
if !self.cachedPlayerItemsDict.keys.contains(message.audioDataUrl) {
|
||||||
// save to play from mem later
|
// save to play from mem later
|
||||||
|
|
||||||
let task = URLSession.shared.dataTask(with: audioUrl) {[weak self] (data, response, error) in
|
let task = URLSession.shared.dataTask(with: audioUrl) {[weak self] (data, response, error) in
|
||||||
guard let data = data else { return }
|
guard let data = data else { return }
|
||||||
print(data)
|
print(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user