Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom event endpoint #103

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stream_chat/async_chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ async def get_export_channel_status(self, task_id: str) -> StreamResponse:
async def get_task(self, task_id: str) -> StreamResponse:
return await self.get(f"tasks/{task_id}")

async def send_user_custom_event(self, user_id: str, event: Dict) -> StreamResponse:
return await self.post(f"users/{user_id}/event", data={"event": event})

async def close(self) -> None:
await self.session.close()

Expand Down
9 changes: 9 additions & 0 deletions stream_chat/base/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,15 @@ def get_task(
"""
pass

@abc.abstractmethod
def send_user_custom_event(
self, user_id: str, event: Dict
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Allows you to send custom events to a connected user.
"""
pass

#####################
# Private methods #
#####################
Expand Down
3 changes: 3 additions & 0 deletions stream_chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,6 @@ def get_export_channel_status(self, task_id: str) -> StreamResponse:

def get_task(self, task_id: str) -> StreamResponse:
return self.get(f"tasks/{task_id}")

def send_user_custom_event(self, user_id: str, event: Dict) -> StreamResponse:
return self.post(f"users/{user_id}/event", data={"event": event})
7 changes: 7 additions & 0 deletions stream_chat/tests/async_chat/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,13 @@ async def test_delete_channels(self, client: StreamChatAsync, channel: Channel):

pytest.fail("task did not succeed")

async def test_send_user_custom_event(
self, client: StreamChatAsync, random_user: Dict
):
await client.send_user_custom_event(
random_user["id"], {"type": "friendship_request", "text": "testtext"}
)

@pytest.mark.asyncio
async def test_stream_response(self, client: StreamChatAsync):
resp = await client.get_app_settings()
Expand Down
5 changes: 5 additions & 0 deletions stream_chat/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,11 @@ def test_delete_channels(self, client: StreamChat, channel: Channel):

pytest.fail("task did not succeed")

def test_send_user_custom_event(self, client: StreamChat, random_user: Dict):
client.send_user_custom_event(
random_user["id"], {"type": "friendship_request", "text": "testtext"}
)

def test_stream_response_contains_metadata(self, client: StreamChat):
resp = client.get_app_settings()

Expand Down