Skip to content

Commit c9445d3

Browse files
feat: pending messages (#143)
* feat: pending messages * refactor: lint-fix * fix: test case * refactor: lint-fix * fix: test cases * refactor: lint-fix
1 parent 6099626 commit c9445d3

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

stream_chat/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ def translate_message(self, message_id: str, language: str) -> StreamResponse:
272272
f"messages/{message_id}/translate", data={"language": language}
273273
)
274274

275+
def commit_message(self, message_id: str) -> StreamResponse:
276+
return self.post(f"messages/{message_id}/commit")
277+
275278
def pin_message(
276279
self, message_id: str, user_id: str, expiration: int = None
277280
) -> StreamResponse:

stream_chat/tests/test_channel.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ def test_send_message_with_options(self, channel: Channel, random_user: Dict):
4747
assert "message" in response
4848
assert response["message"]["text"] == "hi"
4949

50+
def test_send_pending_message(
51+
self, client: StreamChat, channel: Channel, random_user: Dict
52+
):
53+
response = channel.send_message(
54+
{"text": "hi"},
55+
random_user["id"],
56+
pending=True,
57+
pending_message_metadata={"extra_data": "test"},
58+
)
59+
assert "message" in response
60+
assert response["message"]["text"] == "hi"
61+
62+
response = client.commit_message(response["message"]["id"])
63+
assert "message" in response
64+
assert response["message"]["text"] == "hi"
65+
5066
def test_send_event(self, channel: Channel, random_user: Dict):
5167
response = channel.send_event({"type": "typing.start"}, random_user["id"])
5268
assert "event" in response

stream_chat/tests/test_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ def test_get_app_settings(self, client: StreamChat):
124124
configs = client.get_app_settings()
125125
assert "app" in configs
126126

127+
def test_update_app_settings(self, client: StreamChat):
128+
client.update_app_settings(
129+
async_moderation_config={
130+
"callback": {
131+
"mode": "CALLBACK_MODE_REST",
132+
"server_url": "http://example.com/callback",
133+
},
134+
"timeout_ms": 10000, # how long messages should stay pending before being deleted
135+
}
136+
)
137+
127138
def test_update_user(self, client: StreamChat):
128139
user = {"id": str(uuid.uuid4())}
129140
response = client.update_user(user)

0 commit comments

Comments
 (0)