opsdroid icon indicating copy to clipboard operation
opsdroid copied to clipboard

Add a method on the matrix connector which lists all rooms the account is joined to

Open Cadair opened this issue 3 years ago • 8 comments

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].

Cadair avatar Jan 27 '21 13:01 Cadair

Hey, I am completely new here. Can you give me a gist on how to approach this?

jerinjtitus avatar Feb 26 '21 11:02 jerinjtitus

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.

Cadair avatar Feb 26 '21 11:02 Cadair

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?

jerinjtitus avatar Feb 26 '21 13:02 jerinjtitus

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 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).

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.)

Cadair avatar Mar 01 '21 09:03 Cadair

How exactly can I test the changes I done? Do I have to create a new test for it?

jerinjtitus avatar Mar 02 '21 11:03 jerinjtitus

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.

Cadair avatar Mar 02 '21 14:03 Cadair

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)

jerinjtitus avatar Mar 03 '21 00:03 jerinjtitus

Yes please do

Cadair avatar Mar 03 '21 09:03 Cadair