Я хотел бы получить сообщения от следующих пользователей по их идентификаторам. Я просмотрел много статей, но пока не нашел решения. Может быть, я не смотрю в нужном месте.
Структура базы данных:
Firestore-root
|
--- users (collection)
| |
| --- uid (documents)
| |
| --- name: "User Name"
| |
| --- email: "email@email.com"
|
--- following (collection)
| |
| --- uid (document)
| |
| --- userFollowing (collection)
| |
| --- uid (documents)
| |
| --- uid (documents)
|
--- posts (collection)
|
--- uid (documents)
|
--- userPosts (collection)
|
--- postId (documents)
| |
| --- title: "Post Title"
| |
| --- date: September 03, 2018 at 6:16:58 PM UTC+3
|
--- postId (documents)
|
--- title: "Post Title"
|
--- date: September 03, 2018 at 6:16:58 PM UTC+3
Функция для получения сообщений:
static func subscribe(userID: String) -> AppThunkAction {
AppThunkAction { dispatch, _ in
let listener = Snapshot<Model.Photo>.listen(.photos(userID: userID), queryBuilderBlock: {
$0.order(by: .updateTime, descending: true).limit(to: 30)
}) { result in
switch result {
case let .success(photos):
dispatch(PhotosAction.updatePhotos(photos: photos))
case let .failure(error):
print(error)
// error handling
dispatch(PhotosAction.updatePhotos(photos: []))
}
}
dispatch(PhotosAction.updateListener(listener: listener))
}
}