diff --git a/example/lib/main.dart b/example/lib/main.dart index 190aa62..4602aac 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -170,6 +170,7 @@ class MyHomePage extends StatelessWidget { title: 'Test conversation', messages: messages, channelId: channelId, + jid: 'testjid', ), ); }, diff --git a/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Api.java b/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Api.java index beb1e1a..c1b3eb7 100644 --- a/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Api.java +++ b/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Api.java @@ -335,6 +335,20 @@ public class Api { this.channelId = setterArg; } + /** The JID of the chat in which the notifications happen. */ + private @NonNull String jid; + + public @NonNull String getJid() { + return jid; + } + + public void setJid(@NonNull String setterArg) { + if (setterArg == null) { + throw new IllegalStateException("Nonnull field \"jid\" is null."); + } + this.jid = setterArg; + } + /** Messages to show. */ private @NonNull List messages; @@ -375,6 +389,13 @@ public class Api { return this; } + private @Nullable String jid; + + public @NonNull Builder setJid(@NonNull String setterArg) { + this.jid = setterArg; + return this; + } + private @Nullable List messages; public @NonNull Builder setMessages(@NonNull List setterArg) { @@ -387,6 +408,7 @@ public class Api { pigeonReturn.setTitle(title); pigeonReturn.setId(id); pigeonReturn.setChannelId(channelId); + pigeonReturn.setJid(jid); pigeonReturn.setMessages(messages); return pigeonReturn; } @@ -394,10 +416,11 @@ public class Api { @NonNull ArrayList toList() { - ArrayList toListResult = new ArrayList(4); + ArrayList toListResult = new ArrayList(5); toListResult.add(title); toListResult.add(id); toListResult.add(channelId); + toListResult.add(jid); toListResult.add(messages); return toListResult; } @@ -410,7 +433,9 @@ public class Api { pigeonResult.setId((id == null) ? null : ((id instanceof Integer) ? (Integer) id : (Long) id)); Object channelId = list.get(2); pigeonResult.setChannelId((String) channelId); - Object messages = list.get(3); + Object jid = list.get(3); + pigeonResult.setJid((String) jid); + Object messages = list.get(4); pigeonResult.setMessages((List) messages); return pigeonResult; } diff --git a/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/NotificationReceiver.kt b/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/NotificationReceiver.kt index fa38e2d..cd022ad 100644 --- a/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/NotificationReceiver.kt +++ b/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/NotificationReceiver.kt @@ -14,7 +14,7 @@ class NotificationReceiver : BroadcastReceiver() { // send a notification to the app. // TODO: Notify app if (intent.action == MARK_AS_READ_ACTION) { - Log.d("NotificationReceiver", "Marking ${intent.getStringExtra("title")} as read") + Log.d("NotificationReceiver", "Marking ${intent.getStringExtra("jid")} as read") NotificationManagerCompat.from(context).cancel(intent.getLongExtra(MARK_AS_READ_ID_KEY, -1).toInt()) return } diff --git a/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Notifications.kt b/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Notifications.kt index 907e233..140b629 100644 --- a/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Notifications.kt +++ b/packages/moxplatform_android/android/src/main/java/me/polynom/moxplatform_android/Notifications.kt @@ -41,7 +41,7 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif val markAsReadIntent = Intent(context, NotificationReceiver::class.java).apply { action = MARK_AS_READ_ACTION // TODO: Put the JID here - putExtra("title", notification.title) + putExtra("jid", notification.jid) } val markAsReadPendingIntent = PendingIntent.getBroadcast( context.applicationContext, @@ -50,6 +50,19 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif 0, ) + // -> Tap action + // Thanks https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L246 + // TODO: Copy the interface of awesome_notifications + val tapIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)!!.apply { + putExtra("jid", notification.jid) + } + val tapPendingIntent = PendingIntent.getActivity( + context, + notification.id.toInt(), + tapIntent, + PendingIntent.FLAG_UPDATE_CURRENT + ) + // Build the notification // TODO: Use a person // TODO: i18n @@ -97,6 +110,10 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif // TODO: I think this is wrong setSmallIcon(R.drawable.ic_service_icon) + // Tap action + setContentIntent(tapPendingIntent) + + // Notification actions addAction(replyAction) addAction( // TODO: Wrong icon diff --git a/packages/moxplatform_platform_interface/lib/src/api.g.dart b/packages/moxplatform_platform_interface/lib/src/api.g.dart index 09299ef..089454a 100644 --- a/packages/moxplatform_platform_interface/lib/src/api.g.dart +++ b/packages/moxplatform_platform_interface/lib/src/api.g.dart @@ -92,6 +92,7 @@ class MessagingNotification { required this.title, required this.id, required this.channelId, + required this.jid, required this.messages, }); @@ -104,6 +105,9 @@ class MessagingNotification { /// The id of the notification channel the notification should appear on. String channelId; + /// The JID of the chat in which the notifications happen. + String jid; + /// Messages to show. List messages; @@ -112,6 +116,7 @@ class MessagingNotification { title, id, channelId, + jid, messages, ]; } @@ -122,7 +127,8 @@ class MessagingNotification { title: result[0]! as String, id: result[1]! as int, channelId: result[2]! as String, - messages: (result[3] as List?)!.cast(), + jid: result[3]! as String, + messages: (result[4] as List?)!.cast(), ); } } diff --git a/pigeons/notifications.dart b/pigeons/api.dart similarity index 91% rename from pigeons/notifications.dart rename to pigeons/api.dart index 061e1d3..14d8a61 100644 --- a/pigeons/notifications.dart +++ b/pigeons/api.dart @@ -54,7 +54,7 @@ class NotificationMessage { } class MessagingNotification { - const MessagingNotification(this.title, this.id, this.messages, this.channelId); + const MessagingNotification(this.title, this.id, this.jid, this.messages, this.channelId); /// The title of the conversation. final String title; @@ -65,6 +65,9 @@ class MessagingNotification { /// The id of the notification channel the notification should appear on. final String channelId; + /// The JID of the chat in which the notifications happen. + final String jid; + /// Messages to show. final List messages; }