Skip to content

Commit f954fd5

Browse files
committed
wip refresh on changed token
1 parent 76e004b commit f954fd5

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

lib/model/push_device.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,16 @@ class PushDeviceManager extends PerAccountStoreBase {
136136

137137
// TODO(#1764) if account.pushToken not null, skip? cf #322
138138

139-
int? pushAccountId = account.pushAccountId;
140-
Uint8List? pushKey = account.pushKey;
141-
if (pushAccountId == null) {
142-
pushAccountId = NotificationService.generatePushAccountId();
143-
pushKey = NotificationService.generatePushKey();
139+
if (token != account.pushToken) {
140+
// TODO(#1764) if old pushToken not null, maybe tell server to forget
144141
await updateAccount(AccountsCompanion(
145-
pushAccountId: drift.Value(pushAccountId),
146-
pushKey: drift.Value(pushKey),
142+
pushAccountId: drift.Value(NotificationService.generatePushAccountId()),
143+
pushKey: drift.Value(NotificationService.generatePushKey()),
144+
pushToken: drift.Value(token),
147145
));
148146
}
149-
if (pushKey == null) {
150-
throw StateError('Account missing pushKey while have pushAccountId'); // TODO(log)
151-
}
147+
final pushAccountId = account.pushAccountId!;
148+
final pushKey = account.pushKey!;
152149

153150
final tokenKind = switch (defaultTargetPlatform) {
154151
TargetPlatform.android => PushTokenKind.fcm,

0 commit comments

Comments
 (0)