discourse-chat-integration
discourse-chat-integration copied to clipboard
[Matrix] Room aliases and auto-join
I would like to add support for auto-joining rooms to the Matrix provider. It does the auto-join in either of two cases:
- The
auto_join
setting is set globally for the provider - A room alias is set as room ID
I combined the two because the join
endpoint in the Matrix Client-Server API conveniently allows passing aliases, and returns the real room ID in the body.
The feature is quite important as we are facing an issue with the limitation that only room IDs are supported, and rooms are not auto-joined: Room Upgrades. When upgrading the room version in Matrix, a new room with a new ID is created. All users have to join the new room, in turn, but all aliases are moved. So allowing both using an alias, and auto-joining, fixes that, without having to re-configure all rooms in Discourse.
The feature comes at the cost of one additional HTTP call.
For adding a test for auto-join, I still have to learn how to write them using Spec.
@davidtaylorhq I'm not sure how we approve things for chat providers we don't use ourselves.
Thanks @Natureshadow, and sorry for the delay here. We'd be happy to accept this change, but we will need to add some kind of rspec test to make sure it doesn't regress in the future. Is that something you'd be able to add? There should be an existing matrix spec file to uses as a basis.
Thanks @Natureshadow, and sorry for the delay here. We'd be happy to accept this change, but we will need to add some kind of rspec test to make sure it doesn't regress in the future. Is that something you'd be able to add? There should be an existing matrix spec file to uses as a basis.
Yep, I would like to do that, but until now, as stated above, I failed to understand how this test framework works. Specifically, I am not sure how to design the mock API to test against.
You can simulate an API like this:
https://github.com/discourse/discourse-chat-integration/blob/ae0389ca89f26401a6c4cffaaae6adcf14af0e15/spec/lib/discourse_chat_integration/provider/matrix/matrix_provider_spec.rb#L17
We use the webmock
library for this: https://github.com/bblimke/webmock
Going to close this for now, but please feel free to reopen if/when some tests are added.