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 */; };
|
||||
8909199C277EFDF30025F4BB /* joinSound.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = 8909199B277EFDF30025F4BB /* joinSound.mp3 */; };
|
||||
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 */; };
|
||||
890C2460277BF896009B4A30 /* AgoraViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C245F277BF896009B4A30 /* AgoraViewController.swift */; };
|
||||
890C2462277BF935009B4A30 /* CallView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 890C2461277BF935009B4A30 /* CallView.swift */; };
|
||||
@@ -174,6 +175,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
890C245D277BF628009B4A30 /* AgoraRtcKit in Frameworks */,
|
||||
890919A42781845D0025F4BB /* AlertToast in Frameworks */,
|
||||
89BCABE2276B3CB0009E9B10 /* NavigationStack in Frameworks */,
|
||||
89F18AD4276E881800115B1E /* FirebaseAuthCombine-Community in Frameworks */,
|
||||
89F18AEA276E881900115B1E /* FirebaseStorageSwift-Beta in Frameworks */,
|
||||
@@ -553,6 +555,7 @@
|
||||
891060E92774460500F14509 /* FirebaseInAppMessagingSwift-Beta */,
|
||||
891060EB2774460500F14509 /* FirebaseMessaging */,
|
||||
890C245C277BF628009B4A30 /* AgoraRtcKit */,
|
||||
890919A32781845D0025F4BB /* AlertToast */,
|
||||
);
|
||||
productName = "nirvana-ios";
|
||||
productReference = 891A15DD27653A7000B26659 /* nirvana-ios.app */;
|
||||
@@ -587,6 +590,7 @@
|
||||
89BCABE0276B3CB0009E9B10 /* XCRemoteSwiftPackageReference "swiftui-navigation-stack" */,
|
||||
89F18ACC276E881800115B1E /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */,
|
||||
890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */,
|
||||
890919A22781845C0025F4BB /* XCRemoteSwiftPackageReference "AlertToast" */,
|
||||
);
|
||||
productRefGroup = 891A15DE27653A7000B26659 /* Products */;
|
||||
projectDirPath = "";
|
||||
@@ -898,6 +902,14 @@
|
||||
/* End XCConfigurationList 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" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/AgoraIO/AgoraAudio_iOS";
|
||||
@@ -933,6 +945,11 @@
|
||||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
890919A32781845D0025F4BB /* AlertToast */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 890919A22781845C0025F4BB /* XCRemoteSwiftPackageReference "AlertToast" */;
|
||||
productName = AlertToast;
|
||||
};
|
||||
890C245C277BF628009B4A30 /* AgoraRtcKit */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 890C245B277BF628009B4A30 /* XCRemoteSwiftPackageReference "AgoraAudio_iOS" */;
|
||||
|
||||
@@ -19,6 +19,15 @@
|
||||
"version": "3.6.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "AlertToast",
|
||||
"repositoryURL": "https://github.com/elai950/AlertToast.git",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "a4f4267f6454259ba4ed8f9dadb87334a789c26c",
|
||||
"version": "1.3.7"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "AppAuth",
|
||||
"repositoryURL": "https://github.com/openid/AppAuth-iOS.git",
|
||||
|
||||
@@ -9,28 +9,61 @@ import Foundation
|
||||
import AgoraRtcKit
|
||||
import Firebase
|
||||
import SwiftUI
|
||||
import AlertToast
|
||||
|
||||
class ConvoViewModel: NSObject, ObservableObject {
|
||||
enum Error: Identifiable {
|
||||
enum Toast: Identifiable {
|
||||
var id: Self { self }
|
||||
|
||||
case newRelevantConvoFound
|
||||
case successfullyJoined
|
||||
case successfullyAddedThirdParty
|
||||
case disconnected
|
||||
|
||||
case notAuthenticated
|
||||
case maxLimitUsers
|
||||
case convoNotFound
|
||||
case probSettingUpConvo
|
||||
case cantAddThirdParty
|
||||
|
||||
var alert: Alert {
|
||||
case generalError
|
||||
|
||||
var view: AlertToast {
|
||||
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:
|
||||
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:
|
||||
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 connectionState: AgoraConnectionStateType?
|
||||
@Published var error: Error?
|
||||
@Published var toast: Toast? {
|
||||
didSet {
|
||||
self.showToast = true
|
||||
}
|
||||
}
|
||||
@Published var showToast: Bool = false
|
||||
|
||||
let firestoreService = FirestoreService()
|
||||
private var db = Firestore.firestore()
|
||||
@@ -62,6 +95,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
let userId = AuthSessionStore.getCurrentUserId()
|
||||
if userId == nil {
|
||||
print("no authenticated user")
|
||||
self.toast = .notAuthenticated
|
||||
return
|
||||
}
|
||||
|
||||
@@ -73,6 +107,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
.getDocuments() {[weak self] (querySnapshot, err) in
|
||||
if let err = err {
|
||||
print("Error getting user's active friends: \(err)")
|
||||
self?.toast = .generalError
|
||||
} else {
|
||||
for document in querySnapshot!.documents {
|
||||
let userFriend:UserFriends? = try? document.data(as: UserFriends.self)
|
||||
@@ -99,6 +134,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
print("convos listener")
|
||||
guard let documents = querySnapshot?.documents else {
|
||||
print("Error fetching convos \(error!)")
|
||||
self?.toast = .generalError
|
||||
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
|
||||
print("this convo counts as relevant!!!")
|
||||
self?.toast = .newRelevantConvoFound
|
||||
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -180,6 +218,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
self.agoraService.getAgoraTokenCF(channelName: channelName) {[weak self] token in
|
||||
if token == nil {
|
||||
print("error in getting token")
|
||||
self?.toast = .probSettingUpConvo
|
||||
return
|
||||
}
|
||||
|
||||
@@ -196,7 +235,9 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
self?.joinConvo(convo: convo)
|
||||
case .error(let error):
|
||||
print(error)
|
||||
self?.toast = .probSettingUpConvo
|
||||
default:
|
||||
self?.toast = .generalError
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -234,6 +275,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
if convo == nil {
|
||||
// handles the offchance that the convo was deactivated or was mistakenly seen by this user
|
||||
print("convo not available")
|
||||
self.toast = .convoNotFound
|
||||
return
|
||||
}
|
||||
|
||||
@@ -255,6 +297,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
|
||||
if !self.isInCall() {
|
||||
print("not in a call, can't invite/force someone else...must have a selected convo")
|
||||
self.toast = .cantAddThirdParty
|
||||
return
|
||||
}
|
||||
|
||||
@@ -263,6 +306,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
convo.id == self.selectedConvoId
|
||||
}
|
||||
if convo == nil {
|
||||
self.toast = .convoNotFound
|
||||
print("convo not available")
|
||||
return
|
||||
}
|
||||
@@ -271,6 +315,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
convo!.users.append(friendId)
|
||||
|
||||
self.firestoreService.updateConvo(convo: convo!) {[weak self] res in
|
||||
self?.toast = .successfullyAddedThirdParty
|
||||
print("updated with new friend added in the convo")
|
||||
}
|
||||
}
|
||||
@@ -281,11 +326,13 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
|
||||
if userId == nil {
|
||||
print("not authenticated...can't join channel")
|
||||
self.toast = .notAuthenticated
|
||||
return
|
||||
}
|
||||
|
||||
if self.selectedConvoId == nil {
|
||||
if !self.isInCall() {
|
||||
print("not in a convo currently!")
|
||||
self.toast = .convoNotFound
|
||||
return
|
||||
}
|
||||
|
||||
@@ -332,7 +379,7 @@ class ConvoViewModel: NSObject, ObservableObject {
|
||||
self?.selectedConvoId = nil
|
||||
|
||||
print("left convo officially in our db as well")
|
||||
|
||||
self?.toast = .disconnected
|
||||
|
||||
// deinit the agora engine
|
||||
if destroyInstance {
|
||||
@@ -414,6 +461,7 @@ extension ConvoViewModel: AgoraRtcEngineDelegate {
|
||||
|
||||
if userId == nil {
|
||||
print("not authenticated...can't join channel")
|
||||
self.toast = .notAuthenticated
|
||||
return
|
||||
}
|
||||
|
||||
@@ -441,7 +489,7 @@ extension ConvoViewModel: AgoraRtcEngineDelegate {
|
||||
|
||||
self?.firestoreService.updateConvo(convo: updatedConvo!) {[weak self] res in
|
||||
print(res)
|
||||
|
||||
self?.toast = .successfullyJoined
|
||||
}
|
||||
case .error(let error):
|
||||
print(error)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import SwiftUI
|
||||
import NavigationStack
|
||||
import AVKit
|
||||
import AlertToast
|
||||
|
||||
struct CircleGridView: View {
|
||||
@EnvironmentObject var innerCircleVM: InnerCircleViewModel
|
||||
@@ -338,9 +339,9 @@ struct CircleGridView: View {
|
||||
|
||||
self.animateLiveConvos = true
|
||||
}// univseral alert TODO: move to inner circle view and use this pattern for all view models
|
||||
.alert(item: self.$convoVM.error) {error in
|
||||
error.alert
|
||||
}
|
||||
// .alert(item: self.$convoVM.error) {error in
|
||||
// error.alert
|
||||
// }
|
||||
} // scrollview reader
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import SwiftUI
|
||||
import NavigationStack
|
||||
import AlertToast
|
||||
|
||||
struct InnerCircleView: View {
|
||||
@StateObject var convoViewModel: ConvoViewModel = ConvoViewModel()
|
||||
@@ -148,7 +149,9 @@ struct InnerCircleView: View {
|
||||
|
||||
// set status of user to 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 {
|
||||
// print("deiniting data listeners, but current data should still be cached!")
|
||||
|
||||
Reference in New Issue
Block a user