Skip to content

notif: Replace flutter_local_notification createNotificationChannel with pigeon #795

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 3 commits into from
Jul 28, 2024

Conversation

rajveermalviya
Copy link
Member

Work towards #351

@rajveermalviya rajveermalviya requested a review from sm-sayedi July 9, 2024 06:23
@rajveermalviya rajveermalviya added the buddy review GSoC buddy review needed. label Jul 9, 2024
@sm-sayedi
Copy link
Collaborator

sm-sayedi commented Jul 10, 2024

I will leave my review in the next few hours.

Copy link
Collaborator

@sm-sayedi sm-sayedi left a comment

Choose a reason for hiding this comment

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

Thanks @rajveermalviya for this! Just a small comment below, otherwise LGTM!

Let's move forward to the mentor review with @sumanthvrao!

/// Corresponds to `androidx.core.app.NotificationManagerCompat.createNotificationChannel`.
///
/// See: https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannel(androidx.core.app.NotificationChannelCompat)
void createNotificationChannel(NotificationChannel channel);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if this could return Future<void> instead of void in here too, as the autogenerated concrete class has a return type of Future<void>. Looking at the docs from the link provided, it seems that this method has a return type of void, but that's in Java, and it doesn't have a type Future; at least that's how I know so far about Java. 😀

Copy link
Member Author

Choose a reason for hiding this comment

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

This file is a Pigeon file, not a standard Dart file. It contains types and methods that define the native plugin API interface. See Pigeon's example.

Adding a Future<void> here will result in an error:

Error: pigeon/notifications.dart:120: Unknown type: Future

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok thanks, got it!

@sm-sayedi sm-sayedi added mentor review GSoC mentor review needed. and removed buddy review GSoC buddy review needed. labels Jul 11, 2024
@sm-sayedi sm-sayedi requested a review from sumanthvrao July 11, 2024 22:37
@rajveermalviya rajveermalviya requested a review from kenclary July 12, 2024 08:40
Copy link
Collaborator

@kenclary kenclary left a comment

Choose a reason for hiding this comment

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

this looks fine to me, but I have basically no familiarity with pigeon.

@rajveermalviya rajveermalviya added maintainer review PR ready for review by Zulip maintainers and removed mentor review GSoC mentor review needed. labels Jul 13, 2024
@rajveermalviya rajveermalviya force-pushed the pr-pigeon-create-channel branch from 2ef9e12 to 60d84a0 Compare July 15, 2024 22:31
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! Small comments below, and now over to Greg for his review.

@@ -94,8 +94,39 @@ class MessagingStyle {
final bool isGroupConversation;
}

/// Corresponds to `androidx.core.app.NotificationChannelCompat`
///
/// See: https://developer.androicd.com/reference/androidx/core/app/NotificationChannelCompat
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: developer.android.com

