Query inside for loop in Back4App(Parse) - android

I am building a social network application using parse which have follow/unfollow feature.
I have two tables: Users and Follow table.
Users table have user related data and Follow table have two fields: followerId and followedId.
I have a list of searched users. So, corresponding to each user i just want to get from query that whether i am following him/her or not. So, how to run query inside a loop?
Any help will be deeply appreciated.
Thanks.

For get follower
ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followedId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
public void done( List<ParseObject> MyList, ParseException e) {
if (e == null) {
// Get your follower user list
}else{
//error
}
For get following
ParseQuery query = new ParseQuery("FollowTable");
query.whereEqualTo("followerId", ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback() {
public void done( List<ParseObject> MyList, ParseException e) {
if (e == null) {
// Get your following user list
}else{
//error
}
Then after call user list query in ParseUser table and get all the user.
Thanks

Related

Get all users by Role Parse Android

Hi I have the next problem:
I have 10 users registered in Parse,a user can have the role of Admin or Player.
I'm trying to get all the users first but when I tried, the query only return one (The current user).
How can I get all the users? And then how can I filter by Role?
I have the next code:
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if (e==null){
Log.i("OK","no problem");
}else{
Log.i("NOT OK","problem");
}
}
});
Honestly, for something as simple as this, it would be better for you not to use relations and separate classes at all and instead to simply add a string field to the User Class called "role." So go to your User class on Parse, add a new column of type String called "role" and then query it as follows.
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.whereEqualTo("role", "admin");
userQuery.findInBackground(new FindCallback<ParseUser>() {
void done(List<ParseUser> results, ParseException e) {
// results has the list of users who are admins
}
});
You should check the ACL(readAccess) of each user. The user is without read access right. The other 9 user may not with public read, not specify the user's id, and the role is not equip access right.
As A.Vin's answer, if your user have more than 1 role, you can use array of strings.

Parse.com android app case insensitive searches

I'm using parse backend for one of my apps. There are three tables and I want to be able to search text entered by the user in search view in the table columns.
private void getDataFromParse() {
ParseQuery<ParseObject> query = ParseQuery.getQuery(Message.NAME);
query.addDescendingOrder(Message.CREATED_AT);
**query.whereStartsWith(Message.MESSAGE, mTag);**
query.setLimit(20);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
mMessages = (List<Message>) (Object) objects;
setAdapter();
}
}
});
}
The problem is that parse search is case sensitive. I enter the table content in parse from their websites UI. One suggestion to solve this problem is here
http://blog.parse.com/learn/engineering/implementing-scalable-search-on-a-nosql-backend/
How do solve my problem ?
You can convert the text enterd by the user to upper case and make sure that all the data in parse are upper case too

Check for username's existence | Parse.com

I'm searching for a good way of querying usernames towards my app's user-database. So that people can't signup with the same username as someone else.
I'm using a username, password and an email for recover of password. So I want to check for username's basically.
I've understood this can be achieved with ParseQuery?
I would like an example if anyone can provide?
You can use a ParseQuery to query all usernames in the database like this.
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
// objects is a list of all the User you have. Just get all the usernames,
//and check if there's already one equal to the one you want to insert.
} else {
//error handling
}
}
}

Can I update another ParseUser data different by the on logged in?

I want to update a field from table 'User' of a ParseUser different by the one logged in.
The code below is not working and I was wondering if there is some impediment that does not allow to update other's user info.
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.whereMatches("objectId", "4mdsJKKgDJ");
userQuery.getFirstInBackground(new GetCallback<ParseUser>() {
#Override
public void done(ParseUser parseUser, ParseException e) {
// I retreive the parseUser object correctly here
int score = parseUser.getInt("score"); // I have added this column in User table with a default value of 0
parseUser.put("score", score+1);
parseUser.saveInBackground(); // nothing happens. the value is not updated
}
});
Thanks.
I answer myself to my question: you cannot update another user info, different by the one logged in.
Using:
parseUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
System.out.println("ParseException: "+ e);
}
});
revealed the problem:
com.parse.ParseException: java.lang.IllegalArgumentException: Cannot save a ParseUser that is not authenticated.
So I will need to use another table to keep this info.

How to retrieve all rows of ParseObject in Android

On googlemap if my app user creates any maker I am storing that marker location details as a parse object,
now I want to retrieve all location details of all markers, how to do it. I already gone through parse.com tutorial links.
Try something like....
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("GreenMarkers");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> markers, ParseException e) {
if (e == null) {
// your logic here
} else {
// handle Parse Exception here
}
}
});
This should get all items from the "GreenMarkers" table.

Categories

Resources