notifications: Fix push notifications with multiple realms.

Previously, Zulip did not correctly handle the case of a mobile device
being registered with a push device token being registered for
multiple accounts on the same server (which is a common case on
zulipchat.com).  This was because our database `unique` and
`unique_together` indexes incorrectly enforced the token being unique
on a given server, rather than unique for a given user_id.

We fix this gap, and at the same time remove unnecessary (and
incorrectly racey) logic deleting and recreating the tokens in the
appropriate tables.

There's still an open mobile app bug causing repeated re-registrations
in a loop, but this should fix the fact that the relevant mobile bug
causes the server to 500.

Follow-up work that may be of value includes:
* Removing `ios_app_id`, which may not have much purpose.
* Renaming `last_updated` to `data_created`, since that's what it is now.

But none of those are critical to solving the actual bug here.

Fixes #8841.
This commit is contained in:
Tim Abbott
2018-10-10 15:53:13 -07:00
parent 83bcea3917
commit c57c4cf703
6 changed files with 77 additions and 35 deletions

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.14 on 2018-10-10 22:52
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('zerver', '0189_userprofile_add_some_emojisets'),
]
operations = [
migrations.AlterField(
model_name='pushdevicetoken',
name='token',
field=models.CharField(db_index=True, max_length=4096),
),
migrations.AlterUniqueTogether(
name='pushdevicetoken',
unique_together=set([('user', 'kind', 'token')]),
),
]