opsdroid
opsdroid copied to clipboard
Add a method on the matrix connector which lists all rooms the account is joined to
Somewhat related to #1724 but it's also useful for skills to be able to get a list of all joined (not just configured) rooms.
I am thinking a signature like:
def joined_rooms(self, encrypted_only=False):
which returns room_ids for the rooms. Richer nio room objects could then be obtained by doing connector.connection.rooms[room_id]
.
Hey, I am completely new here. Can you give me a gist on how to approach this?
You would use the nio.AsyncClient
object, which is the ConnectorMatrix.connection
attribute, and call the joined_rooms
method (https://matrix-nio.readthedocs.io/en/stable/nio.html#nio.Api.joined_rooms), and return a tuple of strings which are the matrix room ids of the rooms.
You would use the nio.AsyncClient object, which is the ConnectorMatrix.connection attribute, and call the joined_rooms method (https://matrix-nio.readthedocs.io/en/stable/nio.html#nio.Api.joined_rooms), and return a tuple of strings which are the matrix room ids of the rooms.
Thanks for the help.
So, the return value of joined_rooms
is a list of room_ids, right? I called ConnectorMatrix.connection.joined_rooms
which contains joined_rooms
method (from nio.Api
). So I think ConnectorMatrix.connection.joined_rooms
returns room_ids list (I am not totally sure of that).
Plus, I had one more doubt. How exactly can I check if a room is encrypted for encrypted_only
parameter?
So, the return value of
joined_rooms
is a list of room_ids, right?
Yes that is what I would like it to be.
I called
ConnectorMatrix.connection.joined_rooms
which containsjoined_rooms
method (fromnio.Api
). So I thinkConnectorMatrix.connection.joined_rooms
returns room_ids list (I am not totally sure of that).
It returns a JoinedRoomsResponse
instance or a JoinedRoomsError
instance depending on if the call was successful.
Plus, I had one more doubt. How exactly can I check if a room is encrypted for
encrypted_only
parameter?
I think you will need to attempt to get the m.room.encryption
state event for each room (using AsyncClient.room_get_state
) if the event exists then the room is encrypted. (You should only do this check if you need to (i.e. encrypted_only=True
) to save time.)
How exactly can I test the changes I done? Do I have to create a new test for it?
yeah, without filtering by encrypted the test should only make one API call so it should be easy enough to provide a canned response to the /joined_rooms
endpoint. See these tests as a good template.
How exactly can I test the changes I done?
Is it fine if I open a draft pull request on this for you to review? (Before starting with the tests)
Yes please do