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: package info indirection #1143

Open
wants to merge 3 commits 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 {
Copy link
Member

Choose a reason for hiding this comment

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

binding: add packageName to the packageInfo class in the binding class 
made changes to access packageName from the PackageInfo class.
remove getAppBundleId() from Zulip Binding class
Add packageName variable to PackageInfo class
Fixes #407

The commit claims that getAppBundleId() got removed, but it is not present in the commit itself. For changes that address reviews on a previous revision of the commit, the PR thread is more appropriate.

The commit summary and the "Fixes" line also need to be updated. This commit doesn't fix #407. We should move this line to the next commit where we start using packageName.

For the commit message, changes that one can tell from reading the diffs generally don't need to be reiterated: "made changes to access packageName from the PackageInfo class"
"Add packageName variable to PackageInfo class".

Please review Zulip's commit discipline linked in the README https://github.com/zulip/zulip-flutter?tab=readme-ov-file#submitting-a-pull-request

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
4 changes: 2 additions & 2 deletions lib/notifications/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ 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);
// 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.

Since this resolves the TODO, we can remove this line.

await addApnsToken(connection, token: token, appid: (await ZulipBinding.instance.packageInfo)?.packageName ?? "com.zulip.flutter");
Copy link
Member

Choose a reason for hiding this comment

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

I think there is an underlying issue if packageInfo is missing, so let's include a // TODO(log) comment here.

Copy link
Member

Choose a reason for hiding this comment

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

This case is interesting so it might worth a test for it. Let's find a way to test when we fallback to this default value, if packageInfo is somehow missing.


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');
const packageInfo = PackageInfo(version: '0.0.1', buildNumber: '1', packageName: 'com.zulip.flutter.test');

const testCases = [
('ZulipFlutter/0.0.1+1 (Android 14)', AndroidDeviceInfo(release: '14', sdkInt: 34), ),
Expand Down
3 changes: 2 additions & 1 deletion test/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,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 const _defaultPackageInfo = PackageInfo(version: '0.0.1', buildNumber: '1', packageName: 'com.zulip.flutter.test');

void _resetPackageInfo() {
packageInfoResult = _defaultPackageInfo;
Expand Down Expand Up @@ -380,6 +380,7 @@ class TestZulipBinding extends ZulipBinding {
Future<void> toggleWakelock({required bool enable}) async {
_wakelockEnabled = enable;
}

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is unintentional.

}

class FakeFirebaseMessaging extends Fake implements FirebaseMessaging {
Expand Down
4 changes: 2 additions & 2 deletions test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ void main() {
if (defaultTargetPlatform == TargetPlatform.android) {
checkLastRequestFcm(token: '012abc');
} else {
checkLastRequestApns(token: '012abc', appid: 'com.zulip.flutter');
checkLastRequestApns(token: '012abc', appid:(await testBinding.packageInfo)?.packageName?? 'com.zulip.flutter.test');
Copy link
Member

Choose a reason for hiding this comment

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

The test should encode the clear expectation of what the expected appid is. Let's avoid looking up the value and use a literal string instead.

}

if (defaultTargetPlatform == TargetPlatform.android) {
Expand Down Expand Up @@ -1071,7 +1071,7 @@ void main() {
if (defaultTargetPlatform == TargetPlatform.android) {
checkLastRequestFcm(token: '012abc');
} else {
checkLastRequestApns(token: '012abc', appid: 'com.zulip.flutter');
checkLastRequestApns(token: '012abc', appid:(await testBinding.packageInfo)?.packageName?? 'com.zulip.flutter.test');
Copy link
Member

Choose a reason for hiding this comment

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

Same as the other case.

}

if (defaultTargetPlatform == TargetPlatform.android) {
Expand Down
8 changes: 8 additions & 0 deletions test/notifications/receive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ void main() {
.length.equals(1);
}, variant: const TargetPlatformVariant({TargetPlatform.android, TargetPlatform.iOS}));
});

group('tokens', () {
test('APNs token registration using correct app bundle ID', () async {
await init();
check((await testBinding.packageInfo)?.packageName?? 'com.zulip.flutter.test')
Copy link
Member

Choose a reason for hiding this comment

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

Falling back to com.zulip.flutter.test defeats the purpose of this test. I think we don't expect packageInfo to be missing in this case, right?

.equals('com.zulip.flutter.test');
}, );
});
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this commit should be dropped as getAppBundleId doesn't exist anymore.

This is one reason that we should include the tests in the same commit that implements the feature tested.

}