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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pyjwt>=2.0.0,<3",
"typing_extensions; python_version < '3.8'",
]
tests_require = ["pytest", "pytest-asyncio <= 0.21.1"]
tests_require = ["pytest == 8.1.1", "pytest-asyncio <= 0.21.1"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pinned pytest version to last known working version
pytest-dev/pytest#12269

ci_require = [
"black",
"flake8",
Expand Down
12 changes: 12 additions & 0 deletions stream_chat/async_chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,18 @@ async def delete_message(self, message_id: str, **options: Any) -> StreamRespons
async def get_message(self, message_id: str, **options: Any) -> StreamResponse:
return await self.get(f"messages/{message_id}", options)

async def query_message_history(
self, filter: Dict = None, sort: List[Dict] = None, **options: Any
) -> StreamResponse:
params = options.copy()
params.update(
{
"filter": filter,
"sort": self.normalize_sort(sort),
}
)
return await self.post("messages/history", data=params)

async def query_users(
self, filter_conditions: Dict, sort: List[Dict] = None, **options: Any
) -> StreamResponse:
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 @@ -525,6 +525,15 @@ def get_message(
"""
pass

@abc.abstractmethod
def query_message_history(
self, filter: Dict = None, sort: List[Dict] = None, **options: Any
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Queries message history.
"""
pass

@abc.abstractmethod
def query_users(
self, filter_conditions: Dict, sort: List[Dict] = None, **options: Any
Expand Down
7 changes: 7 additions & 0 deletions stream_chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ def delete_message(self, message_id: str, **options: Any) -> StreamResponse:
def get_message(self, message_id: str, **options: Any) -> StreamResponse:
return self.get(f"messages/{message_id}", options)

def query_message_history(
self, filter: Dict = None, sort: List[Dict] = None, **options: Any
) -> StreamResponse:
params = options.copy()
params.update({"filter": filter, "sort": self.normalize_sort(sort)})
return self.post("messages/history", data=params)

def query_users(
self, filter_conditions: Dict, sort: List[Dict] = None, **options: Any
) -> StreamResponse:
Expand Down
36 changes: 36 additions & 0 deletions stream_chat/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,3 +828,39 @@ def test_unread_counts_batch(self, client: StreamChat, channel, random_users: Di
assert (
response["counts_by_user"][user_id]["total_unread_threads_count"] == 1
)

def test_query_message_history(
self, client: StreamChat, channel, random_user: Dict
):
msg_id = str(uuid.uuid4())
channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])
client.update_message(
{"id": msg_id, "text": "helloworld-1", "user_id": random_user["id"]}
)
client.update_message(
{"id": msg_id, "text": "helloworld-2", "user_id": random_user["id"]}
)
client.update_message(
{"id": msg_id, "text": "helloworld-3", "user_id": random_user["id"]}
)
client.update_message(
{"id": msg_id, "text": "helloworld-4", "user_id": random_user["id"]}
)

response = client.query_message_history(
{"message_id": {"$eq": msg_id}},
sort=[{"message_updated_at": -1}],
**{"limit": 1},
)

assert len(response["message_history"]) == 1
assert response["message_history"][0]["text"] == "helloworld-3"

response_next = client.query_message_history(
{"message_id": {"$eq": msg_id}},
sort=[{"message_updated_at": -1}],
**{"limit": 1, "next": response["next"]},
)

assert len(response_next["message_history"]) == 1
assert response_next["message_history"][0]["text"] == "helloworld-2"