How to add users to groups in Firebase? - android

A newbie Firebase/Android user here, and I am attempting to create an application where users can be added to a group in my Firebase database.
I have defined my User and Group objects as per this post -
Group of users in firebase
My user and group object looks as in the above post and I understand from the documents on Firebase that in order to add a user to a group I need to also add a group reference to a user object but I do not know how I would code this.
I am just unsure of how best to add a User to a Group with Android programatically ,how would I best achieve this?

i think if you familiar with lists you will use it very well as it is very basic one that you have object of group and object of user
and all you want is to access the user and add the group object
like this
user.getGroups().add(group)

Related

How to give data access in cloud firestore to another added users in android?

I wanna ask about the concept and logically ways to give another user the privilege to access other's users' data. What I want to do exactly is like this :
Basically, collection 1 contains several Users ID (UID) from authentication, then the user will have their own data collected in collection 2 which contain the data ID.
So, it's like giving access to another user to collaborate with the data like Google Docs Apps where we can add another user to edit our documents. I've been thinking of how to do this, but still, I got stuck.
My question is, how can I possibly do this? cause from what I've read, cloud firestore don't use such a foreign key like MySQL. Thank You
haven't tried something like this but i think this approch overcomes your problem.
modify your structure according to above image. userID collection will contain userIds which are allowed to edit their parent collection.and create firestore rules according to your use to check weather the userId is allowed to edit the Collection or not.
in your case when 'user 2' will have reference to 'collection 2', he/she will try to change data. firebase rule will check if auth.userId is inside the 'collection2.UserIDs' or not and will allow according that.

create private chat & group chat on different condition using firebase firestore in android

I have to implement chat functionality in my existing app using firebase firestore but there are 2 cases:
create private chat- in this case i have the recyclerview that contain user list while i select particular user then start communication in current user & selected user.
group chat- in this case i have food item list & each food item has user list who send request to that food item now i want to allow current user to create group chat by adding those user who send request to that food item.
how to achieve those thing.
There are many ways on how to achieve the Chat application. It will depend on how you want or prefer to develop your database and application in general.
Considering that, I would recommend you take a look at the below articles, for more information and steps on how to achieve that.
These first 3 are more related to your private chat application part, that I think should help you.
[Make-A] Simple Chat Application using Cloud Firestore Part 1 – Introduction
Firestore Megachat - Let's Build a Chat App
How to structure Firestore database in chat app?
This last one, I would recommend you take a look, as it provides more information regarding creating a Group Chat application with Firestore.
Group Chat with Firestore
Let me know if the information helped you!

How to Retrieve specific uid key when clicking on recyclerView an object

I have built an android application using firebase database. I have a recyclerView in which i saw some objects. When i click on one of the options i want to get the unique id so later i can change some values.
If it where a user i could get the id by FirebaseAuth.getInstance().getCurrentUser().getUid()
I want something like that but i cannot find it.
For example. I have those two Notifications Objects in the database.
Here when i click on one i need to get the key. I have not added the objects on a list so i can use list.get(position).getId(). Is it possible to get it from getAdapterPosition()?

How to match elements from one set to elements in another set using Firebase?

I recently started to learn Android and I came across a problem. I want to create a code for Firebase (the database I am using to store values) such that the contents from one set are matched to elements in another set.
The scenario is as follows: there is a student who wants to learn or is interested in learning a new skill (C/C++, drawing, music, etc.), if he were to update them in their profile, he should get suggestions as names of other users registered in the application who have already listed their skill set.
It is much like how Facebook suggests common friends, but here, the basis for suggestion is what skills the user has and what he wants to learn.
I worked on the same thing for one of my apps. I'll write about what I did to achieve that
First of all, you need to design your Realtime Database structure in a way to achieve that.
Example of a Individual User node in your database at firebase could be like
User
- Personal Details
- First name
- last name
- Dob
- Interests (values like "music,movies,sports") //Separated by a comma
- ...
Now lets say User A likes "music" and that you need to suggest him other users who likes music too, In this case what you can do is retrieve all the users who have interests "music" in their profile.
reference.addChildEventListener()
In here,inside the onChildAdded() you can compare to see if the Interest of a particular user has music in it. (if it does, add that user to your arraylist for your recyclerview to display it.)
Hope it helps!

ParseUser role on individual object - Parse.com

I have 2 classes in Parse, a User class and a Group class. The idea is simple. A logged-in user will be able to create a new Group object, and an array relationship will form between that user and that newly created group. That user can now invite other users to that group via a push notification invitation. A second user will also form a relationship with that group object once he accepts the invite.
So far this is simple and working fine. However, I want the creator of that group object to have full control of the group he created.
1- Creator can invite other users, members cannot.
2- Creator can kick a member out
3- Creator can destroy/delete the group object.
I'm not sure what is the correct way of implementing this using ParseRole. Any suggestions?
You can enforce requirement 1 and requirement 3 with row-level ACL permitting write/delete to the Group table only by the creating user. (to enforce this for invitations, check the group's ACL in the invite logic to see if the inviting user equals the creating user).
Requirement 3 is trickier and, I think, not achievable given how you describe the data. A user who accepts an invitation can add to their own array of groups, but no other user (including a group creator) will be able update that user's row.
Your alternatives are either (a) represent group membership with an array on the group object, or (b) create a another object, one for each user, where the member-of-groups array is kept. Think of this object as a user's persona, and keep a pointer relationship between it and its user.
You can add column 'author' to group class with a User pointer.
When you receive a request, you check if the request author equal to author group.
You must add the user token in your request and compare Parse.User.current() with Group author.

Categories

Resources