adding all toasts for whole of convo vm
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
89091999277EFDCC0025F4BB /* leaveSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 89091998277EFDCC0025F4BB /* leaveSound.mp3 */; };
|
89091999277EFDCC0025F4BB /* leaveSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 89091998277EFDCC0025F4BB /* leaveSound.mp3 */; };
|
||||||
8909199C277EFDF30025F4BB /* joinSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 8909199B277EFDF30025F4BB /* joinSound.mp3 */; };
|
8909199C277EFDF30025F4BB /* joinSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 8909199B277EFDF30025F4BB /* joinSound.mp3 */; };
|
||||||
8909199E278155920025F4BB /* UserStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909199D278155920025F4BB /* UserStatusView.swift */; };
|
8909199E278155920025F4BB /* UserStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909199D278155920025F4BB /* UserStatusView.swift */; };
|
||||||
|
890919A42781845D0025F4BB /* AlertToast in Frameworks */ = {isa = PBXBuildFile; productRef = 890919A32781845D0025F4BB /* AlertToast */; };
|
||||||
890C245D277BF628009B4A30 /* AgoraRtcKit in Frameworks */ = {isa = PBXBuildFile; productRef = 890C245C277BF628009B4A30 /* AgoraRtcKit */; };
|
890C245D277BF628009B4A30 /* AgoraRtcKit in Frameworks */ = {isa = PBXBuildFile; productRef = 890C245C277BF628009B4A30 /* AgoraRtcKit */; };
|
||||||
890C2460277BF896009B4A30 /* AgoraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C245F277BF896009B4A30 /* AgoraViewController.swift */; };
|
890C2460277BF896009B4A30 /* AgoraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C245F277BF896009B4A30 /* AgoraViewController.swift */; };
|
||||||
890C2462277BF935009B4A30 /* CallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C2461277BF935009B4A30 /* CallView.swift */; };
|
890C2462277BF935009B4A30 /* CallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C2461277BF935009B4A30 /* CallView.swift */; };
|
||||||
@@ -174,6 +175,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
890C245D277BF628009B4A30 /* AgoraRtcKit in Frameworks */,
|
890C245D277BF628009B4A30 /* AgoraRtcKit in Frameworks */,
|
||||||
|
890919A42781845D0025F4BB /* AlertToast in Frameworks */,
|
||||||
89BCABE2276B3CB0009E9B10 /* NavigationStack in Frameworks */,
|
89BCABE2276B3CB0009E9B10 /* NavigationStack in Frameworks */,
|
||||||
89F18AD4276E881800115B1E /* FirebaseAuthCombine-Community in Frameworks */,
|
89F18AD4276E881800115B1E /* FirebaseAuthCombine-Community in Frameworks */,
|
||||||
89F18AEA276E881900115B1E /* FirebaseStorageSwift-Beta in Frameworks */,
|
89F18AEA276E881900115B1E /* FirebaseStorageSwift-Beta in Frameworks */,
|
||||||
@@ -553,6 +555,7 @@
|
|||||||
891060E92774460500F14509 /* FirebaseInAppMessagingSwift-Beta */,
|
891060E92774460500F14509 /* FirebaseInAppMessagingSwift-Beta */,
|
||||||
891060EB2774460500F14509 /* FirebaseMessaging */,
|
891060EB2774460500F14509 /* FirebaseMessaging */,
|
||||||
890C245C277BF628009B4A30 /* AgoraRtcKit */,
|
890C245C277BF628009B4A30 /* AgoraRtcKit */,
|
||||||
|
890919A32781845D0025F4BB /* AlertToast */,
|
||||||
);
|
);
|
||||||
productName = "nirvana-ios";
|
productName = "nirvana-ios";
|
||||||
productReference = 891A15DD27653A7000B26659 /* nirvana-ios.app */;
|
productReference = 891A15DD27653A7000B26659 /* nirvana-ios.app */;
|
||||||
@@ -587,6 +590,7 @@
|
|||||||
89BCABE0276B3CB0009E9B10 /* XCRemoteSwiftPackageReference "swiftui-navigation-stack" */,
|
89BCABE0276B3CB0009E9B10 /* XCRemoteSwiftPackageReference "swiftui-navigation-stack" */,
|
||||||
89F18ACC276E881800115B1E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
|
89F18ACC276E881800115B1E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
|
||||||
890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */,
|
890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */,
|
||||||
|
890919A22781845C0025F4BB /* XCRemoteSwiftPackageReference "AlertToast" */,
|
||||||
);
|
);
|
||||||
productRefGroup = 891A15DE27653A7000B26659 /* Products */;
|
productRefGroup = 891A15DE27653A7000B26659 /* Products */;
|
||||||
projectDirPath = "";
|
projectDirPath = "";
|
||||||
@@ -898,6 +902,14 @@
|
|||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
|
|
||||||
/* Begin XCRemoteSwiftPackageReference section */
|
/* Begin XCRemoteSwiftPackageReference section */
|
||||||
|
890919A22781845C0025F4BB /* XCRemoteSwiftPackageReference "AlertToast" */ = {
|
||||||
|
isa = XCRemoteSwiftPackageReference;
|
||||||
|
repositoryURL = "https://github.com/elai950/AlertToast.git";
|
||||||
|
requirement = {
|
||||||
|
kind = upToNextMajorVersion;
|
||||||
|
minimumVersion = 1.0.0;
|
||||||
|
};
|
||||||
|
};
|
||||||
890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */ = {
|
890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */ = {
|
||||||
isa = XCRemoteSwiftPackageReference;
|
isa = XCRemoteSwiftPackageReference;
|
||||||
repositoryURL = "https://github.com/AgoraIO/AgoraAudio_iOS";
|
repositoryURL = "https://github.com/AgoraIO/AgoraAudio_iOS";
|
||||||
@@ -933,6 +945,11 @@
|
|||||||
/* End XCRemoteSwiftPackageReference section */
|
/* End XCRemoteSwiftPackageReference section */
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
/* Begin XCSwiftPackageProductDependency section */
|
||||||
|
890919A32781845D0025F4BB /* AlertToast */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = 890919A22781845C0025F4BB /* XCRemoteSwiftPackageReference "AlertToast" */;
|
||||||
|
productName = AlertToast;
|
||||||
|
};
|
||||||
890C245C277BF628009B4A30 /* AgoraRtcKit */ = {
|
890C245C277BF628009B4A30 /* AgoraRtcKit */ = {
|
||||||
isa = XCSwiftPackageProductDependency;
|
isa = XCSwiftPackageProductDependency;
|
||||||
package = 890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */;
|
package = 890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */;
|
||||||
|
|||||||
@@ -19,6 +19,15 @@
|
|||||||
"version": "3.6.0"
|
"version": "3.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"package": "AlertToast",
|
||||||
|
"repositoryURL": "https://github.com/elai950/AlertToast.git",
|
||||||
|
"state": {
|
||||||
|
"branch": null,
|
||||||
|
"revision": "a4f4267f6454259ba4ed8f9dadb87334a789c26c",
|
||||||
|
"version": "1.3.7"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"package": "AppAuth",
|
"package": "AppAuth",
|
||||||
"repositoryURL": "https://github.com/openid/AppAuth-iOS.git",
|
"repositoryURL": "https://github.com/openid/AppAuth-iOS.git",
|
||||||
|
|||||||
@@ -9,28 +9,61 @@ import Foundation
|
|||||||
import AgoraRtcKit
|
import AgoraRtcKit
|
||||||
import Firebase
|
import Firebase
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import AlertToast
|
||||||
|
|
||||||
class ConvoViewModel: NSObject, ObservableObject {
|
class ConvoViewModel: NSObject, ObservableObject {
|
||||||
enum Error: Identifiable {
|
enum Toast: Identifiable {
|
||||||
var id: Self { self }
|
var id: Self { self }
|
||||||
|
|
||||||
|
case newRelevantConvoFound
|
||||||
|
case successfullyJoined
|
||||||
|
case successfullyAddedThirdParty
|
||||||
|
case disconnected
|
||||||
|
|
||||||
case notAuthenticated
|
case notAuthenticated
|
||||||
case maxLimitUsers
|
case maxLimitUsers
|
||||||
case convoNotFound
|
case convoNotFound
|
||||||
|
case probSettingUpConvo
|
||||||
|
case cantAddThirdParty
|
||||||
|
|
||||||
var alert: Alert {
|
case generalError
|
||||||
|
|
||||||
|
var view: AlertToast {
|
||||||
switch self {
|
switch self {
|
||||||
|
case .disconnected:
|
||||||
|
return AlertToast(displayMode: .hud, type: .systemImage("hand.wave.fill", NirvanaColor.teal), title: "disconnected")
|
||||||
|
case .successfullyAddedThirdParty:
|
||||||
|
return AlertToast(displayMode: .hud, type: .complete(Color.green), title: "added friend")
|
||||||
|
case .cantAddThirdParty:
|
||||||
|
return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "You are not in a call, cannot add this friend")
|
||||||
|
case .convoNotFound:
|
||||||
|
return AlertToast(displayMode: .hud, type: .error(Color.orange), title: "Not a valid convo to join 😞")
|
||||||
|
case .newRelevantConvoFound:
|
||||||
|
return AlertToast(displayMode: .hud, type: .systemImage("person.2.wave.2.fill", NirvanaColor.teal), title: "joined convo")
|
||||||
|
case .successfullyJoined:
|
||||||
|
return AlertToast(displayMode: .hud, type: .complete(Color.green), title: "joined convo")
|
||||||
|
case .probSettingUpConvo:
|
||||||
|
return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Problem setting up convo ‼️")
|
||||||
|
case .maxLimitUsers:
|
||||||
|
return AlertToast(displayMode: .hud, type: .error(Color.red), title: "The convo is full! Sorry! 😞")
|
||||||
case .notAuthenticated:
|
case .notAuthenticated:
|
||||||
return Alert(title: Text("Not Authenticated!"))
|
return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Not authenticated ‼️")
|
||||||
|
case .generalError:
|
||||||
|
return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Something went wrong ‼️")
|
||||||
default:
|
default:
|
||||||
return Alert(title: Text("There was a problem"))
|
return AlertToast(displayMode: .hud, type: .error(Color.red), title: "Something went wrong ‼️")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Published var selectedConvoId:String? = nil
|
@Published var selectedConvoId:String? = nil
|
||||||
@Published var connectionState: AgoraConnectionStateType?
|
@Published var connectionState: AgoraConnectionStateType?
|
||||||
@Published var error: Error?
|
@Published var toast: Toast? {
|
||||||
|
didSet {
|
||||||
|
self.showToast = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Published var showToast: Bool = false
|
||||||
|
|
||||||
let firestoreService = FirestoreService()
|
let firestoreService = FirestoreService()
|
||||||
private var db = Firestore.firestore()
|
private var db = Firestore.firestore()
|
||||||
@@ -62,6 +95,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
let userId = AuthSessionStore.getCurrentUserId()
|
let userId = AuthSessionStore.getCurrentUserId()
|
||||||
if userId == nil {
|
if userId == nil {
|
||||||
print("no authenticated user")
|
print("no authenticated user")
|
||||||
|
self.toast = .notAuthenticated
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +107,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
.getDocuments() {[weak self] (querySnapshot, err) in
|
.getDocuments() {[weak self] (querySnapshot, err) in
|
||||||
if let err = err {
|
if let err = err {
|
||||||
print("Error getting user's active friends: \(err)")
|
print("Error getting user's active friends: \(err)")
|
||||||
|
self?.toast = .generalError
|
||||||
} else {
|
} else {
|
||||||
for document in querySnapshot!.documents {
|
for document in querySnapshot!.documents {
|
||||||
let userFriend:UserFriends? = try? document.data(as: UserFriends.self)
|
let userFriend:UserFriends? = try? document.data(as: UserFriends.self)
|
||||||
@@ -99,6 +134,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
print("convos listener")
|
print("convos listener")
|
||||||
guard let documents = querySnapshot?.documents else {
|
guard let documents = querySnapshot?.documents else {
|
||||||
print("Error fetching convos \(error!)")
|
print("Error fetching convos \(error!)")
|
||||||
|
self?.toast = .generalError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +184,8 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
|
|
||||||
if relevancyScore > Self.relevancyAcceptance && convo.users.count > 1 { //offchance that it's just the one person in the convo right now, don't want to see it until there are at least 2 people
|
if relevancyScore > Self.relevancyAcceptance && convo.users.count > 1 { //offchance that it's just the one person in the convo right now, don't want to see it until there are at least 2 people
|
||||||
print("this convo counts as relevant!!!")
|
print("this convo counts as relevant!!!")
|
||||||
|
self?.toast = .newRelevantConvoFound
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -180,6 +218,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
self.agoraService.getAgoraTokenCF(channelName: channelName) {[weak self] token in
|
self.agoraService.getAgoraTokenCF(channelName: channelName) {[weak self] token in
|
||||||
if token == nil {
|
if token == nil {
|
||||||
print("error in getting token")
|
print("error in getting token")
|
||||||
|
self?.toast = .probSettingUpConvo
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +235,9 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
self?.joinConvo(convo: convo)
|
self?.joinConvo(convo: convo)
|
||||||
case .error(let error):
|
case .error(let error):
|
||||||
print(error)
|
print(error)
|
||||||
|
self?.toast = .probSettingUpConvo
|
||||||
default:
|
default:
|
||||||
|
self?.toast = .generalError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,6 +275,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
if convo == nil {
|
if convo == nil {
|
||||||
// handles the offchance that the convo was deactivated or was mistakenly seen by this user
|
// handles the offchance that the convo was deactivated or was mistakenly seen by this user
|
||||||
print("convo not available")
|
print("convo not available")
|
||||||
|
self.toast = .convoNotFound
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +297,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
|
|
||||||
if !self.isInCall() {
|
if !self.isInCall() {
|
||||||
print("not in a call, can't invite/force someone else...must have a selected convo")
|
print("not in a call, can't invite/force someone else...must have a selected convo")
|
||||||
|
self.toast = .cantAddThirdParty
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,6 +306,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
convo.id == self.selectedConvoId
|
convo.id == self.selectedConvoId
|
||||||
}
|
}
|
||||||
if convo == nil {
|
if convo == nil {
|
||||||
|
self.toast = .convoNotFound
|
||||||
print("convo not available")
|
print("convo not available")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -271,6 +315,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
convo!.users.append(friendId)
|
convo!.users.append(friendId)
|
||||||
|
|
||||||
self.firestoreService.updateConvo(convo: convo!) {[weak self] res in
|
self.firestoreService.updateConvo(convo: convo!) {[weak self] res in
|
||||||
|
self?.toast = .successfullyAddedThirdParty
|
||||||
print("updated with new friend added in the convo")
|
print("updated with new friend added in the convo")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,11 +326,13 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
|
|
||||||
if userId == nil {
|
if userId == nil {
|
||||||
print("not authenticated...can't join channel")
|
print("not authenticated...can't join channel")
|
||||||
|
self.toast = .notAuthenticated
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.selectedConvoId == nil {
|
if !self.isInCall() {
|
||||||
print("not in a convo currently!")
|
print("not in a convo currently!")
|
||||||
|
self.toast = .convoNotFound
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +379,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
|||||||
self?.selectedConvoId = nil
|
self?.selectedConvoId = nil
|
||||||
|
|
||||||
print("left convo officially in our db as well")
|
print("left convo officially in our db as well")
|
||||||
|
self?.toast = .disconnected
|
||||||
|
|
||||||
// deinit the agora engine
|
// deinit the agora engine
|
||||||
if destroyInstance {
|
if destroyInstance {
|
||||||
@@ -414,6 +461,7 @@ extension ConvoViewModel: AgoraRtcEngineDelegate {
|
|||||||
|
|
||||||
if userId == nil {
|
if userId == nil {
|
||||||
print("not authenticated...can't join channel")
|
print("not authenticated...can't join channel")
|
||||||
|
self.toast = .notAuthenticated
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,7 +489,7 @@ extension ConvoViewModel: AgoraRtcEngineDelegate {
|
|||||||
|
|
||||||
self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in
|
self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in
|
||||||
print(res)
|
print(res)
|
||||||
|
self?.toast = .successfullyJoined
|
||||||
}
|
}
|
||||||
case .error(let error):
|
case .error(let error):
|
||||||
print(error)
|
print(error)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import NavigationStack
|
import NavigationStack
|
||||||
import AVKit
|
import AVKit
|
||||||
|
import AlertToast
|
||||||
|
|
||||||
struct CircleGridView: View {
|
struct CircleGridView: View {
|
||||||
@EnvironmentObject var innerCircleVM: InnerCircleViewModel
|
@EnvironmentObject var innerCircleVM: InnerCircleViewModel
|
||||||
@@ -338,9 +339,9 @@ struct CircleGridView: View {
|
|||||||
|
|
||||||
self.animateLiveConvos = true
|
self.animateLiveConvos = true
|
||||||
}// univseral alert TODO: move to inner circle view and use this pattern for all view models
|
}// univseral alert TODO: move to inner circle view and use this pattern for all view models
|
||||||
.alert(item: self.$convoVM.error) {error in
|
// .alert(item: self.$convoVM.error) {error in
|
||||||
error.alert
|
// error.alert
|
||||||
}
|
// }
|
||||||
} // scrollview reader
|
} // scrollview reader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import NavigationStack
|
import NavigationStack
|
||||||
|
import AlertToast
|
||||||
|
|
||||||
struct InnerCircleView: View {
|
struct InnerCircleView: View {
|
||||||
@StateObject var convoViewModel: ConvoViewModel = ConvoViewModel()
|
@StateObject var convoViewModel: ConvoViewModel = ConvoViewModel()
|
||||||
@@ -148,7 +149,9 @@ struct InnerCircleView: View {
|
|||||||
|
|
||||||
// set status of user to online
|
// set status of user to online
|
||||||
self.authSessionStore.updateUserStatus(userStatus: .online)
|
self.authSessionStore.updateUserStatus(userStatus: .online)
|
||||||
|
}
|
||||||
|
.toast(isPresenting: self.$convoViewModel.showToast) {
|
||||||
|
self.convoViewModel.toast?.view ?? AlertToast(displayMode: .hud, type: .error(Color.red), title: "Something went wrong")
|
||||||
}
|
}
|
||||||
// .onDisappear {
|
// .onDisappear {
|
||||||
// print("deiniting data listeners, but current data should still be cached!")
|
// print("deiniting data listeners, but current data should still be cached!")
|
||||||
|
|||||||
Reference in New Issue
Block a user