notifications working!!!!
This commit is contained in:
@@ -12,7 +12,7 @@ class PushNotificationService {
|
|||||||
func sendPushNotification(to token: String, title: String, body: String) {
|
func sendPushNotification(to token: String, title: String, body: String) {
|
||||||
let urlString = "https://fcm.googleapis.com/fcm/send"
|
let urlString = "https://fcm.googleapis.com/fcm/send"
|
||||||
let url = NSURL(string: urlString)!
|
let url = NSURL(string: urlString)!
|
||||||
let paramString: [String : Any] = ["to" : token,
|
let paramString: [String : Any] = ["to" : token, // sending to the device token of the desired receiving device
|
||||||
"notification" : ["title" : title, "body" : body],
|
"notification" : ["title" : title, "body" : body],
|
||||||
"data" : ["user" : "test_id"]
|
"data" : ["user" : "test_id"]
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ struct CircleGridView: View {
|
|||||||
|
|
||||||
self.selectedFriendIndex = nil
|
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()
|
// self.recordingGestureDeactived()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class InnerCircleViewModel: ObservableObject {
|
|||||||
|
|
||||||
let cloudStorageService = CloudStorageService()
|
let cloudStorageService = CloudStorageService()
|
||||||
let firestoreService = FirestoreService()
|
let firestoreService = FirestoreService()
|
||||||
let pushNotificationService = pushNotificationService()
|
let pushNotificationService = PushNotificationService()
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
do {
|
do {
|
||||||
@@ -60,7 +60,7 @@ class InnerCircleViewModel: ObservableObject {
|
|||||||
|
|
||||||
// sender should be current user
|
// sender should be current user
|
||||||
// receiver is the person we are sending to
|
// receiver is the person we are sending to
|
||||||
func stopRecording(senderId:String, receiverId:String) {
|
func stopRecording(senderId:String, receiver: User) {
|
||||||
audioRecorder.stop()
|
audioRecorder.stop()
|
||||||
isRecording = false
|
isRecording = false
|
||||||
|
|
||||||
@@ -72,13 +72,16 @@ class InnerCircleViewModel: ObservableObject {
|
|||||||
return
|
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
|
// 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
|
self?.firestoreService.createMessage(message: newMessage) {[weak self] res in
|
||||||
print(res)
|
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
|
// 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)")
|
print("stopped recording: file about to get deleted from \(self?.getTemporaryDirectory()) with filename: \(self?.audioLocalUrl)")
|
||||||
|
|||||||
Reference in New Issue
Block a user