Skip to content

notif: Use live value for app ID on registering APNs token #1451

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

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,12 @@ class LinuxDeviceInfo implements BaseDeviceInfo {
class PackageInfo {
final String version;
final String buildNumber;
final String packageName;

const PackageInfo({
required this.version,
required this.buildNumber,
required this.packageName,
});
}

Expand Down Expand Up @@ -427,6 +429,7 @@ class LiveZulipBinding extends ZulipBinding {
_syncPackageInfo = PackageInfo(
version: info.version,
buildNumber: info.buildNumber,
packageName: info.packageName,
);
} catch (e, st) {
assert(debugLog('Failed to prefetch package info: $e\n$st')); // TODO(log)
Expand Down
6 changes: 4 additions & 2 deletions lib/notifications/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ class NotificationService {
await addFcmToken(connection, token: token);

case TargetPlatform.iOS:
const appBundleId = 'com.zulip.flutter'; // TODO(#407) find actual value live
Copy link
Member

Choose a reason for hiding this comment

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

nit in commit message:

Fixes zulip#407

follow existing patterns for how to format this — use git log (better, git log --grep Fixes) to see examples

Copy link
Member

Choose a reason for hiding this comment

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

notif: Use live value for app ID on registering APNs token

Fixes #407

Closer, but make it a complete sentence:

notif: Use live value for app ID on registering APNs token

Fixes #407.

await addApnsToken(connection, token: token, appid: appBundleId);
final packageInfo = await ZulipBinding.instance.packageInfo;
await addApnsToken(connection,
token: token,
appid: packageInfo!.packageName);

case TargetPlatform.linux:
case TargetPlatform.macOS:
Expand Down
2 changes: 1 addition & 1 deletion test/api/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void main() {
});
}

const packageInfo = PackageInfo(version: '0.0.1', buildNumber: '1');
final packageInfo = eg.packageInfo(version: '0.0.1', buildNumber: '1');

const testCases = [
('ZulipFlutter/0.0.1+1 (Android 14)', AndroidDeviceInfo(release: '14', sdkInt: 34), ),
Expand Down
13 changes: 13 additions & 0 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:zulip/api/model/submessage.dart';
import 'package:zulip/api/route/messages.dart';
import 'package:zulip/api/route/realm.dart';
import 'package:zulip/api/route/channels.dart';
import 'package:zulip/model/binding.dart';
import 'package:zulip/model/database.dart';
import 'package:zulip/model/narrow.dart';
import 'package:zulip/model/settings.dart';
Expand Down Expand Up @@ -994,3 +995,15 @@ UpdateMachine updateMachine({
return UpdateMachine.fromInitialSnapshot(
store: store, initialSnapshot: initialSnapshot);
}

PackageInfo packageInfo({
String? version,
String? buildNumber,
String? packageName,
}) {
return PackageInfo(
version: version ?? '1.0.0',
buildNumber: buildNumber ?? '1',
packageName: packageName ?? 'com.example.app',
);
}
2 changes: 1 addition & 1 deletion test/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class TestZulipBinding extends ZulipBinding {

/// The value that `ZulipBinding.instance.packageInfo` should return.
PackageInfo packageInfoResult = _defaultPackageInfo;
static const _defaultPackageInfo = PackageInfo(version: '0.0.1', buildNumber: '1');
static final _defaultPackageInfo = eg.packageInfo();

void _resetPackageInfo() {
packageInfoResult = _defaultPackageInfo;
Expand Down
19 changes: 19 additions & 0 deletions test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ void main() {
addTearDown(testBinding.reset);
testBinding.firebaseMessagingInitialToken = '012abc';
addTearDown(NotificationService.debugReset);
testBinding.packageInfoResult = eg.packageInfo(packageName: 'com.zulip.flutter');
await NotificationService.instance.start();

// On store startup, send the token.
Expand Down Expand Up @@ -1318,6 +1319,7 @@ void main() {
addTearDown(testBinding.reset);
testBinding.firebaseMessagingInitialToken = '012abc';
addTearDown(NotificationService.debugReset);
testBinding.packageInfoResult = eg.packageInfo(packageName: 'com.zulip.flutter');
final startFuture = NotificationService.instance.start();

// TODO this test is a bit brittle in its interaction with asynchrony;
Expand All @@ -1336,6 +1338,7 @@ void main() {
// When the token later appears, send it.
connection.prepare(json: {});
await startFuture;
async.flushMicrotasks();
if (defaultTargetPlatform == TargetPlatform.android) {
checkLastRequestFcm(token: '012abc');
} else {
Expand All @@ -1350,6 +1353,22 @@ void main() {
checkLastRequestFcm(token: '456def');
}
}));

test('on iOS, use provided app ID from packageInfo', () => awaitFakeAsync((async) async {
final origTargetPlatform = debugDefaultTargetPlatformOverride;
addTearDown(() => debugDefaultTargetPlatformOverride = origTargetPlatform);
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
addTearDown(testBinding.reset);
testBinding.firebaseMessagingInitialToken = '012abc';
testBinding.packageInfoResult = eg.packageInfo(packageName: 'com.example.test');
addTearDown(NotificationService.debugReset);
await NotificationService.instance.start();

prepareStore();
connection.prepare(json: {});
await updateMachine.registerNotificationToken();
checkLastRequestApns(token: '012abc', appid: 'com.example.test');
}));
});

group('ZulipVersionData', () {
Expand Down