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

Update Account Data with user matrix id for invited user by email #3743

Merged
merged 4 commits into from
Aug 23, 2021

Conversation

Florian14
Copy link
Contributor

Fixes #3643

Update the Account Data when an user has been invited to a DM by email (which is not bound to an existing account).

The DM is initially populated with the invited user email and stuck with this email when the user has joined Element by creating an account. Therefore, the RoomSummary.directUserId is also stuck on the email and does not match the otherUserId which has been updated with the user matrix id.

To handle the user registration, we catch the m.room.member event which contains the matrix id as part of the third_party_invite content. Then, we check the account data dictionary and update the entries matching the roomId attached to the event, and where the user id does not match the matrix id pattern.
Update the account data will then cause the update of the directUserId in the RoomSummary.

@Florian14 Florian14 requested a review from bmarty July 28, 2021 09:15
When an user has been invited by email to a DM, account data entry was stuck on the user email after the user account creation.
When the user has joined element, an event m.room.member is triggered for each room attached to the user, containing a third party invite with the user matrix id. We use this event to update the user account with the matrix id.
}

// remove roomId from currentDirectUserId entry
hasUpdate = hasUpdate or(directChats[currentDirectUserId]?.remove(roomId) == true)
Copy link
Member

@bmarty bmarty Jul 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to assign hasUpdate here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the remove method will modify the direct chat dictionary if the given item has been found and removed, so I want to edit this flag in that case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I was wondering if hasUpdate was not already equal to true in this case. It can maybe add some cleanup on some existing account data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I understand now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand, I use the or function which will always call the second part of the operation (whether hasUpdate is true or not). The flag should be updated for each modification in the direct chats dictionary. In our case, the cleanup will be performed only for members related to the given directUserIdsToUpdate dictionary.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small remarks/question. Can you add a file for towncrier please?

// remove roomId from currentDirectUserId entry
hasUpdate = hasUpdate or(directChats[currentDirectUserId]?.remove(roomId) == true)
// remove currentDirectUserId entry if there is no attached room anymore
hasUpdate = hasUpdate or(directChats.takeIf { it[currentDirectUserId].isNullOrEmpty() }?.remove(currentDirectUserId) != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer, If I remove a key from the directChats dictionary, I also want to edit this flag in order to update the accountData with the updated dictionary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= null could be replaced by == true, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop, in that case, remove returns the removed object, if any or null otherwise

@Florian14
Copy link
Contributor Author

Some small remarks/question. Can you add a file for towncrier please?

Done

@Florian14 Florian14 requested a review from bmarty August 2, 2021 07:24
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the update

@bmarty bmarty merged commit 4a33fbb into develop Aug 23, 2021
@bmarty bmarty deleted the florian14/dm_email_invite branch August 23, 2021 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DM created to invite someone by email is stuck on the email address in the AccountData
3 participants