notifications working!!!!

This commit is contained in:
talksik
2021-12-23 01:46:49 -08:00
parent 09a3f2b0bb
commit de973c4652
3 changed files with 9 additions and 6 deletions
@@ -137,7 +137,7 @@ struct CircleGridView: View {
self.selectedFriendIndex = nil
self.innerCircleVM.stopRecording(senderId: self.authSessionStore.user!.id!, receiverId: friend.id!)
self.innerCircleVM.stopRecording(senderId: self.authSessionStore.user!.id!, receiver: friend)
// self.recordingGestureDeactived()
}
@@ -20,7 +20,7 @@ class InnerCircleViewModel: ObservableObject {
let cloudStorageService = CloudStorageService()
let firestoreService = FirestoreService()
let pushNotificationService = pushNotificationService()
let pushNotificationService = PushNotificationService()
init() {
do {
@@ -60,7 +60,7 @@ class InnerCircleViewModel: ObservableObject {
// sender should be current user
// receiver is the person we are sending to
func stopRecording(senderId:String, receiverId:String) {
func stopRecording(senderId:String, receiver: User) {
audioRecorder.stop()
isRecording = false
@@ -72,13 +72,16 @@ class InnerCircleViewModel: ObservableObject {
return
}
let newMessage = Message(sendId: senderId, receivId: receiverId, audioDUrl: audioDataUrl!.absoluteString)
let newMessage = Message(sendId: senderId, receivId: receiver.id!, audioDUrl: audioDataUrl!.absoluteString)
// create a new message in firestore with the url for receiving user to automatically get notified
self?.firestoreService.createMessage(message: newMessage) {[weak self] res in
print(res)
// sending push notification
// sending push notification if there was a device token
if receiver.deviceToken != nil && receiver.nickname != nil {
self?.pushNotificationService.sendPushNotification(to: receiver.deviceToken!, title: "🌱Nirvana", body: "continue your conversation with \(receiver.nickname ?? "your friend")")
}
// delete local audio file from user's phone so that it doesn't get crazy
print("stopped recording: file about to get deleted from \(self?.getTemporaryDirectory()) with filename: \(self?.audioLocalUrl)")