///
/// See: https://developer.android.com/reference/android/app/NotificationChannel#setImportance(int)
abstract class NotificationImportance {
/// Corresponds to [`IMPORTANCE_UNSPECIFIED`](https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE_UNSPECIFIED())
Copy link
Collaborator

Choose a reason for hiding this comment

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

The [text](example.com) syntax makes it a bit harder to work out what the intended URL is and select it, especially here where the intended URL ends with ")".

I did notice Android Studio helpfully trying to linkify this in a hover interaction:

image

but then it similarly gets confused about what the intended URL is; it takes me here: https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE_UNSPECIFIED(

when it should have taken me here: https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE_UNSPECIFIED()

so the browser just leaves me at the top of the page, instead of scrolling me down to the #IMPORTANCE_UNSPECIFIED() element.

So I think probably most helpful to give up that syntax and just write some thing like:

  /// Corresponds to `IMPORTANCE_UNSPECIFIED`:
  ///   https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#IMPORTANCE_UNSPECIFIED()

(here and elsewhere in the PR)

@chrisbobbe chrisbobbe added integration review Added by maintainers when PR may be ready for integration and removed maintainer review PR ready for review by Zulip maintainers labels Jul 17, 2024
@rajveermalviya rajveermalviya force-pushed the pr-pigeon-create-channel branch from 60d84a0 to e37e269 Compare July 18, 2024 14:03
@rajveermalviya
Copy link
Member Author

Thanks for the review @chrisbobbe, pushed a new revision PTAL :)

@rajveermalviya rajveermalviya force-pushed the pr-pigeon-create-channel branch 2 times, most recently from ab32f24 to 01adf07 Compare July 19, 2024 06:09
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks @rajveermalviya, and thanks @sm-sayedi and @chrisbobbe for the previous reviews!

Generally this looks great — a few nits below.

///
/// See: https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat
class NotificationChannel {
/// Corresponds to [`NotificationChannelCompat.Builder`](https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat.Builder#Builder(java.lang.String,int))
Copy link
Member

Choose a reason for hiding this comment

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

nit: one remaining instance of the pattern @chrisbobbe pointed out above

Copy link
Member

Choose a reason for hiding this comment

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

Separately, the reference to the builder class is good but I think it's most accurate to link to the class as a whole rather than that constructor. Three of the five parameters here don't go to the builder's constructor, but rather to method calls on the builder.


/// For use in [NotificationChannel.importance].
///
/// See: https://developer.android.com/reference/android/app/NotificationChannel#setImportance(int)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// See: https://developer.android.com/reference/android/app/NotificationChannel#setImportance(int)
/// See:
/// https://developer.android.com/reference/android/app/NotificationChannel#setImportance(int)
/// https://developer.android.com/reference/android/app/NotificationChannel#getImportance()

The getter's doc has some additional information that isn't on the setter, and they don't link to each other, so best to provide both.

/// Corresponds to `androidx.core.app.NotificationChannelCompat`
///
/// See: https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat
class NotificationChannel {
Copy link
Member

Choose a reason for hiding this comment

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

nit: put this at the top of the file, before PendingIntent — that makes a nice logical lifecycle-oriented order

The methods on AndroidNotificationHostApi are already good this way.

The enum class NotificationImportance should get the same treatment, coming before PendingIntentFlag.

Comment on lines 476 to 534
class FakeAndroidFlutterLocalNotificationsPlugin extends Fake implements AndroidFlutterLocalNotificationsPlugin {
}

class FakeIOSFlutterLocalNotificationsPlugin extends Fake implements IOSFlutterLocalNotificationsPlugin {
}
Copy link
Member

Choose a reason for hiding this comment

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

Neat!

Does this mean we can also cut out the test binding's resolvePlatformSpecificImplementation? That'd be a nice further cleanup commit to come after this one.

@@ -513,6 +509,11 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
_activeNotificationsMessagingStyle.clear();
}

@override
Future<void> createNotificationChannel(NotificationChannel channel) async {
Copy link
Member

Choose a reason for hiding this comment

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

nit: keep this next to the data it acts on (so _createdChannels)

Copy link
Member

Choose a reason for hiding this comment

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

Relatedly, in the first commit this should go above takeNotifyCalls, so as not to separate that from notify.

@rajveermalviya rajveermalviya force-pushed the pr-pigeon-create-channel branch 2 times, most recently from bfe1433 to 59d248d Compare July 25, 2024 23:10
@rajveermalviya
Copy link
Member Author

Thanks for the review @gnprice, pushed a new revision.

@rajveermalviya rajveermalviya requested a review from gnprice July 25, 2024 23:11
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks for the revision! Two nits, and otherwise this looks great.

Comment on lines 13 to 18
/// See:
/// https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat
/// https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat.Builder#Builder(java.lang.String,int)
class NotificationChannel {
NotificationChannel({
Copy link
Member

Choose a reason for hiding this comment

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

Ah, just to clarify what I meant at #795 (comment) because it might have been confusing:

I think having a doc comment on this Pigeon/Dart constructor is fine and potentially helpful. What I meant was that the doc on this constructor should link to the doc of the upstream builder class as a whole, and not to the specific point on that page for the builder's constructor.

So like this:

Suggested change
/// See:
/// https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat
/// https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat.Builder#Builder(java.lang.String,int)
class NotificationChannel {
NotificationChannel({
/// See:
/// https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat
/// https://developer.android.com/reference/androidx/core/app/NotificationChannelCompat.Builder
class NotificationChannel {
NotificationChannel({

but also that second link would be fine to move back to being a doc comment on this NotificationChannel constructor rather than on the NotificationChannel class.

FlutterLocalNotificationsPlatform? _platform;

@override
T? resolvePlatformSpecificImplementation<T extends FlutterLocalNotificationsPlatform>() {
Copy link
Member

Choose a reason for hiding this comment

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

commit-structure nit: this should come as a separate commit after the main commit, as per #795 (comment)

@rajveermalviya rajveermalviya force-pushed the pr-pigeon-create-channel branch from 59d248d to 107810f Compare July 28, 2024 08:55
@rajveermalviya
Copy link
Member Author

Thanks for the review @gnprice, pushed a new revision, PTAL.

@rajveermalviya rajveermalviya requested a review from gnprice July 28, 2024 08:57
@rajveermalviya rajveermalviya force-pushed the pr-pigeon-create-channel branch 2 times, most recently from de6271f to b36b8da Compare July 28, 2024 19:28
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks for the revision! Looks good — merging, after fixing two quick nits mentioned below.

This is great progress on #351; looking forward to seeing the remaining pieces.

Comment on lines 530 to 533
class FakeAndroidFlutterLocalNotificationsPlugin extends Fake implements AndroidFlutterLocalNotificationsPlugin {
}

class FakeIOSFlutterLocalNotificationsPlugin extends Fake implements IOSFlutterLocalNotificationsPlugin {
Copy link
Member

Choose a reason for hiding this comment

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

nit: these can be cut too, since they're effectively part of the implementation of resolvePlatformSpecificImplementation

(the previous revision did cut them, so I'm guessing their coming back was a rebase error)

FlutterLocalNotificationsPlatform? _platform;

@override
T? resolvePlatformSpecificImplementation<T extends FlutterLocalNotificationsPlatform>() {
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:

notif [nfc]: Remove unused test harness for flutter_local_notification

This sounds like it might mean our whole test harness for that package. Also the package's name has an "s" at the end. So:

notif [nfc]: Remove unused test harness for parts of flutter_local_notifications

@gnprice
Copy link
Member

gnprice commented Jul 28, 2024

Oh and a different commit-message nit — the commit series looks like this:
1f641b7 notif: Add createNotificationChannel method to pigeon bindings
2af238b notif: Add createNotificationChannel method to pigeon bindings
b35b73c28 notif [nfc]: Remove unused test harness for parts of flutter_local_notifications

So the first commit message is duplicated.

I think you intended the second commit to have the message it had in the last revision:

notif: Replace flutter_local_notification `createNotificationChannel` with pigeon

Updates #351

So I'll put that message back.

This is probably also a good moment for a reminder that I highly recommend setting up and using a graphical Git client, like gitk. Especially when doing a rebase, or operations like splitting up commits, a graphical client can be extremely helpful for getting a clear picture of what the old and new branch look like. I think if you'd used gitk or similar when self-reviewing your revision, you'd probably have immediately spotted that the commit message on the second commit had gotten clobbered.

@gnprice gnprice force-pushed the pr-pigeon-create-channel branch from b36b8da to 016f22a Compare July 28, 2024 21:35
@gnprice gnprice merged commit 016f22a into zulip:main Jul 28, 2024
1 check passed
@rajveermalviya rajveermalviya deleted the pr-pigeon-create-channel branch July 28, 2024 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants