Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Cadair opened this issue Jan 27, 2021 · 8 comments

Comments

@Cadair
Copy link
Contributor

Cadair commented Jan 27, 2021

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

@jerinjtitus
Copy link

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

@Cadair
Copy link
Contributor Author

Cadair commented Feb 26, 2021

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.

@jerinjtitus
Copy link

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?

@Cadair
Copy link
Contributor Author

Cadair commented Mar 1, 2021

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

@jerinjtitus
Copy link

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

@Cadair
Copy link
Contributor Author

Cadair commented Mar 2, 2021

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.

@jerinjtitus
Copy link

jerinjtitus commented Mar 3, 2021

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)

@Cadair
Copy link
Contributor Author

Cadair commented Mar 3, 2021

Yes please do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants