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

Commit

Permalink
Add an email pusher for new users
Browse files Browse the repository at this point in the history
If they registered with an email address and email notifs are enabled on the HS
  • Loading branch information
dbkr committed Apr 29, 2016
1 parent ec9cbe8 commit b2c04da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions synapse/push/pusherpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def add_pusher(self, user_id, access_token, kind, app_id,
# recreated, added and started: this means we have only one
# code path adding pushers.
pusher.create_pusher(self.hs, {
"id": None,
"user_name": user_id,
"kind": kind,
"app_id": app_id,
Expand Down
26 changes: 26 additions & 0 deletions synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, hs):
super(RegisterRestServlet, self).__init__()
self.hs = hs
self.auth = hs.get_auth()
self.store = hs.get_datastore()
self.auth_handler = hs.get_handlers().auth_handler
self.registration_handler = hs.get_handlers().registration_handler
self.identity_handler = hs.get_handlers().identity_handler
Expand Down Expand Up @@ -214,6 +215,31 @@ def on_POST(self, request):
threepid['validated_at'],
)

# And we add an email pusher for them by default, but only
# if email notifications are enabled (so people don't start
# getting mail spam where they weren't before if email
# notifs are set up on a home server)
if self.hs.config.email_enable_notifs:
# Pull the ID of the access token back out of the db
# It would really make more sense for this to be passed
# up when the access token is saved, but that's quite an
# invasive change I'd rather do separately.
user_tuple = yield self.store.get_user_by_access_token(
token
)

yield self.hs.get_pusherpool().add_pusher(
user_id=user_id,
access_token=user_tuple["token_id"],
kind="email",
app_id="m.email",
app_display_name="Email Notifications",
device_display_name=threepid["address"],
pushkey=threepid["address"],
lang=None, # We don't know a user's language here
data={},
)

if 'bind_email' in params and params['bind_email']:
logger.info("bind_email specified: binding")

Expand Down

0 comments on commit b2c04da

Please sign in to comment.