Skip to content

Commit 3fff308

Browse files
xloemJohn Doejacobtomlinson
authored
Add handling of LeaveRoom event for matrix. (opsdroid#1982)
* Add handling of LeaveRoom event for matrix. * Test for matrix LeaveRoom * Fix test name --------- Co-authored-by: John Doe <[email protected]> Co-authored-by: Jacob Tomlinson <[email protected]>
1 parent ad52d90 commit 3fff308

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

opsdroid/connector/matrix/connector.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,11 @@ async def _send_room_address(self, address_event):
613613
async def _send_join_room(self, join_event):
614614
return await self.connection.join(join_event.target)
615615

616+
@register_event(events.LeaveRoom)
617+
@ensure_room_id_and_send
618+
async def _send_leave_room(self, leave_event):
619+
return await self.connection.room_leave(leave_event.target)
620+
616621
@register_event(events.UserInvite)
617622
@ensure_room_id_and_send
618623
async def _send_user_invitation(self, invite_event):
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
3+
from opsdroid import events
4+
5+
6+
@pytest.mark.add_response(
7+
"/_matrix/client/r0/rooms/!12345:localhost/leave",
8+
"POST",
9+
{},
10+
)
11+
@pytest.mark.add_response(
12+
"/_matrix/client/r0/directory/room/#test:localhost",
13+
"GET",
14+
{
15+
"room_id": "!12345:localhost",
16+
"servers": ["localhost"],
17+
},
18+
)
19+
@pytest.mark.asyncio
20+
async def test_leave_room(opsdroid, connector_connected, mock_api):
21+
await opsdroid.send(
22+
events.LeaveRoom(target="#test:localhost", connector=connector_connected)
23+
)
24+
assert mock_api.called("/_matrix/client/r0/rooms/!12345:localhost/leave")

0 commit comments

Comments
 (0)