Created
January 5, 2024 17:56
-
-
Save RishiRavula/4052adbdc604f4badd65653a56c87259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./Travely/ViewModel/LoginViewModel.swift: db.collection("Users").document(result!.user.uid).getDocument { document, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/ViewModel/LoginViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"notifToken": self.deviceNotifToken, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/ViewModel/LoginViewModel.swift: db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("usersThatLiked", arrayContains: String(Auth.auth().currentUser!.uid)) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/LoginViewModel.swift: // db.collection("Users").document(result!.user.uid).getDocument {(document, err) in | |
// | |
// if(err != nil){ | |
// print(err?.localizedDescription) | |
// return | |
// } | |
./Travely/ViewModel/LoginViewModel.swift: // db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
// | |
// "notifToken": self.deviceNotifToken | |
// | |
// ]) { err in | |
// | |
// if err != nil{ | |
// print(err?.localizedDescription) | |
// return | |
// } | |
./Travely/ViewModel/LoginViewModel.swift: // db.collection("Plans") | |
// .order(by: "datePosted", descending: true) | |
// .whereField("usersThatLiked", arrayContains: String(Auth.auth().currentUser!.uid)) | |
// .getDocuments {(snap, err) in | |
// | |
// if err != nil{ | |
// return | |
// } | |
./Travely/ViewModel/LoginViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"subscriptionStatus": true, | |
"subscriptionExpirationDate": expirationDate ?? Date.now, | |
"subscriptionPurchaseDate": purchaseDate ?? Date.now, | |
"subscriptionType": subscriptionType ?? "error", | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/LoginViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"subscriptionStatus": false, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/LoginViewModel.swift: db.collection("Users").document(uid).setData([ | |
"firstName": self.firstNameSaved, | |
"lastName": self.lastNameSaved, | |
"birthday": self.birthDate, | |
"gender": self.gender, | |
"country": self.country, | |
"countryCode": self.countryCode, | |
"bio": self.bio, | |
"profilePicURL": url!.absoluteString, | |
"profilePicURLLowQuality": url2!.absoluteString, | |
"notifToken": self.deviceNotifToken, | |
"blockedUsers": [], | |
"defaultPhoto": defaultVariable, | |
]) { err in | |
if err != nil { | |
print(err!.localizedDescription) | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap = try! await db.collection("GroupTrips") | |
.order(by: "startDate", descending: true) | |
.getDocuments() | |
for i in snap.documents { | |
let id = i.documentID | |
let title = i.get("title") as? String ?? "" | |
let imageURL = i.get("imageURL") as? String ?? "" | |
let spots = i.get("spots") as? Int ?? 0 | |
let active = i.get("active") as? Bool ?? false | |
let country = i.get("country") as? String ?? "" | |
let days = i.get("days") as? Int ?? 0 | |
let endDate = i.get("endDate") as? Timestamp ?? Timestamp(date: Date()) | |
let endDates = i.get("endDates") as? [Timestamp] ?? [] | |
let guided = i.get("guided") as? Bool ?? false | |
let included = i.get("included") as? [String] ?? [] | |
let includedImages = i.get("includedImages") as? [String] ?? [] | |
let itineraryTitles = i.get("itineraryTitles") as? [String] ?? [] | |
let itineraryDetails = i.get("itineraryDetails") as? [String] ?? [] | |
let itineraryPics = i.get("itineraryPics") as? [String] ?? [] | |
let overview = i.get("overview") as? String ?? "" | |
let partner = i.get("partner") as? String ?? "" | |
let partnerLogo = i.get("partnerLogo") as? String ?? "" | |
let price = i.get("price") as? Int ?? 0 | |
let startDate = i.get("startDate") as? Timestamp ?? Timestamp(date: Date()) | |
let startDates = i.get("startDates") as? [Timestamp] ?? [] | |
let link = i.get("link") as? String ?? "" | |
let numPeople = i.get("numPeople") as? Int ?? 0 | |
let urls = i.get("urls") as? [String] ?? [] | |
let shareLink = i.get("shareLink") as? String ?? "" | |
let youtube = i.get("youtube") as? String ?? "" | |
let spotsHidden = i.get("spotsHidden") as? Bool ?? false | |
var startDatesNew = [Date]() | |
for timestamp in startDates { | |
startDatesNew.append(timestamp.dateValue()) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: var query = db.collection("Plans") | |
.whereField("planNameArray", arrayContains: searchText.lowercased()) | |
.whereField("endDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "endDate", descending: false) | |
.limit(to: 5) | |
if let lastDoc = lastDocumentsearchTripNamePlans { | |
query = query.start(afterDocument: lastDoc) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: var query = db.collection("Plans") | |
.whereField("planNameArray", arrayContains: searchText.lowercased()) | |
.whereField("endDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "endDate", descending: false) | |
.limit(to: 5) | |
if let lastDoc = lastDocumentsearchTripNamePlans { | |
query = query.start(afterDocument: lastDoc) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: var query = db.collection("TravelersGoing").document("Cities").collection(city) | |
.whereField("endDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "endDate", descending: false) | |
.limit(to: 5) | |
if let lastDoc = lastDocumentsearchTripCityTravelersGoing { | |
query = query.start(afterDocument: lastDoc) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: var query = db.collection("TravelersGoing").document("Cities").collection(city) | |
.whereField("endDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "endDate", descending: false) | |
.limit(to: 5) | |
if let lastDoc = lastDocumentsearchTripCityTravelersGoing { | |
query = query.start(afterDocument: lastDoc) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: var query = db.collection("Plans") | |
.whereField("planNameArray", arrayContains: city.lowercased()) | |
.whereField("endDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "endDate", descending: false) | |
.limit(to: 5) | |
if let lastDoc = lastDocumentsearchTripCityPlans { | |
query = query.start(afterDocument: lastDoc) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: var query = db.collection("Plans") | |
.whereField("planNameArray", arrayContains: city.lowercased()) | |
.whereField("endDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "endDate", descending: false) | |
.limit(to: 5) | |
if let lastDoc = lastDocumentsearchTripCityPlans { | |
query = query.start(afterDocument: lastDoc) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let TrendingPlansSnap = try! await db.collection("TrendingPlans").getDocuments() // fetch document contain all id's for plans | |
let documentDataTrending = TrendingPlansSnap.documents[num].data() // get the trending continent plan id's data | |
let planIds = documentDataTrending["plans"] as! [String] // plan id's | |
for planId in planIds { | |
let document = try! await db.collection("Plans").document(planId).getDocument() // fetch document from firebase | |
if document.exists { | |
let plan = fetchPlanDataAsDocumentData(document: document) | |
DispatchQueue.main.async { | |
if num == 1 { | |
self.AfricaPlans.append(plan) | |
} else if num == 2 { | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.whereField("planNameArray", arrayContains: destination.lowercased()) | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentDestinationPlans!) | |
.limit(to: 10) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap = try! await db.collection("Plans") | |
.whereField("planNameArray", arrayContains: destination.lowercased()) | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
for i in snap.documents { | |
let plan = fetchPlanDataAsGet(i: i) | |
DispatchQueue.main.async { | |
self.destinationPlans.append(plan) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.whereField("countries", arrayContains: countriesForforYouFeed[0]) | |
.whereField("datePosted", isGreaterThan: calendar.date(byAdding: .weekOfYear, value: -3, to: Date()) as Any) | |
.whereField("numLikes", in: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) | |
.start(afterDocument: lastDocumentforYouDiscoverPlans!) | |
.limit(to: 3) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap2 = try! await db.collection("Plans") | |
.whereField("countries", arrayContains: countries[0]) | |
.whereField("datePosted", isGreaterThan: calendar.date(byAdding: .weekOfYear, value: -3, to: Date()) as Any) | |
.whereField("numLikes", in: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17]) | |
.limit(to: 5) | |
.getDocuments() | |
for i in snap2.documents { | |
let plan = fetchPlanDataAsGet(i: i) // fetch document data | |
DispatchQueue.main.async { | |
self.forYoudiscoverPlans.append(plan) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts") | |
.whereField("countryorinterest", isEqualTo: countriesForforYouFeed[0]) | |
.whereField("datePosted", isGreaterThan: calendar.date(byAdding: .weekOfYear, value: -3, to: Date()) as Any) | |
.whereField("numComments", in: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentforYouDiscoverPosts!) | |
.limit(to: 5) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap = try! await db.collection("Posts") | |
.whereField("countryorinterest", isEqualTo: countries[0]) | |
.whereField("datePosted", isGreaterThan: calendar.date(byAdding: .weekOfYear, value: -3, to: Date()) as Any) | |
.whereField("numComments", in: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
for i in snap.documents { | |
let id = i.documentID | |
let creator = i.get("creator") as? String ?? "" | |
let post = i.get("postText") as? String ?? "" | |
let numLikes = i.get("likes") as? Int ?? 0 | |
let numComments = i.get("numComments") as? Int ?? 0 | |
let datePostedTS = i.get("datePosted") as? Timestamp ?? Timestamp(date: Date()) | |
let name = i.get("name") as? String ?? "" | |
let url = i.get("urlProfilePic") as? String ?? "" | |
let countryInterestImage = i.get("countryInterestImage") as? String ?? "" | |
let usersThatLiked = i.get("usersThatLiked") as? [String] ?? [] | |
let countryInterestName = i.get("countryorinterest") as? String ?? "" | |
let lastCommentText = i.get("mostRecentCommentText") as? String ?? "" | |
let lastCommentUser = i.get("mostRecentCommentUser") as? String ?? "" | |
let datePosted = datePostedTS.dateValue() | |
if usersThatLiked.contains(Auth.auth().currentUser!.uid) && !postsLikedThisSession.contains(id) { | |
postsLikedThisSession.append(id) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentDiscoverPlans!) | |
.limit(to: 10) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap2 = try! await db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
for i in snap2.documents { | |
let plan = fetchPlanDataAsGet(i: i) | |
DispatchQueue.main.async { | |
self.discoverPlans.append(plan) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentDiscoverPosts!) | |
.limit(to: 10) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap = try! await db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
for i in snap.documents { | |
let id = i.documentID | |
let creator = i.get("creator") as? String ?? "" | |
let post = i.get("postText") as? String ?? "" | |
let numLikes = i.get("likes") as? Int ?? 0 | |
let numComments = i.get("numComments") as? Int ?? 0 | |
let datePostedTS = i.get("datePosted") as? Timestamp ?? Timestamp(date: Date()) | |
let name = i.get("name") as? String ?? "" | |
let url = i.get("urlProfilePic") as? String ?? "" | |
let countryInterestImage = i.get("countryInterestImage") as? String ?? "" | |
let usersThatLiked = i.get("usersThatLiked") as? [String] ?? [] | |
let countryInterestName = i.get("countryorinterest") as? String ?? "" | |
let lastCommentText = i.get("mostRecentCommentText") as? String ?? "" | |
let lastCommentUser = i.get("mostRecentCommentUser") as? String ?? "" | |
let datePosted = datePostedTS.dateValue() | |
if usersThatLiked.contains(Auth.auth().currentUser!.uid) && !postsLikedThisSession.contains(id) { | |
postsLikedThisSession.append(id) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users") | |
.order(by: "dateLastSignedIn", descending: true) | |
.whereField("currentCountryLocation", isEqualTo: country) | |
.start(afterDocument: lastDocumentNearMeTravelers!) | |
.limit(to: 10) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users") | |
.order(by: "dateLastSignedIn", descending: true) | |
.whereField("currentCountryLocation", isEqualTo: country) | |
.limit(to: 10) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.whereField("countries", arrayContains: country) | |
.whereField("datePosted", isGreaterThan: calendar.date(byAdding: .weekOfYear, value: -3, to: Date()) as Any) | |
.start(afterDocument: lastDocumentNearMePlans!) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.whereField("countries", arrayContains: country) | |
.whereField("datePosted", isGreaterThan: calendar.date(byAdding: .weekOfYear, value: -3, to: Date()) as Any) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: firestoreListenerBlocked = db.collection("Users").document(uid).collection("blocked").addSnapshotListener { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"followedInterests": tempArray, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"followedCountries": tempArray, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("CountryChats").document(country).updateData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
self.db.collection("CountryChats").document(country).setData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("CountryChats").document(country).collection("Followers").document(myuid).setData([ | |
"firstName": firstNameSaved, | |
"profilePicture": urlToSubmit, | |
"dateFollowed": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("CountryChats").document(country).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
]) { err in | |
if err != nil { | |
self.db.collection("CountryChats").document(country).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("CountryChats").document(country).collection("Followers").document(myuid).delete { err in | |
if let err = err { | |
print("Error removing document: \(err)") | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"blockedUsers": tempArray, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(uid).collection("blocked").document(Auth.auth().currentUser!.uid).setData([ | |
"dateBlocked": FieldValue.serverTimestamp(), | |
"blockedBy": Auth.auth().currentUser!.uid, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).collection("recents").document(uid).delete { err in | |
if let err = err { | |
print(err.localizedDescription) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(uid).collection("recents").document(Auth.auth().currentUser!.uid).delete { err in | |
if let err = err { | |
print(err.localizedDescription) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"blockedUsers": tempArray, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(uid).collection("blocked").document(Auth.auth().currentUser!.uid).delete { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.whereField("creator", isEqualTo: Auth.auth().currentUser!.uid) | |
.limit(to: 10) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.whereField("creator", isEqualTo: Auth.auth().currentUser!.uid) | |
.start(afterDocument: lastDocumentMyPosts!) | |
.limit(to: 5) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("creator", isEqualTo: Auth.auth().currentUser!.uid) | |
.limit(to: 10) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("creator", isEqualTo: Auth.auth().currentUser!.uid) | |
.start(afterDocument: lastDocumentMyPlans!) | |
.limit(to: 5) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let listener = db.collection("Users").document(uid).collection("planRecents").order(by: "dateOfLastMessage", descending: true).addSnapshotListener { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let listener = db.collection("Users").document(uid).collection("recents").order(by: "timestamp", descending: true).addSnapshotListener { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap = try! await db.collection("Users").document(Auth.auth().currentUser!.uid).collection("Notifications").order(by: "dateCreated", descending: true).whereField("dateCreated", isGreaterThan: (firstDocument!.get("dateCreated") as! Timestamp)).limit(to: 20).getDocuments() | |
if !snap.documents.isEmpty { | |
firstDocument = snap.documents[0] | |
for i in snap.documents { | |
_ = i.documentID | |
let notificationType = i.get("notificationType") as? String ?? "" | |
let dateCreated = i.get("dateCreated") as! Timestamp // .dateValue() | |
let nameOfUser = i.get("nameOfUser") as? String ?? "" | |
let urlProfilePicture = i.get("urlProfilePicture") as? String ?? "" | |
let creator = i.get("creator") as? String ?? "" | |
let postPlanUID = i.get("postPlanUID") as? String ?? "" | |
let planPicURL = i.get("planPicURL") as? String ?? "" | |
let postPicName = i.get("postPicName") as? String ?? "" | |
newNotifications.append(Notification(notificationType: notificationType, dateCreated: dateCreated.dateValue(), nameOfUser: nameOfUser, urlProfilePicture: urlProfilePicture, creator: creator, postPlanUID: postPlanUID, planPicURL: planPicURL, postPicName: postPicName)) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap = try! await db.collection("Users").document(Auth.auth().currentUser!.uid).collection("Notifications").order(by: "dateCreated", descending: true).limit(to: 15).getDocuments() | |
if !snap.documents.isEmpty { | |
firstDocument = snap.documents.first | |
lastDocumentNotification = snap.documents.last | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try! await db.collection("Posts").document(postId).getDocument() | |
if document.exists { | |
let documentData = document.data()! | |
let id = document.documentID | |
let likes = documentData["likes"] as! Int | |
let numComments = documentData["numComments"] as? Int ?? 0 | |
let datePosted = documentData["datePosted"] as! Timestamp | |
let postText = documentData["postText"] as! String | |
let countryInterestImage = documentData["countryInterestImage"] as! String | |
let usersThatLiked = documentData["usersThatLiked"] as! [String] | |
let creator = documentData["creator"] as! String | |
let userName = documentData["name"] as! String | |
let url = documentData["urlProfilePic"] as! String | |
let countryInterestName = documentData["countryorinterest"] as? String ?? "" | |
let lastCommentText = documentData["mostRecentCommentText"] as? String ?? "" | |
let lastCommentUser = documentData["mostRecentCommentUser"] as? String ?? "" | |
let date = datePosted.dateValue() | |
if usersThatLiked.contains(Auth.auth().currentUser!.uid) && !postsLikedThisSession.contains(id) { | |
postsLikedThisSession.append(id) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try! await db.collection("Plans").document(planId).getDocument() // fetch plan by id | |
if document.exists { | |
planToReturn = fetchPlanDataAsDocumentData(document: document) // get document data | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let planDocuments = try! await db.collection("Plans").order(by: "datePosted", descending: true) | |
.whereField("creator", isEqualTo: uid) | |
.getDocuments() | |
if !planDocuments.isEmpty { | |
for i in planDocuments.documents { | |
let plan = fetchPlanDataAsGet(i: i) // fetch document data | |
userPlans.append(plan) // append plans to temp array | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let planDocuments = try! await db.collection("Plans").order(by: "datePosted", descending: true) | |
.whereField("creator", isEqualTo: uid) | |
.limit(to: 2) | |
.getDocuments() | |
if !planDocuments.isEmpty { | |
for i in planDocuments.documents { | |
let plan = fetchPlanDataAsGet(i: i) // fetch document data | |
userPlans.append(plan) // add to the temp array | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try await db.collection("Users").document(uid).getDocument() | |
if document.exists { | |
let documentData = document.data()! | |
let dateLastSignedIn = documentData["dateLastSignedIn"] as? Timestamp ?? Timestamp(date: Date()) | |
var isActive = false | |
if getActiveStatus(lastSignedInDate: dateLastSignedIn.dateValue()) { | |
isActive = true | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try await db.collection("Users").document(uid).getDocument() | |
if document.exists { | |
let documentData = document.data()! | |
let date = documentData["birthday"] as! Timestamp | |
let dateFormatter = DateFormatter() | |
let calendar = Calendar.current | |
dateFormatter.dateFormat = "yyyy-MM-dd" | |
let stringDate = dateFormatter.string(from: date.dateValue()) | |
let intDate = calendar.dateComponents([.year], from: dateFormatter.date(from: stringDate) ?? Date.now, to: Date()) | |
let newDate = String(intDate.year ?? 0) | |
let dateLastSignedIn = documentData["dateLastSignedIn"] as? Timestamp ?? Timestamp(date: Date()) | |
let user = User(id: uid, firstName: documentData["firstName"] as! String, gender: documentData["gender"] as! String, country: documentData["country"] as! String, countryCode: documentData["countryCode"] as! String, birthday: newDate, bio: documentData["bio"] as! String, url: documentData["profilePicURL"] as! String, url2: documentData["profilePicURL2"] as? String ?? "", url3: documentData["profilePicURL3"] as? String ?? "", urlSmall: documentData["profilePicURLLowQuality"] as? String ?? "", recentTravelPlans: [], notifKey: documentData["notifToken"] as! String, dateLastSignedIn: dateLastSignedIn.dateValue(), languages: documentData["languages"] as? [String] ?? [], travelStatsCountries: documentData["travelStatsCountries"] as? [String] ?? [], travelStatsCountryCodes: documentData["travelStatsCountryCodes"] as? [String] ?? [], travelStatsYears: documentData["travelStatsYears"] as? [String] ?? [], myInterests: documentData["myInterests"] as? [String] ?? [], instagramUsername: documentData["instagramUserName"] as? String ?? "", latitude: documentData["latitude"] as? Double ?? 0.0, longitude: documentData["longitude"] as? Double ?? 0.0, locationHidden: documentData["locationHidden"] as? Bool ?? false, activityStatusHidden: documentData["activityStatusHidden"] as? Bool ?? false, subscriptionStatus: documentData["subscriptionStatus"] as? Bool ?? false, subscriptionDate: (documentData["subscriptionPurchaseDate"] as? Timestamp)?.dateValue() ?? Date.now, banned: documentData["banned"] as? Bool ?? false) | |
userToReturn.append(user) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try? await db.collection("BlockedUsers").document(Auth.auth().currentUser!.uid).getDocument() | |
if document != nil { | |
if document!.exists { | |
return true | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let userDocRef = db.collection("BlockedUsers").document(Auth.auth().currentUser!.uid) | |
_ = Auth.auth().currentUser!.uid | |
firestoreListenerBanned?.remove() | |
firestoreListenerBanned = userDocRef.addSnapshotListener { documentSnapshot, error in | |
if let error = error { | |
print("Error fetching document: \(error)") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snapshot = try! await db.collection("Posts").document(postId).collection("Comments").order(by: "datePosted", descending: false).getDocuments() | |
snapshot.documents.forEach { documentSnapshot in | |
let documentData = documentSnapshot.data() | |
// get comment replies | |
commentsToReturn.append(Comment(id: documentSnapshot.documentID, commentText: documentData["commentText"] as! String, userName: documentData["usersName"] as! String, datePosted: (documentData["datePosted"] as! Timestamp).dateValue(), userProfilePicture: documentData["urlProfilePicture"] as! String, creator: documentData["creator"] as! String, replies: [], numRepies: documentData["numReplies"] as? Int ?? 0)) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(user).collection("Notifications").addDocument(data: [ | |
"notificationType": "commentOnPostYouLiked", | |
"dateCreated": FieldValue.serverTimestamp(), | |
"nameOfUser": firstNameSaved, | |
"urlProfilePicture": urlToSubmit, | |
"creator": Auth.auth().currentUser!.uid, | |
"postPlanUID": postId, | |
"planPicURL": "", | |
"postPicName": countryInterestImage, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(user).collection("Notifications").addDocument(data: [ | |
"notificationType": "commentOnPostYouCommented", | |
"dateCreated": FieldValue.serverTimestamp(), | |
"nameOfUser": firstNameSaved, | |
"urlProfilePicture": urlToSubmit, | |
"creator": Auth.auth().currentUser!.uid, | |
"postPlanUID": postId, | |
"planPicURL": "", | |
"postPicName": countryInterestImage, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(postId).getDocument { document, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(postId).getDocument { document, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(postId).updateData([ | |
"mostRecentCommentText": commentReply.commentText, | |
"mostRecentCommentUser": urlToSubmit, | |
"numComments": FieldValue.increment(Int64(1)), | |
"usersThatCommented": FieldValue.arrayUnion([Auth.auth().currentUser!.uid]), | |
"usersThatCommentedNotifKeys": FieldValue.arrayUnion([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(postId).collection("Comments").document(originalCommentID).updateData([ | |
"numReplies": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(postId).collection("Comments").document(originalCommentID).collection("replies").document(commentReply.id).setData([ | |
"commentText": commentReply.commentText, | |
"usersName": commentReply.userName, | |
"datePosted": FieldValue.serverTimestamp(), | |
"creator": commentReply.creator, | |
"urlProfilePicture": commentReply.userProfilePicture, | |
"notifToken": deviceNotifToken, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: self.db.collection("Users").document(postCreator).collection("Notifications").addDocument(data: [ | |
// notificationType: planLike/postLike/postComment | |
// dateCreated: timestamp | |
// nameOfUser: name of user that liked/commented | |
// urlProfilePicture: profile picture of user that liked/commented | |
// creator: user uid that liked/commented | |
// postPlanUID: uid of the post or plan | |
// planPicURL: url of the plan or "" | |
// postPicName: name of the country/interest or "" | |
"notificationType": "postComment", | |
"dateCreated": FieldValue.serverTimestamp(), | |
"nameOfUser": self.firstNameSaved, | |
"urlProfilePicture": urlToSubmit, | |
"creator": Auth.auth().currentUser!.uid, | |
"postPlanUID": postId, | |
"planPicURL": "", | |
"postPicName": postLocation, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(postId).updateData([ | |
"mostRecentCommentText": comment.commentText, | |
"mostRecentCommentUser": urlToSubmit, | |
"numComments": FieldValue.increment(Int64(1)), | |
"usersThatCommented": FieldValue.arrayUnion([Auth.auth().currentUser!.uid]), | |
"usersThatCommentedNotifKeys": FieldValue.arrayUnion([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(postId).collection("Comments").document(comment.id).setData([ | |
"commentText": comment.commentText, | |
"usersName": comment.userName, | |
"datePosted": FieldValue.serverTimestamp(), | |
"creator": comment.creator, | |
"urlProfilePicture": comment.userProfilePicture, | |
"notifToken": deviceNotifToken, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: self.db.collection("Users").document(postCreator).collection("Notifications").addDocument(data: [ | |
// notificationType: planLike/postLike/postComment | |
// dateCreated: timestamp | |
// nameOfUser: name of user that liked/commented | |
// urlProfilePicture: profile picture of user that liked/commented | |
// creator: user uid that liked/commented | |
// postPlanUID: uid of the post or plan | |
// planPicURL: url of the plan or "" | |
// postPicName: name of the country/interest or "" | |
"notificationType": "postComment", | |
"dateCreated": FieldValue.serverTimestamp(), | |
"nameOfUser": self.firstNameSaved, | |
"urlProfilePicture": urlToSubmit, | |
"creator": Auth.auth().currentUser!.uid, | |
"postPlanUID": postId, | |
"planPicURL": "", | |
"postPicName": postLocation, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(post.id).updateData([ | |
"likes": FieldValue.increment(Int64(1)), | |
"usersThatLiked": FieldValue.arrayUnion([Auth.auth().currentUser!.uid]), | |
"usersThatLikedNotifKeys": FieldValue.arrayUnion([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(post.creator).collection("Notifications").addDocument(data: [ | |
"notificationType": "postLiked", | |
"dateCreated": FieldValue.serverTimestamp(), | |
"nameOfUser": firstNameSaved, | |
"urlProfilePicture": urlToSubmit, | |
"creator": Auth.auth().currentUser!.uid, | |
"postPlanUID": post.id, | |
"planPicURL": "", | |
"postPicName": post.countryInterestImage, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts").document(post.id).updateData([ | |
"likes": FieldValue.increment(Int64(-1)), | |
"usersThatLiked": FieldValue.arrayRemove([Auth.auth().currentUser?.uid ?? ""]), | |
"usersThatLikedNotifKeys": FieldValue.arrayRemove([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(post.creator).collection("Notifications").whereField("postPlanUID", isEqualTo: post.id).getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: self.db.collection("Users").document(post.creator).collection("Notifications").document(document.documentID).delete { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans").document(plan.id).updateData([ | |
"numSaves": FieldValue.increment(Int64(1)), | |
"usersThatSaved": FieldValue.arrayUnion([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(plan.creator).collection("Notifications").addDocument(data: [ | |
"notificationType": "planLiked", | |
"dateCreated": FieldValue.serverTimestamp(), | |
"nameOfUser": firstNameSaved, | |
"urlProfilePicture": urlToSubmit, | |
"creator": Auth.auth().currentUser!.uid, | |
"postPlanUID": plan.id, | |
"planPicURL": plan.imageURL, | |
"postPicName": "", | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans").document(plan.id).updateData([ | |
"numSaves": FieldValue.increment(Int64(-1)), | |
"usersThatSaved": FieldValue.arrayRemove([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Users").document(plan.creator).collection("Notifications").whereField("postPlanUID", isEqualTo: plan.id).getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: self.db.collection("Users").document(plan.creator).collection("Notifications").document(document.documentID).delete { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try! await db.collection("Users").document(uid).getDocument() | |
if document.exists { | |
let documentData = document.data()! | |
let date = documentData["birthday"] as! Timestamp | |
let dateFormatter = DateFormatter() | |
let calendar = Calendar.current | |
dateFormatter.dateFormat = "yyyy-MM-dd" | |
let stringDate = dateFormatter.string(from: date.dateValue()) | |
let newDate = String(calendar.dateComponents([.year], from: dateFormatter.date(from: stringDate) ?? Date.now, to: Date()).year ?? 0) | |
let dateLastSignedIn = documentData["dateLastSignedIn"] as? Timestamp ?? Timestamp(date: Date()) | |
let user = User(id: uid, firstName: documentData["firstName"] as! String, gender: documentData["gender"] as! String, country: documentData["country"] as! String, countryCode: documentData["countryCode"] as! String, birthday: newDate, bio: documentData["bio"] as! String, url: documentData["profilePicURL"] as! String, url2: documentData["profilePicURL2"] as? String ?? "", url3: documentData["profilePicURL3"] as? String ?? "", urlSmall: documentData["profilePicURLLowQuality"] as? String ?? "", recentTravelPlans: [], notifKey: documentData["notifToken"] as! String, dateLastSignedIn: dateLastSignedIn.dateValue(), languages: documentData["languages"] as? [String] ?? [], travelStatsCountries: documentData["travelStatsCountries"] as? [String] ?? [], travelStatsCountryCodes: documentData["travelStatsCountryCodes"] as? [String] ?? [], travelStatsYears: documentData["travelStatsYears"] as? [String] ?? [], myInterests: documentData["myInterests"] as? [String] ?? [], instagramUsername: documentData["instagramUserName"] as? String ?? "", latitude: documentData["latitude"] as? Double ?? 0.0, longitude: documentData["longitude"] as? Double ?? 0.0, locationHidden: documentData["locationHidden"] as? Bool ?? false, activityStatusHidden: documentData["activityStatusHidden"] as? Bool ?? false, subscriptionStatus: documentData["subscriptionStatus"] as? Bool ?? false, subscriptionDate: (documentData["subscriptionPurchaseDate"] as? Timestamp)?.dateValue() ?? Date.now, banned: documentData["banned"] as? Bool ?? false) | |
sendMessageToDevice(deviceToken: user.notifKey, titleText: firstNameSaved, bodyText: bodyText, type: type, id: id) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("Search Text is empty and No Dates Selected") | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "startDate") | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("Search Text is empty and dates ARE selected") | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("planNameArray", arrayContains: searchText.lowercased()) | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("search text is not empty and no dates selected") | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.whereField("planNameArray", arrayContains: searchText.lowercased()) | |
.order(by: "startDate") | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("search text is not empty and dates Are selected") | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("country is selected but is empty and no dates selected") | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "startDate") | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("country is selected but is empty and dates ARE selected") | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("countries", arrayContains: currentCountry) | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("country is selected and is not empty and no dates selected") | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.whereField("countries", arrayContains: currentCountry) | |
.order(by: "startDate") | |
.start(afterDocument: lastDocumentSearched!) | |
.limit(to: 5) | |
.getDocuments() | |
print("country is selected and is not empty and dates ARE selected") | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "startDate") | |
.limit(to: 5) | |
.getDocuments() | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("planNameArray", arrayContains: searchText.lowercased()) | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.whereField("planNameArray", arrayContains: searchText.lowercased()) | |
.order(by: "startDate") | |
.limit(to: 5) | |
.getDocuments() | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.order(by: "startDate") | |
.limit(to: 5) | |
.getDocuments() | |
} | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("countries", arrayContains: currentCountry) | |
.order(by: "datePosted", descending: true) | |
.limit(to: 5) | |
.getDocuments() | |
} else { | |
./Travely/ViewModel/HomeViewModel.swift: snap = try! await db.collection("Plans") | |
.whereField("startDate", isGreaterThanOrEqualTo: startDate) | |
.whereField("countries", arrayContains: currentCountry) | |
.order(by: "startDate") | |
.limit(to: 5) | |
.getDocuments() | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.whereField("countryorinterest", isEqualTo: interest) | |
.start(afterDocument: lastDocumentInterestPosts!) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap2 = try! await db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.whereField("countryorinterest", isEqualTo: interest) | |
.limit(to: 4) | |
.getDocuments() | |
for i in snap2.documents { | |
let id = i.documentID | |
let creator = i.get("creator") as? String ?? "" | |
let post = i.get("postText") as? String ?? "" | |
let numLikes = i.get("likes") as? Int ?? 0 | |
let numComments = i.get("numComments") as? Int ?? 0 | |
let datePostedTS = i.get("datePosted") as? Timestamp ?? Timestamp(date: Date()) | |
let name = i.get("name") as? String ?? "" | |
let url = i.get("urlProfilePic") as? String ?? "" | |
let countryInterestImage = i.get("countryInterestImage") as? String ?? "" | |
let usersThatLiked = i.get("usersThatLiked") as? [String] ?? [] | |
let countryInterestName = i.get("countryorinterest") as? String ?? "" | |
let datePosted = datePostedTS.dateValue() | |
let lastCommentText = i.get("mostRecentCommentText") as? String ?? "" | |
let lastCommentUser = i.get("mostRecentCommentUser") as? String ?? "" | |
if usersThatLiked.contains(Auth.auth().currentUser!.uid) && !postsLikedThisSession.contains(id) { | |
postsLikedThisSession.append(id) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("interests", arrayContains: interest) | |
.start(afterDocument: lastDocumentInterestPlans!) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap2 = try! await db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("interests", arrayContains: interest) | |
.limit(to: 4) | |
.getDocuments() | |
for i in snap2.documents { | |
let plan = fetchPlanDataAsGet(i: i) // fetch document data | |
DispatchQueue.main.async { | |
self.plansByInterest.append(plan) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.whereField("countryorinterest", isEqualTo: country) | |
.start(afterDocument: lastDocumentCountryPosts!) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Posts") | |
.order(by: "datePosted", descending: true) | |
.whereField("countryorinterest", isEqualTo: country) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("countries", arrayContains: country) | |
.start(afterDocument: lastDocumentCountryPlans!) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("countries", arrayContains: country) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try! await db.collection("Plans").document(planId).getDocument() // get plan document | |
if document.exists { | |
let plan = fetchPlanDataAsDocumentData(document: document) // fetch document data | |
DispatchQueue.main.async { | |
self.mostPopularPlans.append(plan) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: self.db.collection("Plans") | |
.whereField("numLikes", isGreaterThan: 12) | |
.order(by: "numLikes", descending: false) | |
.order(by: "datePosted", descending: true) | |
.start(afterDocument: self.lastDocumentRecommended!) | |
.limit(to: 4) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let MonthPlansSnap = try! await db.collection("PopularMonthPlans").getDocuments() // same as trending plans, fetch document that contains array of document id's to fetch | |
let documentDataTrending = MonthPlansSnap.documents[0].data() // get the first document | |
let planIds2 = documentDataTrending["plans"] as! [String] // get the plan id's | |
// only fetch the first 3 plans | |
for planId in planIds2[0 ... 2] { | |
let document = try! await db.collection("Plans").document(planId).getDocument() | |
if document.exists { | |
let plan = fetchPlanDataAsDocumentData(document: document) // fetch document data | |
DispatchQueue.main.async { | |
self.mostPopularPlans.append(plan) // append the plan to popular plans array | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap = try await db.collection("Plans") | |
.whereField("numLikes", isGreaterThan: 12) | |
.order(by: "numLikes", descending: false) | |
.order(by: "datePosted", descending: true) | |
.limit(to: 4) | |
.getDocuments() | |
if !snap.documents.isEmpty { | |
for i in snap.documents { | |
let plan = fetchPlanDataAsGet(i: i) // fetch document data | |
plansRecommendedForYou.append(plan) // append plan to array | |
} | |
./Travely/ViewModel/HomeViewModel.swift: self.db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("usersThatSaved", arrayContains: String(Auth.auth().currentUser!.uid)) | |
.start(afterDocument: self.lastDocument!) | |
.limit(to: 5) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try! await db.collection("Plans").document(planId).getDocument() // fetch document from firebase | |
if document.exists { | |
let plan = fetchPlanDataAsDocumentData(document: document) // fetch document data | |
DispatchQueue.main.async { | |
self.plans.append(plan) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let userDocumentRef = db.collection("Users").document(Auth.auth().currentUser!.uid) | |
let updatedData: [String: Any] = [ | |
"currentCountryLocation": country, | |
"dateLastSignedIn": FieldValue.serverTimestamp(), | |
"latitude": coords.latitude, // location view model | |
"longitude": coords.longitude, // location view model | |
] | |
try await userDocumentRef.updateData(updatedData) | |
} catch {} | |
./Travely/ViewModel/HomeViewModel.swift: let TrendingPlansSnap = try! await db.collection("TrendingPlans").getDocuments() // 10 trending plans from firebase | |
let documentDataTrending = TrendingPlansSnap.documents[0].data() // All 10 plan document id's are stored in an array in the first document | |
let planIds = documentDataTrending["plans"] as! [String] // gets the plan id's from the document | |
// only load the first 3 trending plan documents | |
var index = 0 | |
if planIds.count > 3 { | |
index = 2 | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let document = try! await db.collection("Plans").document(planId).getDocument() | |
if document.exists { | |
let plan = fetchPlanDataAsDocumentData(document: document) // fetches all the document data | |
DispatchQueue.main.async { | |
self.plans.append(plan) | |
} | |
./Travely/ViewModel/HomeViewModel.swift: let snap2 = try! await db.collection("Plans") | |
.order(by: "datePosted", descending: true) | |
.whereField("usersThatSaved", arrayContains: String(Auth.auth().currentUser!.uid)) | |
.limit(to: 5) | |
.getDocuments() | |
for i in snap2.documents { | |
let plan = fetchPlanDataAsGet(i: i) // fetches all the document data | |
DispatchQueue.main.async { | |
self.likedPlans.append(plan) | |
} | |
./Travely/ViewModel/PremiumViewModel.swift: db.collection("Users").document(uid).updateData(data) { err in | |
if let err = err { | |
print("Error updating document: \(err)") | |
} | |
./Travely/ViewModel/PremiumViewModel.swift: db.collection("Users").document(uid).updateData(data) { err in | |
if let err = err { | |
print("Error updating document: \(err)") | |
} | |
./Travely/ViewModel/UserActivityUpdater.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"currentCountryLocation": locationViewModel.country, | |
"dateLastSignedIn": FieldValue.serverTimestamp(), | |
"latitude": locationViewModel.coordinates.latitude, | |
"longitude": locationViewModel.coordinates.longitude, | |
]) { err in | |
if err != nil { | |
_ = err | |
return | |
} | |
./Travely/Future Stuff (not active)/CommunityPage.swift: db.collection("CountryChats").document(country.name).updateData([ | |
"numViews": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
db.collection("CountryChats").document(country.name).setData([ | |
"numViews": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/Future Stuff (not active)/CommunityPage.swift: let document = try! await db.collection("CountryChats").document(country.name).getDocument() | |
if document.exists { | |
let documentData = document.data()! | |
numFollowers = documentData["numLikes"] as? Int ?? 0 | |
numFollowers = numFollowers + 1243 | |
} | |
./Travely/View/Messages Page/Messages.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).collection("planRecents").document(id).delete { err in | |
if let err = err { | |
print(err.localizedDescription) | |
} | |
./Travely/View/Messages Page/Messages.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).collection("recents").document(id).delete { err in | |
if let err = err { | |
print(err.localizedDescription) | |
} | |
./Travely/View/Messages Page/MessageBubble.swift: db.collection("msgs").document(myUID).collection(userUID).document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Messages Page/MessageBubble.swift: db.collection("msgs").document(userUID).collection(myUID).document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Messages Page/MessageBubble.swift: db.collection("msgs").document(myUID).collection(userUID).document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Messages Page/MessageBubble.swift: db.collection("msgs").document(userUID).collection(myUID).document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Messages Page/MessageBubble.swift: db.collection("msgs").document(myUID).collection(userUID).document(message.id).updateData([ | |
"deleted": true, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Messages Page/MessageBubble.swift: db.collection("msgs").document(userUID).collection(myUID).document(message.id).updateData([ | |
"deleted": true, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Messages Page/Requests.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).collection("planRecents").document(id).delete { err in | |
if let err = err { | |
print(err.localizedDescription) | |
} | |
./Travely/View/Messages Page/Requests.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).collection("recents").document(id).delete { err in | |
if let err = err { | |
print(err.localizedDescription) | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("Users").document(myuid).collection("recents").document(uid).updateData([ | |
"read": true, | |
]) | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("msgs").document(uid).collection(messageData.id).order(by: "timestamp", descending: true).whereField("timestamp", isLessThan: firstDocumentDate as Any).limit(to: 10).getDocuments { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: let newListener = db.collection("msgs").document(uid).collection(messageData.id).order(by: "timestamp", descending: true).start(afterDocument: earliestMessageDocument).limit(to: 10).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: let newListener = db.collection("msgs").document(uid).collection(messageData.id).order(by: "timestamp", descending: true).limit(to: 20).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("Users").document(uid).collection("Recents").document(myuid).getDocument { snap, err in | |
if err != nil { | |
setRecent(user: user, uid: uid, pic: pic, msg: msg, date: date, request: request) | |
return | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("Users").document(uid).collection("recents").document(myuid).setData([ | |
"name": firstNameSaved, | |
"url": urlToSubmit, | |
"lastmsg": msg, | |
"timestamp": FieldValue.serverTimestamp(), | |
"notifKey": deviceNotifToken, | |
"sender": false, | |
"read": false, | |
"request": request, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("Users").document(myuid).collection("recents").document(uid).setData([ | |
"name": user, | |
"url": pic, | |
"lastmsg": msg, | |
"timestamp": FieldValue.serverTimestamp(), | |
"notifKey": messageData.notifToken, | |
"sender": true, | |
"read": false, | |
"request": false, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("Users").document(uid).collection("recents").document(myuid).updateData([ | |
"lastmsg": lastmsg, | |
"timestamp": FieldValue.serverTimestamp(), | |
"sender": false, | |
"read": false, | |
"request": request, | |
]) | |
db.collection("Users").document(myuid).collection("recents").document(uid).updateData([ | |
"lastmsg": lastmsg, | |
"timestamp": FieldValue.serverTimestamp(), | |
"sender": true, | |
"read": false, | |
"request": false, | |
]) | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("msgs").document(uid).collection(myuid).document(documentId).setData([ | |
"id": documentId, | |
"msg": msg, | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Messages Page/ProfileMessage.swift: db.collection("msgs").document(myuid).collection(uid).document(documentId).setData([ | |
"id": documentId, | |
"msg": msg, | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Main Views/BannedView.swift: try await db.collection("msgs").document(Auth.auth().currentUser!.uid).delete() | |
try await db.collection("Users").document(Auth.auth().currentUser!.uid).delete() | |
UIApplication.shared.unregisterForRemoteNotifications() | |
homeData.firestoreListenerBlocked?.remove() | |
homeData.usersThatBlockedMe.removeAll() | |
homeData.firestoreListener?.remove() | |
homeData.recents.removeAll() | |
homeData.plans.removeAll() | |
homeData.mostPopularPlans.removeAll() | |
homeData.trendingThisWeekPlans.removeAll() | |
homeData.plansRecommendedForYou.removeAll() | |
homeData.likedPlans.removeAll() | |
try Auth.auth().signOut() | |
firstNameSaved = "" | |
lastNameSaved = "" | |
bioSaved = "" | |
genderSaved = "" | |
urlSaved = "" | |
urlSmallSaved = "" | |
birthDataSaved = "" | |
countrySaved = "" | |
countryCodeSaved = "" | |
deviceNotifToken = "" | |
likedPlansSavedArray = "" | |
blockedArray = "" | |
withAnimation { status = false } | |
./Travely/View/Nearby Page/Nearby/NearMeChat.swift: db.collection("CountryChats").document(country).collection("messages").order(by: "timestamp", descending: true).whereField("timestamp", isLessThan: firstDocumentDate as Any).limit(to: 10).getDocuments { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Nearby Page/Nearby/NearMeChat.swift: let newListener = db.collection("CountryChats").document(country).collection("messages").order(by: "timestamp", descending: true).start(afterDocument: earliestMessageDocument).limit(to: 10).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Nearby Page/Nearby/NearMeChat.swift: let newListener = db.collection("CountryChats").document(country).collection("messages").order(by: "timestamp", descending: true).limit(to: 20).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Nearby Page/Nearby/NearMeChat.swift: db.collection("CountryChats").document(country).collection("messages").document(documentId).setData([ | |
"id": documentId, | |
"msg": msg, | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
"userName": firstNameSaved, | |
"profilePicURL": urlToSubmit, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Nearby Page/Nearby/NearMeMessage.swift: db.collection("CountryChats").document(country).collection("messages").document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
"usersThatLiked": FieldValue.arrayRemove([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Nearby Page/Nearby/NearMeMessage.swift: db.collection("CountryChats").document(country).collection("messages").document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
"usersThatLiked": FieldValue.arrayUnion([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Nearby Page/Nearby/NearMeMessage.swift: db.collection("CountryChats").document(country).collection("messages").document(message.id).updateData([ | |
"deleted": true, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripsPage.swift: let snap = try! await db.collection("GroupTrips") | |
.order(by: "startDate", descending: true) | |
.getDocuments() | |
for i in snap.documents { | |
let id = i.documentID | |
let title = i.get("title") as? String ?? "" | |
let imageURL = i.get("imageURL") as? String ?? "" | |
let spots = i.get("spots") as? Int ?? 0 | |
let active = i.get("active") as? Bool ?? false | |
let country = i.get("country") as? String ?? "" | |
let days = i.get("days") as? Int ?? 0 | |
let endDate = i.get("endDate") as? Timestamp ?? Timestamp(date: Date()) | |
let endDates = i.get("endDates") as? [Timestamp] ?? [] | |
let guided = i.get("guided") as? Bool ?? false | |
let included = i.get("included") as? [String] ?? [] | |
let includedImages = i.get("includedImages") as? [String] ?? [] | |
let itineraryTitles = i.get("itineraryTitles") as? [String] ?? [] | |
let itineraryDetails = i.get("itineraryDetails") as? [String] ?? [] | |
let itineraryPics = i.get("itineraryPics") as? [String] ?? [] | |
let overview = i.get("overview") as? String ?? "" | |
let partner = i.get("partner") as? String ?? "" | |
let partnerLogo = i.get("partnerLogo") as? String ?? "" | |
let price = i.get("price") as? Int ?? 0 | |
let startDate = i.get("startDate") as? Timestamp ?? Timestamp(date: Date()) | |
let startDates = i.get("startDates") as? [Timestamp] ?? [] | |
let link = i.get("link") as? String ?? "" | |
let numPeople = i.get("numPeople") as? Int ?? 0 | |
let urls = i.get("urls") as? [String] ?? [] | |
let shareLink = i.get("shareLink") as? String ?? "" | |
let youtube = i.get("youtube") as? String ?? "" | |
let spotsHidden = i.get("spotsHidden") as? Bool ?? false | |
var startDatesNew = [Date]() | |
for timestamp in startDates { | |
startDatesNew.append(timestamp.dateValue()) | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDiscussion.swift: let snap = try! await db.collection("GroupTrips") | |
.whereField("title", isEqualTo: discussionData.name) | |
.getDocuments() | |
bellEnabled = false | |
for i in snap.documents { | |
let userIds = i.get("userIdsNotification") as? [String] ?? [] | |
let notifs = i.get("notifKeys") as? [String] ?? [] | |
for id in userIds { | |
if id == myuid { | |
bellEnabled = true | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDiscussion.swift: db.collection("GroupTrips").document(discussionData.id).updateData([ | |
"userIdsNotification": FieldValue.arrayUnion([myuid]), | |
"notifKeys": FieldValue.arrayUnion([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDiscussion.swift: db.collection("GroupTrips").document(discussionData.id).updateData([ | |
"userIdsNotification": FieldValue.arrayRemove([myuid]), | |
"notifKeys": FieldValue.arrayRemove([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDiscussion.swift: db.collection("GroupTrips").document(discussionData.id).collection("messages").order(by: "timestamp", descending: true).whereField("timestamp", isLessThan: firstDocumentDate as Any).limit(to: 10).getDocuments { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDiscussion.swift: let newListener = db.collection("GroupTrips").document(discussionData.id).collection("messages").order(by: "timestamp", descending: true).start(afterDocument: earliestMessageDocument).limit(to: 10).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDiscussion.swift: let newListener = db.collection("GroupTrips").document(discussionData.id).collection("messages").order(by: "timestamp", descending: true).limit(to: 20).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDiscussion.swift: db.collection("GroupTrips").document(planId).collection("messages").document(documentId).setData([ | |
"id": documentId, | |
"msg": msg, | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
"userName": name, | |
"profilePicURL": profilePicture, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripView.swift: db.collection("GroupTrips").document(trip.id).updateData([ | |
"userIdsNotification": FieldValue.arrayUnion([myuid]), | |
"notifKeys": FieldValue.arrayUnion([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripView.swift: db.collection("GroupTrips").document(trip.id).updateData([ | |
"userIdsNotification": FieldValue.arrayRemove([myuid]), | |
"notifKeys": FieldValue.arrayRemove([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripView.swift: let snap = try! await db.collection("GroupTrips") | |
.whereField("title", isEqualTo: trip.title) | |
.getDocuments() | |
bellEnabled = false | |
for i in snap.documents { | |
let userIds = i.get("userIdsNotification") as? [String] ?? [] | |
for id in userIds { | |
if id == myuid { | |
bellEnabled = true | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripView.swift: let documentRef = db.collection("GroupTrips").document(tripID) | |
let snapshot = try! await documentRef.getDocument() | |
if snapshot.exists { | |
let documentData = snapshot.data()! | |
let id = snapshot.documentID | |
let title = documentData["title"] as? String ?? "" | |
let imageURL = documentData["imageURL"] as? String ?? "" | |
let spots = documentData["spots"] as? Int ?? 0 | |
let active = documentData["active"] as? Bool ?? false | |
let country = documentData["country"] as? String ?? "" | |
let days = documentData["days"] as? Int ?? 0 | |
let endDate = documentData["endDate"] as? Timestamp ?? Timestamp(date: Date()) | |
let endDates = documentData["endDates"] as? [Timestamp] ?? [] | |
let guided = documentData["guided"] as? Bool ?? false | |
let included = documentData["included"] as? [String] ?? [] | |
let includedImages = documentData["includedImages"] as? [String] ?? [] | |
let itineraryTitles = documentData["itineraryTitles"] as? [String] ?? [] | |
let itineraryDetails = documentData["itineraryDetails"] as? [String] ?? [] | |
let itineraryPics = documentData["itineraryPics"] as? [String] ?? [] | |
let overview = documentData["overview"] as? String ?? "" | |
let partner = documentData["partner"] as? String ?? "" | |
let partnerLogo = documentData["partnerLogo"] as? String ?? "" | |
let price = documentData["price"] as? Int ?? 0 | |
let startDate = documentData["startDate"] as? Timestamp ?? Timestamp(date: Date()) | |
let startDates = documentData["startDates"] as? [Timestamp] ?? [] | |
let link = documentData["link"] as? String ?? "" | |
let numPeople = documentData["numPeople"] as? Int ?? 0 | |
let urls = documentData["urls"] as? [String] ?? [] | |
let shareLink = documentData["shareLink"] as? String ?? "" | |
let youtube = documentData["youtube"] as? String ?? "" | |
let spotsHidden = documentData["spotsHidden"] as? Bool ?? false | |
var startDatesNew = [Date]() | |
for timestamp in startDates { | |
startDatesNew.append(timestamp.dateValue()) | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDM.swift: let newListener = db.collection("GroupTrips").document(groupTripId).collection("dms").document(uid).collection("messages").order(by: "timestamp", descending: true).start(afterDocument: earliestMessageDocument).limit(to: 10).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDM.swift: let newListener = db.collection("GroupTrips").document(groupTripId).collection("dms").document(uid).collection("messages").order(by: "timestamp", descending: true).limit(to: 20).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDM.swift: db.collection("GroupTrips").document(groupTripId).collection("dms").document(myuid).collection("messages").document(documentId).setData([ | |
"id": documentId, | |
"msg": msg, | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Explore Page/Group Trips/GroupTripDM.swift: db.collection("GroupTrips").document(groupTripId).collection("dms").document(myuid).setData([ | |
"lastMessageDate": FieldValue.serverTimestamp(), | |
"name": firstNameSaved, | |
"url": urlSmallSaved, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Search/SearchTripCity/SearchTripCityResults.swift: let documentRef = db.collection("GroupTrips").document("bali") | |
let snapshot = try! await documentRef.getDocument() | |
if snapshot.exists { | |
let documentData = snapshot.data()! | |
let id = snapshot.documentID | |
let title = documentData["title"] as? String ?? "" | |
let imageURL = documentData["imageURL"] as? String ?? "" | |
let spots = documentData["spots"] as? Int ?? 0 | |
let active = documentData["active"] as? Bool ?? false | |
let country = documentData["country"] as? String ?? "" | |
let days = documentData["days"] as? Int ?? 0 | |
let endDate = documentData["endDate"] as? Timestamp ?? Timestamp(date: Date()) | |
let endDates = documentData["endDates"] as? [Timestamp] ?? [] | |
let guided = documentData["guided"] as? Bool ?? false | |
let included = documentData["included"] as? [String] ?? [] | |
let includedImages = documentData["includedImages"] as? [String] ?? [] | |
let itineraryTitles = documentData["itineraryTitles"] as? [String] ?? [] | |
let itineraryDetails = documentData["itineraryDetails"] as? [String] ?? [] | |
let itineraryPics = documentData["itineraryPics"] as? [String] ?? [] | |
let overview = documentData["overview"] as? String ?? "" | |
let partner = documentData["partner"] as? String ?? "" | |
let partnerLogo = documentData["partnerLogo"] as? String ?? "" | |
let price = documentData["price"] as? Int ?? 0 | |
let startDate = documentData["startDate"] as? Timestamp ?? Timestamp(date: Date()) | |
let startDates = documentData["startDates"] as? [Timestamp] ?? [] | |
let link = documentData["link"] as? String ?? "" | |
let numPeople = documentData["numPeople"] as? Int ?? 0 | |
let urls = documentData["urls"] as? [String] ?? [] | |
let shareLink = documentData["shareLink"] as? String ?? "" | |
let youtube = documentData["youtube"] as? String ?? "" | |
let spotsHidden = documentData["spotsHidden"] as? Bool ?? false | |
var startDatesNew = [Date]() | |
for timestamp in startDates { | |
startDatesNew.append(timestamp.dateValue()) | |
} | |
./Travely/View/Home Page/TravelersGoing/TravelersGoingTripsSaved.swift: db.collection("Users").document(uid).collection("savedtrips").document(id).delete { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/TravelersGoing/TravelersGoingTripsSaved.swift: db.collection("TravelersGoing").document("Cities").collection(city).document(uid).delete { err2 in | |
if err2 != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/TravelersGoing/TravelersGoingTripsSaved.swift: db.collection("Users").document(myuid).collection("savedtrips") | |
.order(by: "startDate", descending: true) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/TravelersGoing/CreateTravelersGoing.swift: db.collection("TravelersGoing").document("Cities").collection(city).document(myuid).setData([ | |
"name": firstNameSaved, | |
"url": urlToSubmit, | |
"usersCountryCode": countryCodeSaved, | |
"city": city, | |
"country": country, | |
"countryCode": countryCode, | |
"startDate": startDate, | |
"endDate": endDate, | |
"uid": myuid, | |
]) { err in | |
if err != nil { | |
isLoading = false | |
return | |
} | |
./Travely/View/Home Page/TravelersGoing/CreateTravelersGoing.swift: db.collection("Users").document(myuid).collection("savedtrips").addDocument(data: [ | |
"city": city, | |
"country": country, | |
"countryCode": countryCode, | |
"startDate": startDate, | |
"endData": endDate, | |
]) { err in | |
if err != nil { | |
isLoading = false | |
return | |
} | |
./Travely/View/Home Page/Profile/EditProfile/EditProfile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"firstName": firstName, | |
"birthday": birthDate, | |
"bio": bio, | |
"gender": gender, | |
"country": country, | |
"countryCode": countryCode, | |
"profilePicURL": url!.absoluteString, | |
"profilePicURLLowQuality": url2!.absoluteString, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/Profile/EditProfile/EditProfile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"firstName": firstName, | |
"birthday": birthDate, | |
"bio": bio, | |
"gender": gender, | |
"country": country, | |
"countryCode": countryCode, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/Profile/EditProfile/NewEditProfile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"firstName": firstName, | |
"birthday": birthDate, | |
"bio": bio, | |
"gender": gender, | |
"country": country, | |
"countryCode": countryCode, | |
"instagramUserName": instaUserName, | |
"languages": languages, | |
"travelStatsCountries": travelStatsCountries, | |
"travelStatsCountryCodes": travelStatsCountryCodes, | |
"myInterests": interests, | |
]) { err in | |
if err != nil { | |
return | |
} else { | |
./Travely/View/Home Page/Profile/EditProfile/NewEditProfile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"profilePicURL": url!.absoluteString, | |
"profilePicURLLowQuality": url2!.absoluteString, | |
"defaultPhoto": false, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Profile/EditProfile/NewEditProfile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"profilePicURL2": url!.absoluteString, | |
]) { err in | |
if err != nil { return } | |
./Travely/View/Home Page/Profile/EditProfile/NewEditProfile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"profilePicURL3": url!.absoluteString, | |
]) { err in | |
if err != nil { return } | |
./Travely/View/Home Page/Profile/NewProfile.swift: db.collection("Users").document(myuid).collection("Friends").document(uid).getDocument { document, _ in | |
if let document = document, document.exists { | |
friend = true | |
} else { | |
./Travely/View/Home Page/Profile/NewProfile.swift: db.collection("Users").document(myuid).collection("Friends").document(uid).delete { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/Profile/NewProfile.swift: db.collection("Users").document(myuid).collection("Friends").document(uid).setData([ | |
"id": uid, | |
"firstName": user[0].firstName, | |
"url": userURLToSubmit, | |
"timestamp": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Home Page/Profile/NewProfile.swift: firestoreListener = db.collection("Users").document(Auth.auth().currentUser!.uid).collection("Friends").whereField("id", isEqualTo: uid).addSnapshotListener { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Profile/Profile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"locationHidden": false, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Home Page/Profile/Profile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"locationHidden": true, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Home Page/Profile/Profile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"activityStatusHidden": false, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Home Page/Profile/Profile.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"activityStatusHidden": true, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Home Page/Profile/Profile.swift:// db.collection("msgs").document(Auth.auth().currentUser!.uid).delete { error in | |
// | |
// if let error = error { | |
// print(error.localizedDescription) | |
// } else { | |
./Travely/View/Home Page/Profile/Profile.swift:// db.collection("Users").document(Auth.auth().currentUser!.uid).delete { error in | |
// | |
// if let error = error { | |
// print(error.localizedDescription) | |
// } else { | |
./Travely/View/Home Page/Profile/Profile.swift: try await db.collection("msgs").document(userId).delete() | |
print("delete msg success") | |
try await db.collection("Users").document(userId).delete() | |
print("delete user success") | |
try await Auth.auth().currentUser?.delete() | |
print("delete user auth success") | |
} catch { | |
./Travely/View/Home Page/Profile/MyFriends.swift: db.collection("Users").document(myuid).collection("Friends") | |
.order(by: "timestamp", descending: true) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Profile/MyPlansAndPosts.swift: db.collection("Plans").document(id).delete { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/Profile/MyPlansAndPosts.swift: db.collection("Users").document(userid).collection("planRecents").document(id).delete { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/Profile/MyPlansAndPosts.swift: db.collection("Posts").document(id).delete { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/Profile/BlockUser.swift: // db.collection("ReportedUsers").document(user.id).collection("reports").document().setData([ | |
// | |
// "userThatReported": Auth.auth().currentUser!.uid, | |
// "reportMessage": self.text, | |
// "date": Date.now | |
// | |
// | |
// ]) { err in | |
// | |
// if err != nil{ | |
// | |
// return | |
// }else{ | |
./Travely/View/Home Page/Profile/ReportUser.swift: db.collection("ReportedUsers").addDocument(data: [ | |
"userThatReported": Auth.auth().currentUser!.uid, | |
"reportMessage": text, | |
"dateReported": FieldValue.serverTimestamp(), | |
"reportedUser": user.id, | |
"reportedUserName": user.firstName, | |
]) { err in | |
if err != nil { | |
return | |
} else { | |
./Travely/View/Home Page/Countries and Interests/ViewInterestHome.swift: let document = try! await db.collection("Communities").document(interest.name).getDocument() | |
if document.exists { | |
let documentData = document.data()! | |
numFollowers = documentData["numMembers"] as? Int ?? 0 | |
numFollowers = numFollowers + 1243 | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewInterestHome.swift: db.collection("Communities").document(interest.name).collection("members").document(uid).delete { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewInterestHome.swift: db.collection("Communities").document(interest.name).updateData([ | |
"numMembers": FieldValue.increment(Int64(-1)), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewInterestHome.swift: db.collection("Communities").document(interest.name).collection("members").document(uid).setData([ | |
"uid": uid, | |
"firstName": firstNameSaved, | |
"url": urlToSubmit, | |
"dateJoined": FieldValue.serverTimestamp(), | |
"notifToken": deviceNotifToken, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewInterestHome.swift: db.collection("Communities").document(interest.name).updateData([ | |
"numMembers": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewInterestHome.swift: db.collection("Communities").document(interest.name).updateData([ | |
"numViews": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
db.collection("Communities").document(interest.name).setData([ | |
"numViews": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewCountryHome.swift: db.collection("CountryChats").document(country.name).collection("Followers").order(by: "dateFollowed", descending: true).start(afterDocument: lastDocument!).limit(to: 15).getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewCountryHome.swift: db.collection("CountryChats").document(country.name).collection("Followers").order(by: "dateFollowed", descending: true).limit(to: 15).getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewCountryHome.swift: let document = try! await db.collection("CountryChats").document(country.name).getDocument() | |
if document.exists { | |
let documentData = document.data()! | |
numFollowers = documentData["numLikes"] as? Int ?? 0 | |
numFollowers = numFollowers + 1243 | |
} | |
./Travely/View/Home Page/Countries and Interests/ViewCountryHome.swift: db.collection("CountryChats").document(country.name).updateData([ | |
"numViews": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
db.collection("CountryChats").document(country.name).setData([ | |
"numViews": FieldValue.increment(Int64(1)), | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Post/ReportPost.swift: db.collection("ReportedPosts").document(post.id).collection("reports").document().setData([ | |
"userThatReported": Auth.auth().currentUser!.uid, | |
"reportMessage": text, | |
"date": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
return | |
} else { | |
./Travely/View/Plans & Posts/Post/NewFullPost.swift: let snapshot = try! await db.collection("Posts").document(postID).collection("Comments").document(comment.id).collection("replies").order(by: "datePosted", descending: false).getDocuments() | |
snapshot.documents.forEach { documentSnapshot in | |
let documentData = documentSnapshot.data() | |
// get comment replies | |
commentRepliesToReturn.append(CommentReply(id: documentSnapshot.documentID, originalCommentID: comment.id, commentText: documentData["commentText"] as! String, userName: documentData["usersName"] as! String, datePosted: (documentData["datePosted"] as! Timestamp).dateValue(), userProfilePicture: documentData["urlProfilePicture"] as! String, creator: documentData["creator"] as! String)) | |
} | |
./Travely/View/Plans & Posts/Post/CreatePlan.swift: db.collection("Posts").document(filename).setData([ | |
"postText": postData.postText, | |
"countryorinterest": countryOrInterestSelected, | |
"countryInterestImage": countryInterestImage, | |
"datePosted": FieldValue.serverTimestamp(), | |
"creator": Auth.auth().currentUser?.uid as Any, | |
"name": firstNameSaved, | |
"urlProfilePic": urlToSubmit, | |
"usersThatLiked": [], | |
"likes": 0, | |
]) { err in | |
if err != nil { | |
postDisabled = false | |
// issue with the post | |
return | |
} else { | |
./Travely/View/Plans & Posts/Plan/EditPlanPage.swift: db.collection("Plans").document(planID).updateData([ | |
"planName": newPlanName, | |
"planNameArray": combinations, | |
"planDetails": planDetails, | |
"startDate": startDate, | |
"endDate": endDate, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/EditPlanPage.swift: db.collection("Plans").document(planID).collection("planUpdates").addDocument(data: [ | |
"message": "\(firstNameSaved) changed the plan name to \(newPlanName)", | |
"date": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/ReportPlan.swift: db.collection("ReportedPlans").document(plan.id).collection("reports").document().setData([ | |
"userThatReported": Auth.auth().currentUser!.uid, | |
"reportMessage": text, | |
"date": FieldValue.serverTimestamp(), | |
]) { err in | |
if err != nil { | |
return | |
} else { | |
./Travely/View/Plans & Posts/Plan/NewFullPlan.swift: db.collection("Plans").document(plan.id).updateData([ | |
"notifTokens": FieldValue.arrayUnion([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/NewFullPlan.swift: db.collection("Plans").document(plan.id).collection("messages").document(documentId).setData([ | |
"id": documentId, | |
"msg": "joined the group", | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
"userName": firstNameSaved, | |
"profilePicURL": urlToSubmit, | |
"special": true, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/NewFullPlan.swift: db.collection("Plans").document(plan.id).collection("members").document(uid).setData([ | |
"id": uid, | |
"status": "joined", | |
"firstName": firstNameSaved, | |
"url": urlToSubmit, | |
"dateJoined": FieldValue.serverTimestamp(), | |
"notifToken": deviceNotifToken, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/NewFullPlan.swift: db.collection("Plans").document(plan.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
"usersThatLiked": FieldValue.arrayUnion([uid]), | |
"notifTokens": FieldValue.arrayUnion([deviceNotifToken]), | |
]) { err2 in | |
if err2 != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/NewFullPlan.swift: db.collection("Users").document(plan.creator).collection("Notifications").addDocument(data: [ | |
"notificationType": "groupJoined", | |
"dateCreated": FieldValue.serverTimestamp(), | |
"nameOfUser": firstNameSaved, | |
"urlProfilePicture": urlToSubmit, | |
"creator": Auth.auth().currentUser!.uid, | |
"postPlanUID": plan.id, | |
"planPicURL": plan.imageURL, | |
"postPicName": "", | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/NewFullPlan.swift: firestoreListener = db.collection("Plans").document(plan.id).collection("members").whereField("id", isEqualTo: uid).addSnapshotListener { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/NewFullPlan.swift: db.collection("Users").document(id).getDocument { document, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/CreatePost.swift: db.collection("Plans").document(filename).setData([ | |
"planName": planName, | |
"planNameArray": combinations, | |
"planDetails": planDetails, | |
"countries": countriesSelected, | |
"countriesCode": countriesSelectedCode, | |
"countriesCont": countriesContinent, | |
"interests": interestsSelected, | |
"startDate": startDate, | |
"endDate": endDate, | |
"numLikes": 1, | |
"numSaves": 1, | |
"datePosted": FieldValue.serverTimestamp(), | |
"usersThatLiked": [Auth.auth().currentUser!.uid], | |
"usersThatSaved": [Auth.auth().currentUser!.uid], | |
"creator": Auth.auth().currentUser!.uid, | |
"userName": firstNameSaved, | |
"userProfilePicURL": urlToSubmit, | |
"planURL": url!.absoluteString, | |
"lowQualityPlanURL": url2!.absoluteString, | |
"notifTokens": [], | |
]) { err in | |
if err != nil { | |
isPresented.toggle() | |
rotation.toggle() | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/CreatePost.swift: db.collection("Plans").document(filename).collection("members").document(uid).setData([ | |
"id": uid, | |
"status": "joined", | |
"firstName": firstNameSaved, | |
"url": urlToSubmit, | |
"dateJoined": FieldValue.serverTimestamp(), | |
"notifToken": deviceNotifToken, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(discussionData.id).collection("members").document(uid).delete { err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(discussionData.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
"usersThatLiked": FieldValue.arrayRemove([Auth.auth().currentUser?.uid ?? ""]), | |
"notifTokens": FieldValue.arrayRemove([deviceNotifToken]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).collection("planRecents").document(discussionData.id).delete { err in | |
if let err = err { | |
print(err.localizedDescription) | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(discussionData.id).collection("messages").document(documentId).setData([ | |
"id": documentId, | |
"msg": "left the group", | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
"userName": firstNameSaved, | |
"profilePicURL": urlToSubmit, | |
"special": true, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(discussionData.id).collection("planUpdates") | |
.order(by: "date", descending: true) | |
.getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: let groupChatRef = db.collection("Plans").document(planID) | |
if isTyping { | |
groupChatRef.updateData([ | |
"users_typing.\(userID)": userName, | |
]) | |
} else { | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: let groupChatRef = db.collection("Plans").document(discussionData.id) | |
groupChatRef.addSnapshotListener { documentSnapshot, error in | |
guard let document = documentSnapshot, let data = document.data() else { | |
print("Error fetching document: \(error?.localizedDescription ?? "")") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(discussionData.id).collection("messages").order(by: "timestamp", descending: true).whereField("timestamp", isLessThan: firstDocumentDate as Any).limit(to: 10).getDocuments { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: let newListener = db.collection("Plans").document(discussionData.id).collection("messages").order(by: "timestamp", descending: true).start(afterDocument: earliestMessageDocument).limit(to: 10).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Users").document(myuid).collection("planRecents").document(uid).updateData([ | |
"read": true, | |
]) | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: let newListener = db.collection("Plans").document(discussionData.id).collection("messages").order(by: "timestamp", descending: true).limit(to: 20).addSnapshotListener { snap, err in | |
if err != nil { | |
print(err?.localizedDescription as Any) | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(planId).collection("messages").document(documentId).setData([ | |
"id": documentId, | |
"msg": msg, | |
"user": myuid, | |
"timestamp": FieldValue.serverTimestamp(), | |
"userName": firstNameSaved, | |
"profilePicURL": urlToSubmit, | |
"special": false, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(planId).getDocument { document, _ in | |
if let document = document, document.exists { | |
let dataDescription = document.data() | |
// Extracting the fields | |
if let notifTokens = dataDescription?["notifTokens"] as? [String], | |
let usersThatLiked = dataDescription?["usersThatLiked"] as? [String] | |
{ | |
for token in notifTokens { | |
homeData.sendMessageToDevice(deviceToken: token, titleText: discussionData.name, bodyText: "\(firstNameSaved) sent a message", type: "plan", id: planId) | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Users").document(myuid).collection("planRecents").document(planId).setData([ | |
"lastMessage": msg, | |
"dateOfLastMessage": FieldValue.serverTimestamp(), | |
"lastMessageSender": myuid, | |
"planName": discussionData.name, | |
"planURL": discussionData.imageURL, | |
"notifkeys": notifTokens, | |
"usersThatLiked": usersThatLiked, | |
"read": true, | |
"sender": true, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Users").document(userid).collection("planRecents").document(planId).setData([ | |
"lastMessage": msg, | |
"dateOfLastMessage": FieldValue.serverTimestamp(), | |
"lastMessageSender": myuid, | |
"planName": discussionData.name, | |
"planURL": discussionData.imageURL, | |
"notifkeys": notifTokens, | |
"usersThatLiked": usersThatLiked, | |
"read": true, | |
"sender": true, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Users").document(userid).collection("planRecents").document(planId).setData([ | |
"lastMessage": msg, | |
"dateOfLastMessage": FieldValue.serverTimestamp(), | |
"lastMessageSender": myuid, | |
"planName": discussionData.name, | |
"planURL": discussionData.imageURL, | |
"notifkeys": notifTokens, | |
"usersThatLiked": usersThatLiked, | |
"read": false, | |
"sender": false, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionView.swift: db.collection("Plans").document(planId).updateData([ | |
"dateOfLastMessage": FieldValue.serverTimestamp(), | |
"lastMessage": msg, | |
"lastMessageSender": myuid, | |
]) { err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionDetails.swift: db.collection("Plans").document(planID).collection("members").order(by: "dateJoined", descending: true).start(afterDocument: lastDocument!).limit(to: 15).getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionDetails.swift: db.collection("Plans").document(planID).collection("members").order(by: "dateJoined", descending: true).limit(to: 15).getDocuments { snap, err in | |
if err != nil { | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionMessage.swift: db.collection("Plans").document(planID).collection("messages").document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
"usersThatLiked": FieldValue.arrayRemove([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionMessage.swift: db.collection("GroupTrips").document(planID).collection("messages").document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(-1)), | |
"usersThatLiked": FieldValue.arrayRemove([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionMessage.swift: db.collection("Plans").document(planID).collection("messages").document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
"usersThatLiked": FieldValue.arrayUnion([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionMessage.swift: db.collection("GroupTrips").document(planID).collection("messages").document(message.id).updateData([ | |
"numLikes": FieldValue.increment(Int64(1)), | |
"usersThatLiked": FieldValue.arrayUnion([Auth.auth().currentUser?.uid ?? ""]), | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionMessage.swift: db.collection("Plans").document(planID).collection("messages").document(message.id).updateData([ | |
"deleted": true, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Plans & Posts/Plan/Discussion/DiscussionMessage.swift: db.collection("GroupTrips").document(planID).collection("messages").document(message.id).updateData([ | |
"deleted": true, | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/View/Premium RevenueCat/BuyPremium.swift: db.collection("Users").document(Auth.auth().currentUser!.uid).updateData([ | |
"subscriptionStatus": true, | |
"subscriptionExpirationDate": expirationDate ?? Date.now, | |
"subscriptionPurchaseDate": purchaseDate ?? Date.now, | |
"subscriptionType": subscriptionType ?? "error", | |
]) { err in | |
if err != nil { | |
print(err?.localizedDescription ?? "error printing error") | |
return | |
} | |
./Travely/StoreVM.swift:// db.collection("Users").document(Auth.auth().currentUser!.uid).updateData(dataToUpdate) { err in | |
// | |
// if err != nil{ | |
// print(err?.localizedDescription ?? "error printing error") | |
// return | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment