element-hq / element-hq/synapse

ModuleAPI: provide method to set email / threepid

Open
#13,402 0 comments 0 reactions 0 assignees View on GitHub
A-3PID A-Modules T-Enhancement
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 6h
Merged PRs (30d)
46

Description

This issue has been migrated from [#13402](https://github.com/matrix-org/synapse/issues/13402).

---

I am comparing / syncing user email on login, and for this i currently use:

```python
async def set_email(
self,
user_id: str,
email: str
) -> bool:
threepid_dict_list = await self.api.get_threepids_for_user(user_id)
for threepid_dict in threepid_dict_list:
if threepid_dict['address'] == email:
logger.info('User %s already has this email set. Nice', user_id)
return False
logger.info('User %s did not have email %s set, adding it', user_id, email)
current_time = self.api._hs.get_clock().time_msec()
threepid_dict = {
"medium": "email",
"address": email,
"validated_at": current_time,
}
registration_handler = self.api._hs.get_registration_handler()
await registration_handler._register_email_threepid(user_id, threepid_dict, None)
return True
```

Which isn't great, because i go through api._hs.
Would be nice to have this provided by the API itself.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.