ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
508 stars 577 forks source link

[FR]: Adding data only push notifications for communication (and other) style display of notifications #1673

Open typefox09 opened 1 year ago

typefox09 commented 1 year ago

Feature Request

Plugin

Capacitor Push Notifications

Description

  1. Add functionality to create rich chat message notifications. Creating more meaningful notifications helps drive engagement and response times.

Documentation to implement: https://developer.android.com/develop/ui/views/notifications/group

Add functionality to hook into the following 2 lines on the notification builder:

    .setLargeIcon(emailObject.getSenderAvatar())
    .setGroup(GROUP_ID)

My proposal would be to allow data only notifications for Capacitor's Push Notifications. This would give us the ability to handle the presentation style of notifications. It'd also be great if we could also add actions in the push notifications.

NOTE: I'm aware this functionality is available on local notifications, but this doesn't help when your relying on push (as our app will be closed often). Essentially trying to get a system similar to what Whatsapp, Signal, etc have with their notifications (always displays rich notifications with actions, regardless if in foreground / background or closed).

Platform(s)

iOS (communication notifications - https://developer.apple.com/videos/play/wwdc2021/10091/) Android (Group notifications - https://developer.android.com/develop/ui/views/notifications/group)

typefox09 commented 1 year ago

Also, it appears the code below prevents our app from displaying data only notifications when our app is closed as it prevents fireNotification from being called. Why is this?

public void load() {
    notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    firebaseMessagingService = new MessagingService();

    staticBridge = this.bridge;
    if (lastMessage != null) {
        fireNotification(lastMessage);
        lastMessage = null;
    }

    notificationChannelManager = new NotificationChannelManager(getActivity(), notificationManager, getConfig());
}

public static void sendRemoteMessage(RemoteMessage remoteMessage) {
    PushNotificationsPlugin pushPlugin = PushNotificationsPlugin.getPushNotificationsInstance();
    if (pushPlugin != null) {
        Log.d("PushNotificationPlugin", "second"); // test to see if called
        pushPlugin.fireNotification(remoteMessage);
    } else {
        lastMessage = remoteMessage;
        Log.d("PushNotificationPlugin", "failed"); // test to see if failed
    }
}

public static PushNotificationsPlugin getPushNotificationsInstance() {
    if (staticBridge != null && staticBridge.getWebView() != null) {
        PluginHandle handle = staticBridge.getPlugin("PushNotifications");
        if (handle == null) {
            return null;
        }
        return (PushNotificationsPlugin) handle.getInstance();
    }
    return null;
}