Skip to content
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
34 changes: 0 additions & 34 deletions stream_chat/async_chat/channel_batch_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,37 +206,3 @@ async def update_data(
"data": data,
}
return await self.client.update_channels_batch(options)

async def add_filter_tags(
self, filter: ChannelsBatchFilters, tags: List[str]
) -> StreamResponse:
"""
Adds filter tags to channels matching the filter.

:param filter: The filter to match channels.
:param tags: List of filter tags to add.
:return: StreamResponse containing task_id.
"""
options: ChannelsBatchOptions = {
"operation": "addFilterTags",
"filter": filter,
"filter_tags_update": tags,
}
return await self.client.update_channels_batch(options)

async def remove_filter_tags(
self, filter: ChannelsBatchFilters, tags: List[str]
) -> StreamResponse:
"""
Removes filter tags from channels matching the filter.

:param filter: The filter to match channels.
:param tags: List of filter tags to remove.
:return: StreamResponse containing task_id.
"""
options: ChannelsBatchOptions = {
"operation": "removeFilterTags",
"filter": filter,
"filter_tags_update": tags,
}
return await self.client.update_channels_batch(options)
34 changes: 0 additions & 34 deletions stream_chat/channel_batch_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,37 +206,3 @@ def update_data(
"data": data,
}
return self.client.update_channels_batch(options)

def add_filter_tags(
self, filter: ChannelsBatchFilters, tags: List[str]
) -> StreamResponse:
"""
Adds filter tags to channels matching the filter.

:param filter: The filter to match channels.
:param tags: List of filter tags to add.
:return: StreamResponse containing task_id.
"""
options: ChannelsBatchOptions = {
"operation": "addFilterTags",
"filter": filter,
"filter_tags_update": tags,
}
return self.client.update_channels_batch(options)

def remove_filter_tags(
self, filter: ChannelsBatchFilters, tags: List[str]
) -> StreamResponse:
"""
Removes filter tags from channels matching the filter.

:param filter: The filter to match channels.
:param tags: List of filter tags to remove.
:return: StreamResponse containing task_id.
"""
options: ChannelsBatchOptions = {
"operation": "removeFilterTags",
"filter": filter,
"filter_tags_update": tags,
}
return self.client.update_channels_batch(options)
28 changes: 27 additions & 1 deletion stream_chat/tests/async_chat/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,35 @@ async def channel(client: StreamChatAsync, random_user: Dict):

@pytest.fixture(scope="function")
async def command(client: StreamChatAsync):
try:
commands = await client.list_commands()
for cmd in commands.get("commands", []):
if cmd.get("name") not in (
"giphy",
"imgur",
"flag",
"ban",
"unban",
"mute",
"unmute",
):
try:
await client.delete_command(cmd["name"])
except Exception:
pass
except Exception:
pass

response = await client.create_command(
dict(name=str(uuid.uuid4()), description="My command")
)

yield response["command"]

await client.delete_command(response["command"]["name"])
try:
await client.delete_command(response["command"]["name"])
except Exception:
pass


@pytest.fixture(scope="function")
Expand All @@ -121,6 +143,10 @@ async def fellowship_of_the_ring(client: StreamChatAsync):
},
{"id": "peregrin-took", "name": "Peregrin Took", "race": "Hobbit", "age": 28},
]
try:
await client.restore_users([m["id"] for m in members])
except Exception:
pass
await client.upsert_users(members)
channel = client.channel(
"team", "fellowship-of-the-ring", {"members": [m["id"] for m in members]}
Expand Down
9 changes: 5 additions & 4 deletions stream_chat/tests/async_chat/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import json
import os
import sys
Expand Down Expand Up @@ -173,14 +174,14 @@ async def test_delete_users(self, client: StreamChatAsync, random_user: Dict):
)
assert "task_id" in response

for _ in range(20):
for _ in range(60):
response = await client.get_task(response["task_id"])
if response["status"] == "completed" and response["result"][
random_user["id"]
] == {"status": "ok"}:
return

time.sleep(1)
await asyncio.sleep(1)

pytest.fail("task did not succeed")

Expand Down Expand Up @@ -810,14 +811,14 @@ async def test_delete_channels(self, client: StreamChatAsync, channel: Channel):
response = await client.delete_channels([channel.cid])
assert "task_id" in response

for _ in range(20):
for _ in range(60):
response = await client.get_task(response["task_id"])
if response["status"] == "completed" and response["result"][
channel.cid
] == {"status": "ok"}:
return

time.sleep(1)
await asyncio.sleep(1)

pytest.fail("task did not succeed")

Expand Down
28 changes: 27 additions & 1 deletion stream_chat/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,35 @@ def channel(client: StreamChat, random_user: Dict):

@pytest.fixture(scope="function")
def command(client: StreamChat):
try:
commands = client.list_commands()
for cmd in commands.get("commands", []):
if cmd.get("name") not in (
"giphy",
"imgur",
"flag",
"ban",
"unban",
"mute",
"unmute",
):
try:
client.delete_command(cmd["name"])
except Exception:
pass
except Exception:
pass

response = client.create_command(
dict(name=str(uuid.uuid4()), description="My command")
)

yield response["command"]

client.delete_command(response["command"]["name"])
try:
client.delete_command(response["command"]["name"])
except Exception:
pass


@pytest.fixture(scope="module")
Expand All @@ -111,6 +133,10 @@ def fellowship_of_the_ring(client: StreamChat):
},
{"id": "peregrin-took", "name": "Peregrin Took", "race": "Hobbit", "age": 28},
]
try:
client.restore_users([m["id"] for m in members])
except Exception:
pass
client.upsert_users(members)
channel = client.channel(
"team", "fellowship-of-the-ring", {"members": [m["id"] for m in members]}
Expand Down
4 changes: 2 additions & 2 deletions stream_chat/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_delete_users(self, client: StreamChat, random_user: Dict):
)
assert "task_id" in response

for _ in range(20):
for _ in range(60):
response = client.get_task(response["task_id"])
if response["status"] == "completed" and response["result"][
random_user["id"]
Expand Down Expand Up @@ -818,7 +818,7 @@ def test_delete_channels(self, client: StreamChat, channel: Channel):
response = client.delete_channels([channel.cid])
assert "task_id" in response

for _ in range(20):
for _ in range(60):
response = client.get_task(response["task_id"])
if response["status"] == "completed" and response["result"][
channel.cid
Expand Down
6 changes: 0 additions & 6 deletions stream_chat/types/channel_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"archive",
"unarchive",
"updateData",
"addFilterTags",
"removeFilterTags",
]


Expand Down Expand Up @@ -66,12 +64,10 @@ class ChannelsBatchFilters(TypedDict, total=False):
Parameters:
cids: Filter by channel CIDs (can be a dict with operators like $in).
types: Filter by channel types (can be a dict with operators like $in).
filter_tags: Filter by filter tags (can be a dict with operators like $in).
"""

cids: Optional[Any]
types: Optional[Any]
filter_tags: Optional[Any]


class ChannelsBatchOptions(TypedDict, total=False):
Expand All @@ -83,11 +79,9 @@ class ChannelsBatchOptions(TypedDict, total=False):
filter: The filter to match channels (required).
members: List of members for member-related operations (optional).
data: Channel data updates for updateData operation (optional).
filter_tags_update: List of filter tags for filter tag operations (optional).
"""

operation: ChannelBatchOperation
filter: ChannelsBatchFilters
members: Optional[List[ChannelBatchMemberRequest]]
data: Optional[ChannelDataUpdate]
filter_tags_update: Optional[List[str]]