logic for getting rid of the friends from the list of friends in contacts
This commit is contained in:
@@ -13,6 +13,7 @@ import NavigationStack
|
|||||||
|
|
||||||
struct FindFriendsView: View {
|
struct FindFriendsView: View {
|
||||||
@Environment(\.dismiss) var dismiss
|
@Environment(\.dismiss) var dismiss
|
||||||
|
@EnvironmentObject var authSessionStore: AuthSessionStore
|
||||||
|
|
||||||
@StateObject var contactsVM = ContactsViewModel()
|
@StateObject var contactsVM = ContactsViewModel()
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ struct FindFriendsView: View {
|
|||||||
|
|
||||||
List {
|
List {
|
||||||
ForEach(searchItems, id: \.self) { key in
|
ForEach(searchItems, id: \.self) { key in
|
||||||
if let currContact = self.contactsVM.contacts[key] {
|
if let currContact = self.contactsVM.contacts[key] { // getting contact's info
|
||||||
ListContactRow(contactsVM: self.contactsVM, contact: currContact)
|
ListContactRow(contactsVM: self.contactsVM, contact: currContact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,10 +50,24 @@ struct FindFriendsView: View {
|
|||||||
var searchItems: [String] {
|
var searchItems: [String] {
|
||||||
let keys = (Array(self.contactsVM.contacts.keys) as [String]).sorted()
|
let keys = (Array(self.contactsVM.contacts.keys) as [String]).sorted()
|
||||||
|
|
||||||
|
// checking if currcontact is already a friend
|
||||||
|
let currFriends = self.authSessionStore.friendsArr.map { $0.id }
|
||||||
|
let newPotentialFriends = keys.filter {
|
||||||
|
if let friend = self.contactsVM.contacts[$0]?.user { // seeing if this contact is an existing user
|
||||||
|
if currFriends.contains(friend.id) { // if this is already a friend
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// goes here if is an existing contact and not a friend
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if self.searchQuery.isEmpty {
|
if self.searchQuery.isEmpty {
|
||||||
return keys
|
return newPotentialFriends
|
||||||
} else {
|
} else {
|
||||||
return keys.filter { $0.contains(self.searchQuery) }
|
return newPotentialFriends.filter { $0.contains(self.searchQuery) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,6 @@ class AppDelegate: NSObject, UIApplicationDelegate {
|
|||||||
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
||||||
print("failed ot register for remote notifications with error: \(error)")
|
print("failed ot register for remote notifications with error: \(error)")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cloud messaging
|
// cloud messaging
|
||||||
|
|||||||
Reference in New Issue
Block a user