-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
update m.direct list for InviteAutoAccepter module #11578
Changes from all commits
896e67b
ebaf4d1
3d9ff23
c057768
15b3424
0c20d53
4ab0858
e0012a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Update the m.direct list when auto accepting invites with the [auto-accept invite module](https://github.com/matrix-org/synapse-auto-accept-invite). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -503,6 +503,50 @@ async def update_membership( | |
|
|
||
| return result | ||
|
|
||
| async def update_m_direct( | ||
| self, | ||
| sender: str, | ||
| target: str, | ||
| room_id: str, | ||
| ) -> None: | ||
| """Update a user's m_direct list. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this PR should ensure that there is a way of allowing the Module API to ignore updates from itself via the proposed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If we want to do that, then we should do it before #12327 merges. I guess we can add an argument to the account data handler's methods to differentiate changes done by the server vs changes done by an user (I'm not feeling comfortable about adding a flag about whether the change is done by a module specifically). Though it's worth noting that we have other similar callbacks, such as |
||
|
|
||
| Params: | ||
| sender: The user who sent the invite, used as the key to update the list. | ||
| target: The user whose user's m_direct list is being updated. | ||
| room_id: The room ID which is being added to the list. | ||
| """ | ||
|
|
||
| logger.debug( | ||
| "InviteAutoAccepter: update_m_direct is triggered with room id: %s, sender user id: %s, target user id: %s", | ||
| room_id, | ||
| sender, | ||
| target, | ||
| ) | ||
|
|
||
| # Retrieve user account data | ||
| user_account_data, _ = await self.store.get_account_data_for_user(target) | ||
|
|
||
| # Retrieve m direct list | ||
| direct_rooms = user_account_data.get(AccountDataTypes.DIRECT, {}) | ||
|
|
||
| # Check which key this room is under | ||
| if isinstance(direct_rooms, dict): | ||
| m_list_changed = False | ||
| if sender in direct_rooms: | ||
| if room_id not in direct_rooms[sender]: | ||
| # Add new room_id to this key | ||
| direct_rooms[sender].append(room_id) | ||
| m_list_changed = True | ||
| else: | ||
| direct_rooms[sender] = [room_id] | ||
| m_list_changed = True | ||
| if m_list_changed: | ||
| # Save back to user's m.direct account data | ||
| await self.account_data_handler.add_account_data_for_user( | ||
| target, AccountDataTypes.DIRECT, direct_rooms | ||
| ) | ||
|
|
||
| async def update_membership_locked( | ||
| self, | ||
| requester: Requester, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -889,6 +889,40 @@ async def update_room_membership( | |
|
|
||
| return event | ||
|
|
||
| async def update_m_direct( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I believe I have been misunderstood here. What I was trying to say is that Instead, I would suggest adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep but as a first step I added just updating the list. I guess the logic for that is also better in the module, could we keep that also for a next step? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Module API is supposed to be a stable API. So I don't think we should add things to it if we're already planning to get rid of them soon, as it would mean we would need to maintain an unnecessary layer of backwards compatibility when we do the switch. So since we already have an idea of what the long-term solution should look like (and it's not a complex one) I think we should just do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No objections here with that; it does reflect that it will overwrite account data so sounds right. |
||
| self, | ||
| sender: str, | ||
| target: str, | ||
| room_id: str, | ||
| content: Optional[JsonDict] = None, | ||
| ) -> None: | ||
| """Update a user's m_direct list. | ||
|
|
||
| Params: | ||
| sender: The user who sent the invite, used as the key to update the list. | ||
| target: The user whose user's m_direct list is being updated. | ||
| room_id: The room ID which is being added to the list. | ||
| """ | ||
| logger.debug("InviteAutoAccepter: content of update_m_direct %s", content) | ||
| if not self.is_mine(sender): | ||
| raise RuntimeError( | ||
| "Tried to send an event as a user that isn't local to this homeserver", | ||
| ) | ||
|
|
||
| if content is None: | ||
| content = {} | ||
| # Update the m direct list | ||
| is_direct = content.get("is_direct", False) | ||
| logger.debug("InviteAutoAccepter: is_direct is %s", is_direct) | ||
| logger.debug("InviteAutoAccepter: target is %s", target) | ||
| logger.debug("InviteAutoAccepter: sender is %s", sender) | ||
| if target != sender and is_direct: | ||
| await self._hs.get_room_member_handler().update_m_direct( | ||
| sender=sender, | ||
| target=target, | ||
| room_id=room_id, | ||
| ) | ||
|
|
||
| async def create_and_send_event_into_room(self, event_dict: JsonDict) -> EventBase: | ||
| """Create and send an event into a room. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about async for the function I added, does it need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes since it contains
awaitin the body — perfectly correct