Skip to content

Commit 6cb86a0

Browse files
Update stream service to expose v1_admin_user_uid_streams_list_post
1 parent 00ff40b commit 6cb86a0

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

symphony/bdk/core/service/stream/stream_service.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,39 @@ async def list_streams_admin_one_page(skip, limit):
350350

351351
return offset_based_pagination(list_streams_admin_one_page, chunk_size, max_number)
352352

353+
@retry
354+
async def list_user_streams_admin(self, uid: int, stream_filter: StreamFilter = None, skip: int = 0,
355+
limit: int = 50) -> StreamList:
356+
"""Retrieve a list of all streams of which a user is a member.
357+
Wraps the `User Streams <https://developers.symphony.com/restapi/v20.16/reference#user-streams>`_ endpoint.
358+
359+
:param uid: the ID of the user.
360+
:param stream_filter: the filtering criteria for the streams.
361+
:param skip: the number of streams to skip.
362+
:param limit: the maximum number of streams to retrieve. Must be less or equal than 1000.
363+
:return: the list of streams for the specified user.
364+
"""
365+
return await self._streams_api.v1_admin_user_uid_streams_list_post(
366+
uid=uid, filter=stream_filter, skip=skip, limit=limit, session_token=await self._auth_session.session_token
367+
)
368+
369+
async def list_all_user_streams_admin(self, uid: int, stream_filter: StreamFilter = None, chunk_size: int = 50,
370+
max_number: int = None) -> AsyncGenerator[StreamAttributes, None]:
371+
"""Retrieves all streams of which a user is a member, handling pagination automatically.
372+
Wraps the `User Streams <https://developers.symphony.com/restapi/v20.16/reference#user-streams>`_ endpoint.
373+
374+
:param uid: the ID of the user.
375+
:param stream_filter: the filtering criteria for the streams.
376+
:param chunk_size: the maximum number of streams to retrieve in one underlying HTTP call.
377+
:param max_number: the total maximum number of streams to retrieve.
378+
:return: an asynchronous generator of the streams.
379+
"""
380+
async def list_streams_one_page(skip, limit):
381+
result = await self.list_user_streams_admin(uid, stream_filter, skip, limit)
382+
return result.streams.value if result.streams else None
383+
384+
return offset_based_pagination(list_streams_one_page, chunk_size, max_number)
385+
353386
@retry
354387
async def list_stream_members(self, stream_id: str, skip: int = 0, limit: int = 100) -> V2MembershipList:
355388
"""List the current members of an existing stream. The stream can be of type IM, MIM, or ROOM.

0 commit comments

Comments
 (0)