So, I am using Google Contacts API to let users import their contacts from GMail.
I want the users to be able to select the contacts they want to import in my app, So currently I -
GET a XML feed of all the contacts a user has.
Parse it, and for each contact create a record in the imported_contacts table.
Display the list to the user, with checkboxes, so the user can select which contacts it wants to import.
When the user submits the form, I copy the selected contacts from imported_contacts to the main contacts table.
This works fine, but doesn't feel right. Can someone suggest a way to do so, without using a separate table(imported_contacts).
Map the contacts from XML to objects in memory. Only save them to the main contacts table after the user has selected the ones she wants.
Model View Controller.
Import the contacts into Contact objects, and store in a ContactRepository. All of this is completely in-memory, and is your Model.
When rendering this list in your View, each checkbox will have an ID which will relate to the ID of the Contact object in the Model.
When the user submits, your Controller will be able to interrogate the View for a list of the selected checkboxes (and their IDs), and then it's a case of going through the Model and creating the necessary rows in the database.
Related
I'm new to Firestore and trying to develop a data model for my app.
Background: I have a dating type of app with 3 primary ways that users will communicate with one another. Liking, dismissing, and commenting user profiles. Users likes & comments are private. In other words, only I can see who's liked or commented my profile (it's not like Social media where everyone can see who's liked a post). I'll need to be able to query users to know who's dismissed their profile so I won't show it to those users again. I'll also need to know who's liked/commented a users profile so I can query which users have liked/commented each other (they've matched)
Users can like many profiles and vice versa
Users can dismiss/skip many profiles and vice versa
Users can comment on many profiles and vice versa
I believe this means I'll need a root collection for likedUsers, dismissedUsers, and commentedUsers
Problem:
For dismissed users, I thought I'd store every single user as a Document of the dismissedUsers root collection and store every user they've skipped as a field/value pair like so...
dismissedUsers/User/user1, user2, user3, etc
The above would create the many-many relationship I want where dismissedUsers can have many users and users can have many dismissedUsers. However, I don't believe it would be scalable as the User Document would grow too large.
Question: How do I create this many-many relationship where dismissedUsers can have many users and users can have many dismissedUsers so that it's scalable and least expensive? And query it?
First of all I would ask myself why I am using Firestore, being a document database, instead of choosing a relational database. I personally love Firestore and highly recommend it. We pick a document database because it is faster and easier to use in many ways. In other ways it is a drawback because you have very limited query power. It sounds to me like your brain is working towards a relational database implementation.
Here is one solution
First of all I would try to avoid storing user data in more than one location to avoid anomalies (of course right). I would have one collection of users where I stored all user data with a unique id (best to use the one that Firestore assigns so I don't have collisions). Within each users document I would link a subcollection for dismissed, liked, been dismissed by someone else, liked by someone else etc.. I would keep a record of all users (just the user id) that they have dismissed, liked, been dismissed by, been liked by etc.. This way I can look up all data for who that user has liked or disliked and display whatever I want to that user accordingly.
Drawbacks
You will have to write twice per like, dismiss etc. Use a batch write to update both the liked and likee data at the same time.
You don't need a collection of users who liked, dismissed, or commented on another users profile. You can have one user collection which stores all users. Inside each user document you can have three array of the user ids of the users that liked, commented, and/or dismissed a user profile. Just make sure that the document ID of the documents inside the users collection matches the user id of the corresponding user.
I have a view controller with a tableview that shows all posts by all users, however I am looking to have another view controller with another tableview that displays only the current users posts. This tableview will allow the user to control/delete their posts.
I have the tableview with all the posts however I am unable to get only the current users posts.
How am I able to do this?
My approach to this would be to create a new node, used for users personal posts, using their id as key, it will store all posts they have created along with only the id of that post. From there you can determine if the post belongs to the user.
I would also change your security settings to ensure data isn't edited.
You should create a fan-out approach when storing your data.
Create a new sub-tree that will store users posts id
-userPosts
-userId
-[postId]
This allows you to have a seperate list for each user. Instead of keeping track of the post object, you simply keep a list of each ID.
To get all posts for a specific user you simply just search this new list of objects. Find the current users list, then for each postId in the list, make another request to get the corresponding post for that id.
You now have a list of all posts by a specific user :)
I am building out an iOS app that requires getting lists of users at different parts of the app(finding users nearby, find users that have similar interest etc) I'm displaying the list of users in collection views/table views.
I have a user structure that contains all of the user data(name, photo, list of interest, location, preferences..etc)
My question is, when I'm getting the list of users from the database, is it more cost effective to use the query function or to use the observe functions? In the list I only need to display the users photo and username. If the user wants to find out more then clicking on the cell will get more data from the larger user data table.
My options
using a query to get the users that meet the criteria for that list(say all users nearby). Then when the user clicks on the cell that interests them, get a snapshot from the database for that specific users.
My thought process is its less costly than pulling back the whole snapshot using the observe functions.
using the observe functions, getting all users snapshot data and only displaying the photo and username. If the user selects a cell send the data to the detail view.
creating a special display structure that contains only items necessary for the collection view/ table view and if the user clicks on a cell call the database again getting all of that users data.
If anyone has a point of view they could share that would be great!
Thanks
Observing in Firebase needed for making instant update, like in chats, when new message appear you need to update message list. So here, for getting list of users that fit your request, better to use queries
I am creating a photo sharing app for the iPhone using Parse.com and so far everything has been pretty easy and I just finished writing the code for uploading photos to the Parse server.
So far, I have been using the default "_User" class. Here are some of the key types of data that are being stored for each user: objectId, username, email, and an array object called "friends" that contains the usernames of other users in the database that the user has added to their friends list.
Now, I need to setup the actual sharing functionality between users. I have been going through the Parse documentation and I need to decide whether to use a one-to-many, many-to-many, or one-to-one relationship. Depending on which one I end up choosing, I then will need to decide between using pointers, arrays, parse relations, or join tables.
I am going to quickly explain the "sharing" functionality that I am trying to achieve:
For my photo app, user1 starts the "relationship" by taking a photo and choosing to send it to a friend on their friends list named user2 .
The photo is then uploaded to Parse and sent to user2.
user2 receives the photo from user1.
user2 opens the photo and it is their job to "finish" the "relationship" by using the app's editing tools and drawing something random on the original photo. Example: user2 draws a heart next to user1's face in the photo.
When user2 is finished, the final photo is saved to their profile and also sent back to the original sender, user1, and the "relationship" is now finished and completed/closed.
After reading through the docs and doing my own research, I have come to the conclusion that I need to use a Many-To-Many relationship using Join Tables so that I can include metadata.
However, I am new to objective-c and programming in general and it would be lazy of me if I did not ask for input and advice before getting started when it is possible that I have chosen the wrong solution or an unnecessary solution.
Your question is more about your DB management than anything to do with Obj-C.
Think about using a new class in your DB called SharedImage which hosts the image(s), a link to the originator and the recipient (1 to 1, so could us a pointer or a relationship) and any other data you need.
Now you can create these objects are you require and you can fetch them based on queries using the current user.
Also, for your existing friends array which you said holds the usernames of the friends - it would probably be better to store the objectIds of the friends instead of the usernames (because the username can usually be changed, but the objectId is static).
I'm currently working on a rails app where I have two model classes, Account and User. I want to allow users to link their User with account information from other places.
What I want the user to be able to do is, under my edit user form, I have a list displaying the names of all linked accounts, and a text input for them to add more.
All I want them to do is fill in one field (account name) and hit a button, and the back end will hit a restful API for that account name, pull back relevant info, and populate an Account model object, linking to the current user.
For example, from the user page I would like the user to be able to type in their twitter handle, and in the back end I'd look up that twitter account id and associate it with that User in my database.
Where is the right place to have a hook so that I can take an input (twitter handle), fire off a helper method that populates a Account object, and then link that to my current user?
I'm not sure I understood exactly what you were asking but I'll try my best : If your account 'belongs_to' your User model, it would seem logical to use the create or update method (depending on your standard case) of your Accounts controller, to retrieve a JSON with the accounts datas, and that the client parse this answer (with some JS).