A
A
ArthurHlushko2020-07-16 19:40:11
Mongoose
ArthurHlushko, 2020-07-16 19:40:11

How to make an invitation to friends?

How can I add to friends by invitation? For example, one person sends a friend request to another, and he must accept it in order to add him as a friend.
Now I implemented this by editing the data of another user, but it seems to be unsafe and you need to do it in such a way that only your user's data can be edited.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dasha Tsiklauri, 2020-07-16
@ArthurHlushko

you already have collections:
1) users
2) friends (user id key, user set id value, or better objects with the necessary information)
you make 2 additional collections:
1) incoming requests (key - id of the user who is knocked on friends, value - set users who are knocking, set to avoid duplicates)
2) outgoing applications (key - id of the user who knocks on someone's friend, value - set id to whom applications were sent)
- creation of an application : transaction (read from whom, read to whom, if everything is OK, then we add 2 documents to the collection)
- getting user status: we read 2 documents and see to whom they sent, and who sent applications to us
- confirmation of the application : transaction (read from whom, to whom, check that the user exists, if everything is ok, then delete 2 documents, edit 2 documents in the friends collection, 2 documents because you need to update from whom and to whom a friend is added)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question