Skip to content
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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -303,10 +303,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 @@ -411,6 +413,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
9 changes: 6 additions & 3 deletions lib/notifications/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,12 @@ class NotificationService {
await addFcmToken(connection, token: token);

case TargetPlatform.iOS:
const appBundleId = 'com.zulip.flutter'; // TODO(#407) find actual value live
await addApnsToken(connection, token: token, appid: appBundleId);

final packageInfo = await ZulipBinding.instance.packageInfo;
if (packageInfo == null) {
assert(debugLog('missing packageInfo')); // TODO(log)
}
await addApnsToken(connection, token: token,
appid: packageInfo?.packageName ?? 'com.zulip.flutter');
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
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');
const packageInfo = PackageInfo(version: '0.0.1', buildNumber: '1', packageName: 'com.zulip.flutter');

const testCases = [
('ZulipFlutter/0.0.1+1 (Android 14)', AndroidDeviceInfo(release: '14', sdkInt: 34), ),
Expand Down
5 changes: 3 additions & 2 deletions test/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ class TestZulipBinding extends ZulipBinding {
BaseDeviceInfo? get syncDeviceInfo => deviceInfoResult;

/// The value that `ZulipBinding.instance.packageInfo` should return.
PackageInfo packageInfoResult = _defaultPackageInfo;
static const _defaultPackageInfo = PackageInfo(version: '0.0.1', buildNumber: '1');
PackageInfo? packageInfoResult = _defaultPackageInfo;
static const _defaultPackageInfo = PackageInfo(version: '0.0.1',
buildNumber: '1', packageName: 'com.zulip.flutter');

void _resetPackageInfo() {
packageInfoResult = _defaultPackageInfo;
Expand Down
17 changes: 17 additions & 0 deletions test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,9 @@ void main() {
// When the token later appears, send it.
connection.prepare(json: {});
await startFuture;
// This delay is needed to allow the listener callback to `store._registerNotificationToken()`
// that occurs as a side effect of `startFuture` setting the token value to complete.
await Future<void>.delayed(Duration.zero);
if (defaultTargetPlatform == TargetPlatform.android) {
checkLastRequestFcm(token: '012abc');
} else {
Expand All @@ -1191,6 +1194,20 @@ void main() {
checkLastRequestFcm(token: '456def');
}
}));

testAndroidIos('use default appId if packageInfo is missing', () => awaitFakeAsync((async) async {
if (defaultTargetPlatform == TargetPlatform.iOS) {
addTearDown(testBinding.reset);
testBinding.firebaseMessagingInitialToken = '012abc';
testBinding.packageInfoResult = null;
addTearDown(NotificationService.debugReset);
await NotificationService.instance.start();
prepareStore();
connection.prepare(json: {});
await updateMachine.registerNotificationToken();
checkLastRequestApns(token: '012abc', appid: 'com.zulip.flutter');
}
}));
});
}

Expand Down