|
2 | 2 | //! Support for Slack Files API methods |
3 | 3 | //! |
4 | 4 |
|
5 | | -use rsb_derive::Builder; |
6 | | -use rvstruct::ValueStruct; |
7 | | -use serde::{Deserialize, Serialize, Serializer}; |
8 | | -use serde_with::skip_serializing_none; |
9 | | - |
10 | 5 | use crate::api::{ |
11 | 6 | SlackApiUsersConversationsRequest, SlackApiUsersConversationsResponse, |
12 | 7 | SlackApiUsersProfileSetRequest, SlackApiUsersProfileSetResponse, |
13 | 8 | }; |
14 | 9 | use crate::models::*; |
15 | 10 | use crate::multipart_form::FileMultipartData; |
16 | 11 | use crate::ratectl::*; |
17 | | -use crate::SlackClientSession; |
18 | 12 | use crate::{ClientResult, SlackClientHttpConnector}; |
| 13 | +use crate::{SlackApiScrollableRequest, SlackApiScrollableResponse, SlackClientSession}; |
| 14 | +use futures_util::future::BoxFuture; |
| 15 | +use futures_util::FutureExt; |
| 16 | +use rsb_derive::Builder; |
| 17 | +use rvstruct::ValueStruct; |
| 18 | +use serde::{Deserialize, Serialize, Serializer}; |
| 19 | +use serde_with::skip_serializing_none; |
| 20 | +use tokio_stream::StreamExt; |
19 | 21 |
|
20 | 22 | impl<'a, SCHC> SlackClientSession<'a, SCHC> |
21 | 23 | where |
@@ -223,6 +225,46 @@ pub struct SlackApiFilesListPaging { |
223 | 225 | pub pages: Option<u32>, |
224 | 226 | } |
225 | 227 |
|
| 228 | +impl<SCHC> SlackApiScrollableRequest<SCHC> for SlackApiFilesListRequest |
| 229 | +where |
| 230 | + SCHC: SlackClientHttpConnector + Send + Sync + Clone + 'static, |
| 231 | +{ |
| 232 | + type ResponseType = SlackApiFilesListResponse; |
| 233 | + type CursorType = u32; |
| 234 | + type ResponseItemType = SlackFile; |
| 235 | + |
| 236 | + fn with_new_cursor(&self, new_cursor: Option<&Self::CursorType>) -> Self { |
| 237 | + self.clone().opt_page(new_cursor.cloned()) |
| 238 | + } |
| 239 | + |
| 240 | + fn scroll<'a, 's>( |
| 241 | + &'a self, |
| 242 | + session: &'a SlackClientSession<'s, SCHC>, |
| 243 | + ) -> BoxFuture<'a, ClientResult<Self::ResponseType>> { |
| 244 | + async move { session.files_list(self).await }.boxed() |
| 245 | + } |
| 246 | +} |
| 247 | + |
| 248 | +impl SlackApiScrollableResponse for SlackApiFilesListResponse { |
| 249 | + type CursorType = u32; |
| 250 | + type ResponseItemType = SlackFile; |
| 251 | + |
| 252 | + fn next_cursor(&self) -> Option<Self::CursorType> { |
| 253 | + self.paging |
| 254 | + .as_ref() |
| 255 | + .into_iter() |
| 256 | + .filter_map(|paging| match (paging.page, paging.pages) { |
| 257 | + (Some(page), Some(pages)) if page < pages => Some(page + 1), |
| 258 | + _ => None, |
| 259 | + }) |
| 260 | + .next() |
| 261 | + } |
| 262 | + |
| 263 | + fn scrollable_items<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Self::ResponseItemType> + 'a> { |
| 264 | + Box::new(self.files.iter()) |
| 265 | + } |
| 266 | +} |
| 267 | + |
226 | 268 | #[skip_serializing_none] |
227 | 269 | #[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Builder)] |
228 | 270 | pub struct SlackApiFilesUploadRequest { |
|
0 commit comments