fixing decoding problem
no need for server timestamp, manage it myself as I don't want this value creating automatically or updating automatically, I will decide
This commit is contained in:
@@ -18,7 +18,7 @@ struct Message: Identifiable, Codable {
|
|||||||
var audioDataUrl:String?
|
var audioDataUrl:String?
|
||||||
|
|
||||||
@ServerTimestamp var sentTimestamp:Date?
|
@ServerTimestamp var sentTimestamp:Date?
|
||||||
@ServerTimestamp var firstListenTimestamp:Date?
|
var firstListenTimestamp:Date?
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case id
|
case id
|
||||||
|
|||||||
@@ -292,26 +292,25 @@ extension AuthSessionStore {
|
|||||||
print("got all messages relevant")
|
print("got all messages relevant")
|
||||||
|
|
||||||
self.messagesArr = documents.compactMap { (queryDocumentSnapshot) -> Message? in
|
self.messagesArr = documents.compactMap { (queryDocumentSnapshot) -> Message? in
|
||||||
|
do {
|
||||||
|
let currMessage = try queryDocumentSnapshot.data(as: Message.self)
|
||||||
|
print("new message received! \(queryDocumentSnapshot.data())")
|
||||||
|
|
||||||
let currMessage = try? queryDocumentSnapshot.data(as: Message.self)
|
if currMessage != nil { // not really possible but just check
|
||||||
print("new message received! \(queryDocumentSnapshot.data())")
|
// 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
|
||||||
if currMessage != nil { // not really possible but just check
|
// TODO: prolly want to make a call to get this sender user details for the inbox, but they should either be in the friendsArr or their are not a friend so won't be there
|
||||||
// if the user doesn't exist for the dictionary, then add it
|
if self.friendMessagesDict[currMessage!.senderId] == nil {
|
||||||
// this means it's most likely someone new (never had user_friend relationship before) messaging for the user's inbox
|
self.friendMessagesDict[currMessage!.senderId] = [currMessage!]
|
||||||
// TODO: prolly want to make a call to get this sender user details for the inbox
|
} else {
|
||||||
|
self.friendMessagesDict[currMessage!.senderId]?.append(currMessage!)
|
||||||
if self.friendMessagesDict[currMessage!.senderId] == nil {
|
}
|
||||||
self.friendMessagesDict[currMessage!.senderId] = [currMessage!]
|
|
||||||
} else {
|
|
||||||
self.friendMessagesDict[currMessage!.senderId]?.append(currMessage!)
|
|
||||||
}
|
}
|
||||||
|
return currMessage
|
||||||
|
} catch {
|
||||||
|
print("error in trying to decode message \(error)")
|
||||||
}
|
}
|
||||||
else {
|
return nil
|
||||||
print("unable to unwrap message")
|
|
||||||
}
|
|
||||||
|
|
||||||
return currMessage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: optimize later
|
// TODO: optimize later
|
||||||
|
|||||||
Reference in New Issue
Block a user