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: enable creation of channels with query options #137

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions stream_chat/async_chat/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ async def delete_reaction(
params={"user_id": user_id},
)

async def create(self, user_id: str) -> StreamResponse:
totalimmersion marked this conversation as resolved.
Show resolved Hide resolved
async def create(self, user_id: str, **options: Any) -> StreamResponse:
self.custom_data["created_by"] = {"id": user_id}
return await self.query(watch=False, state=False, presence=False)
options["watch"] = False
options["state"] = False
options["presence"] = False
return await self.query(**options)

async def query(self, **options: Any) -> StreamResponse:
payload = {"state": True, "data": self.custom_data, **options}
Expand Down
2 changes: 1 addition & 1 deletion stream_chat/base/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def delete_reaction(
pass

@abc.abstractmethod
def create(self, user_id: str) -> Union[StreamResponse, Awaitable[StreamResponse]]:
def create(self, user_id: str, **options: Any) -> Union[StreamResponse, Awaitable[StreamResponse]]:
totalimmersion marked this conversation as resolved.
Show resolved Hide resolved
"""
Create the channel

Expand Down
7 changes: 5 additions & 2 deletions stream_chat/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ def delete_reaction(
params={"user_id": user_id},
)

def create(self, user_id: str) -> StreamResponse:
def create(self, user_id: str, **options: Any) -> StreamResponse:
self.custom_data["created_by"] = {"id": user_id}
return self.query(watch=False, state=False, presence=False)
options["watch"] = False
options["state"] = False
options["presence"] = False
return self.query(**options)

def get_messages(self, message_ids: List[str]) -> StreamResponse:
return self.client.get(
Expand Down
9 changes: 9 additions & 0 deletions stream_chat/tests/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ def test_create_without_id(self, client: StreamChat, random_users: List[Dict]):
channel.create(random_users[0]["id"])
assert channel.id is not None

def test_create_with_options(self, client: StreamChat, random_users: List[Dict]):
channel = client.channel(
"messaging", data={"members": [u["id"] for u in random_users]}
)
assert channel.id is None

channel.create(random_users[0]["id"], hide_for_creator=True)
assert channel.id is not None

def test_send_message_with_options(self, channel: Channel, random_user: Dict):
response = channel.send_message(
{"text": "hi"}, random_user["id"], skip_push=True
Expand Down