Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

ModuleAPI: provide method to resolve room_alias to room_id #13359

Closed
uriesk opened this issue Jul 22, 2022 · 4 comments · Fixed by #13428
Closed

ModuleAPI: provide method to resolve room_alias to room_id #13359

uriesk opened this issue Jul 22, 2022 · 4 comments · Fixed by #13428
Labels
A-Modules Module API: https://matrix-org.github.io/synapse/latest/modules/index.html T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.

Comments

@uriesk
Copy link

uriesk commented Jul 22, 2022

I am writing a pluggable module that joins rooms on login,
and i resolve room alias to id with:

    async def translate_room_aliases_to_ids(
        self,
        room_aliases: List[str],
    ) -> List[str]:
        room_ids = []
        logger.info('Translating room_aliases to ids')
        for alias in room_aliases:
            aliasObject = RoomAlias.from_string(alias)
            room = await self.api._store.get_association_from_room_alias(aliasObject)
            if room is not None:
                logger.info('Map alias %s to room %s', alias, room.room_id)
                room_ids.append(room.room_id)
        return room_ids;

Which isn't great, because i go through api._store.
Would be nice to have such a functionality in the api itself.

@babolivier
Copy link
Contributor

also a method to set email / threepids would be nice, this is what i am using now

This method will probably be implemented separately to the one you're initially requesting, could you make a separate issue about it so it's better tracked please?

@babolivier babolivier added the T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. label Jul 22, 2022
@uriesk
Copy link
Author

uriesk commented Jul 27, 2022

of course, #13402

@buffless-matt
Copy link
Contributor

@uriesk

I coincidentally have a present need for this as well 😄

I'm not sure DirectoryWorkerStore.get_association_from_room_alias would be appropriate to use for this new module API method and instead I think RoomMemberHandler.lookup_room_alias would be more appropriate because:

  • It handles both local and non-local/federated rooms.
  • It also queries appservices to try and do the translation.

The method could be accessed (in this new module API method) via self._hs.get_room_member_handler().

@buffless-matt
Copy link
Contributor

This was completed in #13428, so this issue can be closed.

@DMRobertson DMRobertson linked a pull request Aug 8, 2022 that will close this issue
4 tasks
@DMRobertson DMRobertson added the A-Modules Module API: https://matrix-org.github.io/synapse/latest/modules/index.html label Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Modules Module API: https://matrix-org.github.io/synapse/latest/modules/index.html T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants