@@ -14,7 +14,6 @@ import com.whyranoid.data.model.UserResponse
14
14
import com.whyranoid.data.model.toGroupInfo
15
15
import com.whyranoid.data.model.toUser
16
16
import com.whyranoid.domain.model.GroupInfo
17
- import com.whyranoid.domain.model.MoGakRunException
18
17
import com.whyranoid.domain.model.Rule
19
18
import com.whyranoid.domain.model.toRule
20
19
import kotlinx.coroutines.channels.awaitClose
@@ -127,44 +126,32 @@ class GroupDataSource @Inject constructor(
127
126
}
128
127
}
129
128
130
- fun getGroupInfoFlow (uid : String , groupId : String ): Flow <GroupInfo > {
131
- return callbackFlow {
132
- val groupInfoResponse = getGroupInfoResponse(groupId)
133
- val userResponse = getUserInfoResponse(uid)
134
- val groupInfo = groupInfoResponse.toGroupInfo(
135
- leader = userResponse.toUser(),
136
- rules = groupInfoResponse.rules.map { it.toRule() }
137
- )
138
- trySend(groupInfo)
139
- awaitClose()
140
- }
141
- }
129
+ fun getGroupInfoFlow (uid : String , groupId : String ): Flow <GroupInfo > = callbackFlow {
130
+ db.collection(GROUPS_COLLECTION )
131
+ .document(groupId)
132
+ .addSnapshotListener { documentSnapshot, _ ->
133
+ val groupInfoResponse = documentSnapshot?.toObject(GroupInfoResponse ::class .java)
142
134
143
- private suspend fun getGroupInfoResponse (groupId : String ): GroupInfoResponse {
144
- return suspendCancellableCoroutine { continuation ->
145
- db.collection(GROUPS_COLLECTION )
146
- .document(groupId)
147
- .addSnapshotListener { documentSnapshot, _ ->
148
- continuation.resume(
149
- documentSnapshot?.toObject(GroupInfoResponse ::class .java)
150
- ? : throw MoGakRunException .FileNotFoundedException
151
-
152
- )
153
- }
154
- }
155
- }
135
+ groupInfoResponse?.let {
136
+ db.collection(USERS_COLLECTION )
137
+ .document(uid)
138
+ .addSnapshotListener { documentSnapshot, _ ->
139
+ val userResponse = documentSnapshot?.toObject(UserResponse ::class .java)
156
140
157
- private suspend fun getUserInfoResponse (uid : String ): UserResponse {
158
- return suspendCancellableCoroutine { continuation ->
159
- db.collection(USERS_COLLECTION )
160
- .document(uid)
161
- .addSnapshotListener { documentSnapshot, _ ->
162
- continuation.resume(
163
- documentSnapshot?.toObject(UserResponse ::class .java)
164
- ? : throw MoGakRunException .FileNotFoundedException
165
- )
141
+ userResponse?.let {
142
+ trySend(
143
+ groupInfoResponse.toGroupInfo(
144
+ leader = userResponse.toUser(),
145
+ rules = groupInfoResponse.rules.map {
146
+ it.toRule()
147
+ }
148
+ )
149
+ )
150
+ }
151
+ }
166
152
}
167
- }
153
+ }
154
+ awaitClose()
168
155
}
169
156
170
157
suspend fun isDuplicatedGroupName (groupName : String ): Boolean {
0 commit comments