Untitled
unknown
plain_text
2 years ago
1.1 kB
10
Indexable
@override
Future<void> markAsFriend({required RiceUser user}) async {
final currentUser = await getUser();
final currentUserId = currentUser.id;
// Apenas adicionar ao array FriendedBy do user. Analisar depois se é necessário modificar valor no Followings do currentUser
final userDocRef = db.collection('users').doc(user.id);
final currentUserRelationshipDocRef = db
.collection('users')
.doc(currentUserId)
.collection('relationships')
.doc(user.id);
final userRelationshipDocRef = db
.collection('users')
.doc(user.id)
.collection('relationships')
.doc(currentUserId);
// Adicionar ao array e merge
await userDocRef.set(
{
'friendedBy': FieldValue.arrayUnion([currentUserId]),
},
SetOptions(merge: true),
);
await currentUserRelationshipDocRef.set(
{
'yourFriend': true,
},
SetOptions(merge: true),
);
await userRelationshipDocRef.set(
{
'friendedYou': true,
},
SetOptions(merge: true),
);
}Editor is loading...
Leave a Comment