Skip to content

Commit e33ae40

Browse files
feat: enable creation of channels with query options (#137)
* feat: enable creation of channels with query options * feat: allow options for create channel * fix: linting issue * feat: added test
1 parent e54a9e3 commit e33ae40

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

stream_chat/async_chat/channel.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ async def delete_reaction(
3535
params={"user_id": user_id},
3636
)
3737

38-
async def create(self, user_id: str) -> StreamResponse:
38+
async def create(self, user_id: str, **options: Any) -> StreamResponse:
3939
self.custom_data["created_by"] = {"id": user_id}
40-
return await self.query(watch=False, state=False, presence=False)
40+
options["watch"] = False
41+
options["state"] = False
42+
options["presence"] = False
43+
return await self.query(**options)
4144

4245
async def query(self, **options: Any) -> StreamResponse:
4346
payload = {"state": True, "data": self.custom_data, **options}

stream_chat/base/channel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def delete_reaction(
8686
pass
8787

8888
@abc.abstractmethod
89-
def create(self, user_id: str) -> Union[StreamResponse, Awaitable[StreamResponse]]:
89+
def create(
90+
self, user_id: str, **options: Any
91+
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
9092
"""
9193
Create the channel
9294

stream_chat/channel.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ def delete_reaction(
3030
params={"user_id": user_id},
3131
)
3232

33-
def create(self, user_id: str) -> StreamResponse:
33+
def create(self, user_id: str, **options: Any) -> StreamResponse:
3434
self.custom_data["created_by"] = {"id": user_id}
35-
return self.query(watch=False, state=False, presence=False)
35+
options["watch"] = False
36+
options["state"] = False
37+
options["presence"] = False
38+
return self.query(**options)
3639

3740
def get_messages(self, message_ids: List[str]) -> StreamResponse:
3841
return self.client.get(

stream_chat/tests/async_chat/test_channel.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ async def test_create_without_id(
3535
await channel.create(random_users[0]["id"])
3636
assert channel.id is not None
3737

38+
async def test_create_with_options(
39+
self, client: StreamChatAsync, random_users: List[Dict]
40+
):
41+
channel = client.channel(
42+
"messaging", data={"members": [u["id"] for u in random_users]}
43+
)
44+
assert channel.id is None
45+
46+
await channel.create(random_users[0]["id"], hide_for_creator=True)
47+
assert channel.id is not None
48+
3849
async def test_send_message_with_options(self, channel: Channel, random_user: Dict):
3950
response = await channel.send_message(
4051
{"text": "hi"}, random_user["id"], skip_push=True

stream_chat/tests/test_channel.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def test_create_without_id(self, client: StreamChat, random_users: List[Dict]):
3131
channel.create(random_users[0]["id"])
3232
assert channel.id is not None
3333

34+
def test_create_with_options(self, client: StreamChat, random_users: List[Dict]):
35+
channel = client.channel(
36+
"messaging", data={"members": [u["id"] for u in random_users]}
37+
)
38+
assert channel.id is None
39+
40+
channel.create(random_users[0]["id"], hide_for_creator=True)
41+
assert channel.id is not None
42+
3443
def test_send_message_with_options(self, channel: Channel, random_user: Dict):
3544
response = channel.send_message(
3645
{"text": "hi"}, random_user["id"], skip_push=True

0 commit comments

Comments
 (0)