join method
Implementation
Future<void> join(Doc<PlayRoomEntity> playRoomDoc) async {
final user = await _auth.currentUser;
final userDocRef = _store.docRef<UserEntity>(user.uid);
// 既に参加済みの場合
if (playRoomDoc.entity.humans.contains(userDocRef.ref)) {
value.haveJoinedPlayRoom = playRoomDoc;
return notifyListeners();
}
final roomDocRef = _store.collectionRef<PlayRoomEntity>().docRef(playRoomDoc.id);
final batch = _store.firestore.batch();
await userDocRef.updateData(<String, dynamic>{
UserEntityField.joinPlayRoom.name: playRoomDoc.ref,
TimestampField.updatedAt: FieldValue.serverTimestamp(),
}, batch: batch);
await roomDocRef.updateData(<String, dynamic>{
PlayRoomEntityField.humans.name: FieldValue.arrayUnion(<DocumentReference>[userDocRef.ref]),
TimestampField.updatedAt: FieldValue.serverTimestamp(),
}, batch: batch);
await batch.commit();
value.haveJoinedPlayRoom = playRoomDoc;
notifyListeners();
}