Skip to content

Commit 85d7a38

Browse files
authored
feat: add filter tags to channels (#210)
* feat: add filter tags support for channels * feat: add filter tags support for channels * Lint
1 parent 21997ee commit 85d7a38

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

stream_chat/async_chat/channel.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,19 @@ async def get_draft(
272272
if parent_id:
273273
params["parent_id"] = parent_id
274274
return await self.client.get(f"{self.url}/draft", params=params)
275+
276+
async def add_filter_tags(
277+
self,
278+
tags: Iterable[str],
279+
message: Dict = None,
280+
) -> StreamResponse:
281+
payload = {"add_filter_tags": tags, "message": message}
282+
return await self.client.post(self.url, data=payload)
283+
284+
async def remove_filter_tags(
285+
self,
286+
tags: Iterable[str],
287+
message: Dict = None,
288+
) -> StreamResponse:
289+
payload = {"remove_filter_tags": tags, "message": message}
290+
return await self.client.post(self.url, data=payload)

stream_chat/base/channel.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,32 @@ def get_draft(
527527
"""
528528
pass
529529

530+
@abc.abstractmethod
531+
def add_filter_tags(
532+
self, tags: Iterable[str], message: Dict = None
533+
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
534+
"""
535+
Adds filter tags to the channel
536+
537+
:param tags: list of tags to add
538+
:param message: optional system message
539+
:return: The server response
540+
"""
541+
pass
542+
543+
@abc.abstractmethod
544+
def remove_filter_tags(
545+
self, tags: Iterable[str], message: Dict = None
546+
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
547+
"""
548+
Removes filter tags from the channel
549+
550+
:param tags: list of tags to remove
551+
:param message: optional system message
552+
:return: The server response
553+
"""
554+
pass
555+
530556

531557
def add_user_id(payload: Dict, user_id: str) -> Dict:
532558
return {**payload, "user": {"id": user_id}}

stream_chat/channel.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,19 @@ def get_draft(
276276
params["parent_id"] = parent_id
277277

278278
return self.client.get(f"{self.url}/draft", params=params)
279+
280+
def add_filter_tags(
281+
self,
282+
tags: Iterable[str],
283+
message: Dict = None,
284+
) -> StreamResponse:
285+
payload = {"add_filter_tags": tags, "message": message}
286+
return self.client.post(self.url, data=payload)
287+
288+
def remove_filter_tags(
289+
self,
290+
tags: Iterable[str],
291+
message: Dict = None,
292+
) -> StreamResponse:
293+
payload = {"remove_filter_tags": tags, "message": message}
294+
return self.client.post(self.url, data=payload)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
from stream_chat.channel import Channel
4+
5+
6+
@pytest.mark.incremental
7+
class TestFilterTags:
8+
def test_add_and_remove_filter_tags(self, channel: Channel):
9+
# Add tags
10+
add_resp = channel.add_filter_tags(["vip", "premium"])
11+
assert "channel" in add_resp
12+
assert set(add_resp["channel"].get("filter_tags", [])) >= {"vip", "premium"}
13+
14+
# Remove one tag
15+
remove_resp = channel.remove_filter_tags(["premium"])
16+
assert "channel" in remove_resp
17+
remaining = remove_resp["channel"].get("filter_tags", [])
18+
assert "premium" not in remaining
19+
assert "vip" in remaining

0 commit comments

Comments
 (0)