Skip to content

Commit 55a5d79

Browse files
author
Rafael Marinho
committed
[CHA-1230] support delivery receipts
1 parent c911a8b commit 55a5d79

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

stream_chat/async_chat/channel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ async def mark_read(self, user_id: str, **data: Any) -> StreamResponse:
138138
async def mark_unread(self, user_id: str, **data: Any) -> StreamResponse:
139139
payload = add_user_id(data, user_id)
140140
return await self.client.post(f"{self.url}/unread", data=payload)
141+
142+
async def mark_delivered(self, data: Dict[str, Any]) -> Optional[StreamResponse]:
143+
return await self.client.post("channels/delivered", data=data)
141144

142145
async def get_replies(self, parent_id: str, **options: Any) -> StreamResponse:
143146
return await self.client.get(f"messages/{parent_id}/replies", params=options)

stream_chat/base/channel.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,18 @@ def mark_unread(
292292
:return: The server response
293293
"""
294294
pass
295+
296+
@abc.abstractmethod
297+
def mark_delivered(
298+
self, data: Dict[str, Any]
299+
) -> Union[StreamResponse, Awaitable[StreamResponse], None]:
300+
"""
301+
Send the mark delivered event for this user, only works if the `delivery_receipts` setting is enabled
302+
303+
:param data: MarkDeliveredOptions containing channel_delivered_message and other optional fields
304+
:return: The server response or None if delivery receipts are disabled
305+
"""
306+
pass
295307

296308
@abc.abstractmethod
297309
def get_replies(

stream_chat/channel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def mark_read(self, user_id: str, **data: Any) -> StreamResponse:
139139
def mark_unread(self, user_id: str, **data: Any) -> StreamResponse:
140140
payload = add_user_id(data, user_id)
141141
return self.client.post(f"{self.url}/unread", data=payload)
142+
143+
def mark_delivered(self, data: Dict[str, Any]) -> Optional[StreamResponse]:
144+
return self.client.post("channels/delivered", data=data)
142145

143146
def get_replies(self, parent_id: str, **options: Any) -> StreamResponse:
144147
return self.client.get(f"messages/{parent_id}/replies", params=options)

stream_chat/tests/test_channel.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,25 @@ def test_mark_unread(self, channel: Channel, random_user: Dict):
202202
channel.send_message({"id": msg_id, "text": "helloworld"}, random_user["id"])
203203
response = channel.mark_unread(random_user["id"], message_id=msg_id)
204204
assert "duration" in response
205+
206+
def test_mark_delivered(self, channel: Channel, random_user: Dict):
207+
delivery_data = {
208+
"channel_delivered_message": {channel.id: "test-message-id"},
209+
"user_id": random_user["id"]
210+
}
211+
212+
response = channel.mark_delivered(delivery_data)
213+
assert response is not None
214+
215+
delivery_data_with_options = {
216+
"channel_delivered_message": {channel.id: "test-message-id-2"},
217+
"user_id": random_user["id"],
218+
"client_id": "test-client",
219+
"connection_id": "test-connection"
220+
}
221+
222+
response = channel.mark_delivered(delivery_data_with_options)
223+
assert response is not None
205224

206225
def test_get_messages(self, channel: Channel, random_user: Dict):
207226
msg_id = str(uuid.uuid4())

0 commit comments

Comments
 (0)