Create a 'like' feature for feeds using parse - android

I am trying to create a 'like' feature for my android app using parse as backend.I am currently giving the user the option to like or dislike a post in the details screen. But I want to give the user the option to like a post in the feeds section instead of opening the details screen like tumblr,facebook,twitter and many other apps.I know one way of doing it is running a inner query for every post to check if the post is liked or not.But suppose I am loading 25 posts for the feeds section then I will need to run inner queries for the 25 posts at the same time which will cause performance overhead.So is there any other optimized way for doing.How is the anypic and other parse apps doing this? Please help.

Add a property to your Post class called LikedBy which is an array of pointers to users.
Whenever a user likes the post, add them to the array. Then when you query for the posts, use includeKey on the array and you will know who and how many people have liked it :)

Related

How to show Firebase data only once?

I'm working on an android app which uses Firebase Realtime database.
This app is quite similar like a social media app with limited functionality.
The app will show the post contain text data to the users.
I'm stuck with the two problem in which I solved the first one with the help of Pagination but couldn't able to solve the second .
The problem is How can I identify if the post is already seen by the other users and then not show it again.
like other social media platforms
For example Quora, Quora will show different answer every time we open the app.
Do I need to remap my data get this functionality ?
My user object and post object will look something like this.
User{
Name;
Id;
Post;
}
Post {
dateCreated;
data;
userId;
}
My database tree structure will look something like this
ROOT
/ \
POST Users
I'm keeping the copy of the post in child node of ROOT that is POST and also in every users node to get the post posted by the user.
PS: sorry for the poor English.
If you want to
1- Show posts with NO views yet, you can filter posts where for example num_reads < 3. The num_reads will be increased everytime a user sees the post.
2- Show posts to use which the user himself didn't read yet. In this case it is better to create a collection user_post_read which will be many-to-many (ie. link user to post read). Get all posts where the is no entry for current user in user_post_read

Filter data in Firebase by follows

I have a simple Firebase database:
I would like to create an Android app where everybody can posts short texts. However, on the main screen I would like to show only those posts from other users who I followed. On the example, this means that if I logged in like Mrs. Nobody into the app, I can see only the first post created by Mr. Nobody.
Is that possible? (I tried to receive every posts in "posts" and after that I could show only posts what are relevant for me, but data traffic was really high in this case)
I have another idea, but I try to find a more efficient one. My idea is to receive every relations from "relations" where follow_uid is mine. After that, I iterate through all the elements and I download those posts where uid is equals with the uid from "relations"

How to model a timeline that automatically adds post from every follower on firebase database

I am building a social app, I have a database on firebase that is structured like this:
tJWRbfqUUbSQn5eI8ZS5vPG9znr1
bio:
coverPhotoUrl:
email:
firstname:
imgUrl:
lastname:
name:
phone:
posts
-KPN0b7QmNp8AjYy4yFl
-KPXmtvZdiQ--QjZ-j3m
-KPc7PpDkmFNU9JjlIJP
-KPc7PptOulQdrpsrGEp
-KPc7Pq6JC7bjt8-sRFU
-KPc7PqJ2651EIQWXIv6
the top level key is th user id, so i have that for every user, each user has posts too, inside the posts node, i have comments, pushed in the exact the same way as posts.
My question is that I am a bit curious about how i am going to model a Newsfeed, right now A Newsfeed to me is a list of posts from you and your everyone you are following in the exact order of the time they were posted while a timeline is just posts from the said user in that order too.
I have correctly done the timeline by just iterating over posts from the user
I have tried to do the Newsfeed part in two ways, which has bugs and I think is not very efficient
Since every user maintains a list of his followers in his own node, i made it such that anytime a user makes a post, he not only writes in his own 'posts node' but also in every other person following him's 'Newsfeed' node
Cons of this method
a. in the event of an unfollow, i am not able to remove user A's posts from User B's timeline
b. i am giving every user access to write in every other person's node, which as i have read, is not a very good practice.
Maintain the url of User A's post node in user B's Timeline node, which would solve the con B of method 1.
Cons of this method
a. I dont know how to implement it.
I dont know if there is any textbook way to do this(of course there has to be, there is only so much social network platforms out there), if there is i want to know, also if you could point me to how(not help me to) implement my method 2, i will very much appreciate it.
Also, i was following this similar question
which does not completely answer my question but looks like a very interesting approach
I think the solution you are looking for is referred to as client-side fan-out. This Firebase Blog post provides a great explanation and will point you in the right direction.
Client-side fan-out for data consistency
It looks like you need a new datastructure for keeping score who is following who. Use that information to build your newsfeed. That way there is no need for one user to write "into" another user. Every posting is only stored once for the user why created the post. If the follow and unfollow changes, you can simply recalculate on the fly which posts to include in a newsfeed

Android application getting information from a website

I want to write an app get the information from posts (mostly about new classes) on my university website then make some annoucement once there is new class.
I've google and see RSS mostly, but the page I want to get data does not use RSS. I read something about website using service so we can read XML in the app, but I don't know if the page using service or not. Last resort is using host (somee for example) and js to get text from the page, then the app could read data from the host.
That's all I have right now, but it's still unclear for me. Any suggestion about what to read, what should I use?? Much appreciation
I think the first thing you do should be to ask your uni if they provide any feed or webservice for these data that you could use.
If they don't, or don't answer at all, your last resort would be scraping. To do this, you can use an HTML parser, like jsoup, and then go through the HTML data, getting information as you need.
To see if there are been changes, you would just have to cache your current processed information, probably in a database, and compare the new one to the one currently saved.

Getting Git Hub Comments

Basically, I need to get JSON data from Git's web API. Great! Did that.
So, now I have a ListView in an android app, each list element is the title and first 140 characters from the json (jsonObject.getString("title"/"body")). When the user clicks on a list element, a dialog with all the comments in supposed to load.
So each issue (JSONObject) should have it's own comments, and indeed I can see the comments in the HTML version of the repo. However, how the heck do I download the comments in JSON form? So far, here's the "comments" element from inside the original issues JSON object:
"comments": 1,
"milestone": null,
"number": 18,
So, doing the stuff in android shouldn't be a big problem. I can detect the user's list item choice, and then get any string inside the JSON object (I figure ID is key in helping to find the comments for that issue). But, I can't figure out how I'm supposed to use GET like it says on this page under HTTP verbs (http://developer.github.com/v3/), I also can't sort out how to utilize the command as seen on this page under Get a Single comment (http://developer.github.com/v3/issues/comments/).
Lastly, I am using a PHP script on a webpage to access the original JSON. So I can envision a situation where I run another PHP script to get the comments JSON based on the list choice the user made (getID) and then work with it on the screen as need. But I can't do that without knowing how to get the comments!
Well, the url to get all the issues is something like this
https://api.github.com/repos/octocat/Hello-World/issues
as you can see you'll receive a list of issues.
After that just select the issue (let's say the number 26 that has 2 comments) and just add to the url "26/comments"
https://api.github.com/repos/octocat/Hello-World/issues/26/comments
and you'll have your comments!

Categories

Resources