commit 678302bc3ea1b8ad31b03bbe0b5f3630f7169555 Author: toki Date: Mon May 25 13:45:37 2026 +0900 initial commit: mattermost-push-plugin diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9d7f25 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.build/ +.buildlog/ +.history +.svn/ +.swiftpm/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.flutter-plugins-dependencies +/build/ +/coverage/ diff --git a/.metadata b/.metadata new file mode 100644 index 0000000..80e7d69 --- /dev/null +++ b/.metadata @@ -0,0 +1,36 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa" + channel: "stable" + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + base_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + - platform: android + create_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + base_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + - platform: ios + create_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + base_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + - platform: macos + create_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + base_revision: 2c9eb20739dfec95e2c74bd3dfa4601b0a8a36aa + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..41cc7d8 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ba75c69 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0f7aa5f --- /dev/null +++ b/README.md @@ -0,0 +1,135 @@ +# mattermost_push_plugin + +An Android-first Flutter plugin for receiving Mattermost push notifications, displaying system notifications, handling tap events, processing inline replies, delivering ACKs, and securely storing device tokens, authentication tokens, and signing keys. + +--- + +## Support Matrix + +| Platform | Support Status | Native Features Implemented | +|---|---|---| +| **Android** | **Full (Production Ready)** | Kotlin, Native FCM Service, Room DB, JJWT Verification, OkHttp ACK Client, Notification Builder, Inline Reply Receiver, Dismiss Receiver | +| **iOS** | No-op Scaffold (Stub) | Future roadmap milestone | +| **macOS** | No-op Scaffold (Stub) | Future roadmap milestone | + +--- + +## Core Responsibilities + +This plugin isolates the Mattermost push notification domain logic from the host application. + +```mermaid +graph TD + A[Mattermost Server] -->|Secure JWT Push| B(Plugin Native FCM Service) + B -->|1. Signature Verification JJWT| C{Valid?} + C -->|Yes| D[2. Store & Build Notification] + C -->|No| E[Drop Push] + D -->|3. OkHttp ACK API| A + D -->|4. Display System Notification| F(Android Status Bar) + F -->|Tap Notification| G[5. Method Channel Opened Event] + F -->|Inline Reply| H[6. Broadcast Reply Receiver] + H -->|Deliver via OkHttp| A + G -->|Flutter Stream| I(Host App Navigation) +``` + +--- + +## Public Dart API Reference + +Get the singleton instance via `MattermostPushPlugin.instance`. + +### 1. Initialization + +Initialize the plugin channel subscriptions, listen to token refreshes, and request notification permissions: + +```dart +import 'package:mattermost_push_plugin/mattermost_push_plugin.dart'; + +await MattermostPushPlugin.instance.initialize(); +``` + +### 2. Streams & Callbacks + +Set up listeners and navigation callbacks inside your app initialization flow: + +```dart +// 1. Listen to raw native notification events (Message, Clear, Session, etc.) +MattermostPushPlugin.instance.onNotification.listen((data) { + print("Raw push received: $data"); +}); + +// 2. Listen to user interaction (notification tap) events +MattermostPushPlugin.instance.onNotificationOpened.listen((event) { + print("Notification clicked! Channel: ${event.channelId}, Root: ${event.rootId}"); +}); + +// 3. Register navigation handlers (automatically triggered by onNotificationOpened) +MattermostPushPlugin.instance.onNavigateToChannel = (String serverUrl, String channelId) { + // Navigate the app to the specific channel +}; + +MattermostPushPlugin.instance.onNavigateToThread = (String serverUrl, String rootId) { + // Navigate the app to the specific CRT thread +}; + +// 4. Triggered when the device token is registered/refreshed +MattermostPushPlugin.instance.onDeviceTokenReady = (String deviceToken) { + // e.g. "android_rn-v2:YOUR_FCM_TOKEN" + // Send this token to the Mattermost server for token registration +}; +``` + +### 3. Credential & Signing Key Storing + +Securely write server-specific secrets to native persistent storage. These are required by the native service to decrypt and verify the authenticity of push messages. + +```dart +// Save authenticating token for HTTP ACK requests +await MattermostPushPlugin.instance.setAuthToken( + "https://mattermost.example.com", + "YOUR_USER_AUTH_TOKEN", + identifier: "user_session_id", // optional +); + +// Save public signing key for verification +await MattermostPushPlugin.instance.setSigningKey( + "https://mattermost.example.com", + "YOUR_SERVER_PUBLIC_SIGNING_KEY", +); + +// Clear token on logout +await MattermostPushPlugin.instance.clearAuthToken("https://mattermost.example.com"); + +// Fetch the formatted device token +String? token = await MattermostPushPlugin.instance.getDeviceToken(); +``` + +--- + +## Host App Integration & Responsibilities + +The host application (`apps/mobile`) acts as the consumer of the plugin and is responsible for: + +1. **Firebase Configuration**: Include the `google-services.json` in `android/app/` and initialize Firebase in the Dart main block. +2. **Authentication Flow**: Call `setAuthToken` and `setSigningKey` on successful Mattermost login, and `clearAuthToken` on logout. +3. **App Navigation**: Implement `onNavigateToChannel` and `onNavigateToThread` callbacks to route users inside the Flutter UI. +4. **FCM Token Registration**: Send the formatted token received in `onDeviceTokenReady` to the Mattermost server. + +### Firebase Messaging Manifest Collision Guard +This plugin implements a custom Android FCM service (`MattermostFirebaseMessagingService`) that consumes incoming FCM payloads. To prevent manifest merge collisions with the standard Flutter `firebase_messaging` library, the plugin's `AndroidManifest.xml` disables the generic Flutter Firebase service via `tools:node="remove"`. +Ensure that the host app does not redeclare duplicate FCM services unless explicitly configured to do so. + +--- + +## Verification & Manual Smoke Testing Checklist + +Since full end-to-end FCM flows cannot be automated in headless test runners, verify functionality manually using the following checklist: + +- [ ] **FCM Payload Receipt**: Verify that sending an FCM notification payload targeting the host application successfully wakes up `MattermostFirebaseMessagingService`. +- [ ] **Signature Verification**: Ensure that a valid push payload signed by the Mattermost server's private key compiles and passes the native JJWT verification using the stored signing key. +- [ ] **Notification Display**: Verify the system notification builds with the correct title, message, avatar (if supplied), and CRT threading hierarchy. +- [ ] **ACK Delivery**: Verify the plugin sends a HTTP `POST` receipt delivery ACK back to the Mattermost server and logs a `200 OK` or `201 Created` response. +- [ ] **Notification Tap & Route**: Tap the system notification and verify the host app launches/resumes, triggers the `onNotificationOpened` stream, and executes the designated navigation callback. +- [ ] **Inline Reply Action**: Click "Reply" directly on the system notification. Type a reply, press send, and verify the native broadcast receiver intercepts the text, writes it to the local Room database, and sends it via HTTP to the Mattermost API. +- [ ] **Notification Dismiss (Clear)**: Swipe away or dismiss a notification and verify the `NotificationDismissService` is triggered, clearing the corresponding notification records natively. +- [ ] **Token Storage & Generation**: Ensure the generated token has the correct `android_rn-v2:` prefix and is saved securely in the device's native database/shared preferences. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a5744c1 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..161bdcd --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.cxx diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 0000000..b434e9b --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1,95 @@ +group = "com.tokilabs.mattermost_push_plugin" +version = "1.0-SNAPSHOT" + +buildscript { + val kotlinVersion = "2.2.20" + repositories { + google() + mavenCentral() + } + + dependencies { + classpath("com.android.tools.build:gradle:8.11.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin-api:$kotlinVersion") + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +plugins { + id("com.android.library") + id("kotlin-android") + id("kotlin-kapt") +} + +android { + namespace = "com.tokilabs.mattermost_push_plugin" + + compileSdk = 36 + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17.toString() + } + + sourceSets { + getByName("main") { + java.srcDirs("src/main/kotlin", "src/main/java") + } + getByName("test") { + java.srcDirs("src/test/kotlin") + } + } + + defaultConfig { + minSdk = 24 + } + + testOptions { + unitTests { + isIncludeAndroidResources = true + all { + it.useJUnitPlatform() + + it.outputs.upToDateWhen { false } + + it.testLogging { + events("passed", "skipped", "failed", "standardOut", "standardError") + showStandardStreams = true + } + } + } + } +} + +dependencies { + implementation(platform("com.google.firebase:firebase-bom:33.7.0")) + implementation("com.google.firebase:firebase-messaging") + + implementation("io.jsonwebtoken:jjwt-api:0.12.5") + runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.5") + runtimeOnly("io.jsonwebtoken:jjwt-orgjson:0.12.5") { + exclude(group = "org.json", module = "json") + } + + implementation("com.squareup.okhttp3:okhttp:4.12.0") + + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3") + + implementation("androidx.room:room-runtime:2.7.0-rc01") + implementation("androidx.room:room-ktx:2.7.0-rc01") + kapt("androidx.room:room-compiler:2.7.0-rc01") + + testImplementation("org.jetbrains.kotlin:kotlin-test") + testImplementation("org.mockito:mockito-core:5.0.0") +} diff --git a/android/settings.gradle b/android/settings.gradle new file mode 100644 index 0000000..91677d6 --- /dev/null +++ b/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'mattermost_push_plugin' diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts new file mode 100644 index 0000000..91677d6 --- /dev/null +++ b/android/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = 'mattermost_push_plugin' diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..346e129 --- /dev/null +++ b/android/src/main/AndroidManifest.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/src/main/java/com/tokilabs/mattermost_push_plugin/NotificationDismissService.java b/android/src/main/java/com/tokilabs/mattermost_push_plugin/NotificationDismissService.java new file mode 100644 index 0000000..b787ceb --- /dev/null +++ b/android/src/main/java/com/tokilabs/mattermost_push_plugin/NotificationDismissService.java @@ -0,0 +1,33 @@ +package com.tokilabs.mattermost_push_plugin; + +import android.app.IntentService; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import com.tokilabs.mattermost_push_plugin.helpers.NotificationHelper; + +@SuppressWarnings("deprecation") +public class NotificationDismissService extends IntentService { + + private static final String TAG = "NotifDismissService"; + private static final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification"; + + public NotificationDismissService() { + super("notificationDismissService"); + } + + @Override + protected void onHandleIntent(Intent intent) { + if (intent == null) return; + + final Context context = getApplicationContext(); + final Bundle bundle = intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME); + + if (bundle != null) { + NotificationHelper.INSTANCE.dismissNotification(context, bundle); + Log.i(TAG, "Dismiss notification id=" + NotificationHelper.INSTANCE.getNotificationId(bundle)); + } + } +} diff --git a/android/src/main/java/com/tokilabs/mattermost_push_plugin/NotificationReplyBroadcastReceiver.java b/android/src/main/java/com/tokilabs/mattermost_push_plugin/NotificationReplyBroadcastReceiver.java new file mode 100644 index 0000000..22d5904 --- /dev/null +++ b/android/src/main/java/com/tokilabs/mattermost_push_plugin/NotificationReplyBroadcastReceiver.java @@ -0,0 +1,140 @@ +package com.tokilabs.mattermost_push_plugin; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.app.RemoteInput; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; + +import androidx.core.app.NotificationCompat; +import androidx.core.app.Person; + +import com.tokilabs.mattermost_push_plugin.helpers.CustomPushNotificationHelper; +import com.tokilabs.mattermost_push_plugin.helpers.Network; + +import org.json.JSONException; +import org.json.JSONObject; + +public class NotificationReplyBroadcastReceiver extends BroadcastReceiver { + private static final String TAG = "NotifReplyReceiver"; + + private Context mContext; + private Bundle bundle; + private NotificationManager notificationManager; + + @Override + public void onReceive(Context context, Intent intent) { + try { + final CharSequence message = getReplyMessage(intent); + if (message == null) return; + + mContext = context; + bundle = intent.getBundleExtra(CustomPushNotificationHelper.NOTIFICATION); + notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + final int notificationId = intent.getIntExtra(CustomPushNotificationHelper.NOTIFICATION_ID, -1); + final String serverUrl = bundle.getString("server_url"); + + if (serverUrl != null) { + replyToMessage(serverUrl, notificationId, message); + } else { + onReplyFailed(notificationId); + } + } catch (Exception e) { + Log.e(TAG, "onReceive error: " + e.getMessage()); + e.printStackTrace(); + } + } + + protected void replyToMessage(final String serverUrl, final int notificationId, + final CharSequence message) { + final String channelId = bundle.getString("channel_id"); + final String postId = bundle.getString("post_id"); + String rootId = bundle.getString("root_id"); + if (android.text.TextUtils.isEmpty(rootId)) rootId = postId; + + try { + JSONObject body = new JSONObject(); + body.put("channel_id", channelId); + body.put("message", message.toString()); + body.put("root_id", rootId); + + Network.INSTANCE.post(serverUrl, "/api/v4/posts?set_online=false", body, + null, + json -> { + if (json != null) { + try { + if (json.has("status_code")) { + int statusCode = json.getInt("status_code"); + if (statusCode < 200 || statusCode >= 300) { + Log.i(TAG, "Reply FAILED status=" + statusCode); + onReplyFailed(notificationId); + return null; + } + } + onReplySuccess(notificationId, message); + Log.i(TAG, "Reply SUCCESS"); + } catch (JSONException e) { + e.printStackTrace(); + onReplyFailed(notificationId); + } + } else { + Log.i(TAG, "Reply FAILED: null response"); + onReplyFailed(notificationId); + } + return null; + }, + e -> { + Log.i(TAG, "Reply FAILED exception: " + e.getMessage()); + onReplyFailed(notificationId); + return null; + } + ); + } catch (JSONException e) { + Log.e(TAG, "JSON error: " + e.getMessage()); + onReplyFailed(notificationId); + } + } + + protected void onReplyFailed(int notificationId) { + recreateNotification(notificationId, "Message failed to send."); + } + + protected void onReplySuccess(int notificationId, final CharSequence message) { + recreateNotification(notificationId, message); + } + + private void recreateNotification(int notificationId, final CharSequence message) { + Intent openIntent = LaunchIntentHelper.INSTANCE.forBundle(mContext, bundle); + + PendingIntent pendingIntent = PendingIntent.getActivity( + mContext, notificationId, openIntent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); + + NotificationCompat.Builder builder = + CustomPushNotificationHelper.createNotificationBuilder(mContext, pendingIntent, bundle, false); + + Notification notification = builder.build(); + NotificationCompat.MessagingStyle messagingStyle = + NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(notification); + + if (messagingStyle != null) { + messagingStyle.addMessage(message, System.currentTimeMillis(), (Person) null); + notification = builder.setStyle(messagingStyle).build(); + } + + notificationManager.notify(notificationId, notification); + } + + private CharSequence getReplyMessage(Intent intent) { + Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); + if (remoteInput != null) { + return remoteInput.getCharSequence(CustomPushNotificationHelper.KEY_TEXT_REPLY); + } + return null; + } +} diff --git a/android/src/main/java/com/tokilabs/mattermost_push_plugin/ReceiptDelivery.java b/android/src/main/java/com/tokilabs/mattermost_push_plugin/ReceiptDelivery.java new file mode 100644 index 0000000..9a0c7c0 --- /dev/null +++ b/android/src/main/java/com/tokilabs/mattermost_push_plugin/ReceiptDelivery.java @@ -0,0 +1,60 @@ +package com.tokilabs.mattermost_push_plugin; + +import android.os.Bundle; +import android.util.Log; + +import com.tokilabs.mattermost_push_plugin.helpers.Network; + +import org.json.JSONObject; + +import java.util.Objects; + +import okhttp3.Response; + +public class ReceiptDelivery { + private static final String TAG = "ReceiptDelivery"; + private static final String[] ACK_KEYS = { + "post_id", "root_id", "category", "message", "team_id", + "channel_id", "channel_name", "type", "sender_id", "sender_name", "version" + }; + + public static Bundle send(final String ackId, final String serverUrl, + final String postId, final String type, final boolean isIdLoaded) { + Log.i(TAG, String.format("Send ACK=%s TYPE=%s to URL=%s ID-LOADED=%s", ackId, type, serverUrl, isIdLoaded)); + + try { + JSONObject body = new JSONObject(); + body.put("id", ackId); + body.put("received_at", System.currentTimeMillis()); + body.put("platform", "android"); + body.put("type", type); + body.put("post_id", postId); + body.put("is_id_loaded", isIdLoaded); + + try (Response response = Network.INSTANCE.postSync(serverUrl, "api/v4/notifications/ack", body, null)) { + String responseBody = Objects.requireNonNull(response.body()).string(); + JSONObject jsonResponse = new JSONObject(responseBody); + return parseAckResponse(jsonResponse); + } + } catch (Exception e) { + Log.e(TAG, "Send receipt delivery failed: " + e.getMessage()); + e.printStackTrace(); + return null; + } + } + + public static Bundle parseAckResponse(JSONObject jsonResponse) { + try { + Bundle bundle = new Bundle(); + for (String key : ACK_KEYS) { + if (jsonResponse.has(key)) { + bundle.putString(key, jsonResponse.getString(key)); + } + } + return bundle; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/android/src/main/java/com/tokilabs/mattermost_push_plugin/helpers/CustomPushNotificationHelper.java b/android/src/main/java/com/tokilabs/mattermost_push_plugin/helpers/CustomPushNotificationHelper.java new file mode 100644 index 0000000..e782584 --- /dev/null +++ b/android/src/main/java/com/tokilabs/mattermost_push_plugin/helpers/CustomPushNotificationHelper.java @@ -0,0 +1,510 @@ +package com.tokilabs.mattermost_push_plugin.helpers; + +import android.annotation.SuppressLint; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.Rect; +import android.graphics.RectF; +import android.os.Build; +import android.os.Bundle; +import android.text.TextUtils; +import android.util.Base64; +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.core.app.NotificationCompat; +import androidx.core.app.NotificationManagerCompat; +import androidx.core.app.Person; +import androidx.core.app.RemoteInput; +import androidx.core.graphics.drawable.IconCompat; + +import com.tokilabs.mattermost_push_plugin.NotificationDismissService; +import com.tokilabs.mattermost_push_plugin.NotificationReplyBroadcastReceiver; +import com.tokilabs.mattermost_push_plugin.R; +import com.tokilabs.mattermost_push_plugin.helpers.db.MattermostDatabase; + +import java.io.IOException; +import java.security.KeyFactory; +import java.security.PublicKey; +import java.security.spec.X509EncodedKeySpec; +import java.util.Date; +import java.util.Objects; + +import io.jsonwebtoken.IncorrectClaimException; +import io.jsonwebtoken.JwtException; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.MissingClaimException; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class CustomPushNotificationHelper { + public static final String CHANNEL_HIGH_IMPORTANCE_ID = "channel_01"; + public static final String CHANNEL_MIN_IMPORTANCE_ID = "channel_02"; + public static final String KEY_TEXT_REPLY = "CAN_REPLY"; + public static final String NOTIFICATION_ID = "notificationId"; + public static final String NOTIFICATION = "notification"; + public static final String PUSH_TYPE_MESSAGE = "message"; + public static final String PUSH_TYPE_CLEAR = "clear"; + public static final String PUSH_TYPE_SESSION = "session"; + public static final String CATEGORY_CAN_REPLY = "CAN_REPLY"; + public static final String SIGNING_PREFS = "mattermost_signing"; + + private static final String TAG = "PushNotifHelper"; + + private static NotificationChannel mHighImportanceChannel; + private static NotificationChannel mMinImportanceChannel; + + private static final OkHttpClient client = new OkHttpClient(); + private static final BitmapCache bitmapCache = new BitmapCache(); + + public static NotificationCompat.Builder createNotificationBuilder( + Context context, PendingIntent intent, Bundle bundle, boolean createSummary) { + + final NotificationCompat.Builder notification = + new NotificationCompat.Builder(context, CHANNEL_HIGH_IMPORTANCE_ID); + + String postId = bundle.getString("post_id"); + String rootId = bundle.getString("root_id"); + String channelId = bundle.getString("channel_id"); + int notificationId = postId != null ? postId.hashCode() : NotificationHelper.MESSAGE_NOTIFICATION_ID; + + boolean isCrtEnabled = bundle.containsKey("is_crt_enabled") && + Objects.equals(bundle.getString("is_crt_enabled"), "true"); + String groupId = isCrtEnabled && !TextUtils.isEmpty(rootId) ? rootId : channelId; + + addNotificationExtras(notification, bundle); + setNotificationIcons(context, notification, bundle); + setNotificationMessagingStyle(context, notification, bundle); + setNotificationGroup(notification, groupId, createSummary); + setNotificationBadgeType(notification); + setNotificationChannel(context, notification); + setNotificationDeleteIntent(context, notification, bundle, notificationId); + addNotificationReplyAction(context, notification, bundle, notificationId); + + notification + .setContentIntent(intent) + .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) + .setPriority(Notification.PRIORITY_HIGH) + .setCategory(Notification.CATEGORY_MESSAGE) + .setAutoCancel(true); + + return notification; + } + + public static void createNotificationChannels(Context context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; + + final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); + + if (mHighImportanceChannel == null) { + mHighImportanceChannel = new NotificationChannel( + CHANNEL_HIGH_IMPORTANCE_ID, "High Importance", NotificationManager.IMPORTANCE_HIGH); + mHighImportanceChannel.setShowBadge(true); + notificationManager.createNotificationChannel(mHighImportanceChannel); + } + + if (mMinImportanceChannel == null) { + mMinImportanceChannel = new NotificationChannel( + CHANNEL_MIN_IMPORTANCE_ID, "Min Importance", NotificationManager.IMPORTANCE_MIN); + mMinImportanceChannel.setShowBadge(true); + notificationManager.createNotificationChannel(mMinImportanceChannel); + } + } + + public static boolean verifySignature(final Context context, String signature, + String serverUrl, String ackId) { + if (signature == null) { + Log.i(TAG, "No signature in the notification (backward compat)"); + return true; + } + + if (serverUrl == null) { + Log.i(TAG, "No server_url available, skipping signature check"); + return true; + } + + DatabaseHelper dbHelper = DatabaseHelper.Companion.getInstance(); + if (dbHelper == null) { + Log.i(TAG, "Cannot access the database, skipping signature check"); + return true; + } + + MattermostDatabase db = dbHelper.getDatabaseForServer(context, serverUrl); + if (db == null) { + Log.i(TAG, "Cannot access the server database, skipping signature check"); + return true; + } + + if ("NO_SIGNATURE".equals(signature)) { + String version = db.queryConfigServerVersion(); + if (version == null) { + Log.i(TAG, "No server version"); + return false; + } + if (!version.matches("[0-9]+(\\.[0-9]+)*")) { + Log.i(TAG, "Invalid server version"); + return false; + } + + String[] parts = version.split("\\."); + int major = parts.length > 0 ? Integer.parseInt(parts[0]) : 0; + int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0; + int patch = parts.length > 2 ? Integer.parseInt(parts[2]) : 0; + + int[][] targets = {{9,8,0},{9,7,3},{9,6,3},{9,5,5},{8,1,14}}; + boolean rejected = false; + for (int i = 0; i < targets.length; i++) { + boolean first = i == 0; + int majorTarget = targets[i][0]; + int minorTarget = targets[i][1]; + int patchTarget = targets[i][2]; + + if (major > majorTarget) { rejected = first; break; } + if (major < majorTarget) { continue; } + if (minor > minorTarget) { rejected = first; break; } + if (minor < minorTarget) { continue; } + if (patch >= patchTarget) { rejected = true; break; } + return true; + } + + if (rejected) { + Log.i(TAG, "Server version should send signature"); + return false; + } + return true; + } + + String signingKey = db.queryConfigSigningKey(); + if (signingKey == null) { + signingKey = context.getSharedPreferences(SIGNING_PREFS, Context.MODE_PRIVATE) + .getString("signing_key_" + serverUrl, null); + } + if (signingKey == null) { + Log.i(TAG, "No signing key, skipping signature check"); + return true; + } + + try { + byte[] encoded = Base64.decode(signingKey, 0); + KeyFactory kf = KeyFactory.getInstance("EC"); + PublicKey pubKey = kf.generatePublic(new X509EncodedKeySpec(encoded)); + + String storedDeviceToken = dbHelper.getDeviceToken(); + if (storedDeviceToken == null) { + Log.i(TAG, "No device token stored"); + return false; + } + String[] tokenParts = storedDeviceToken.split(":", 2); + if (tokenParts.length != 2) { + Log.i(TAG, "Wrong stored device token format"); + return false; + } + String deviceToken = tokenParts[1]; + if (deviceToken.isEmpty()) { + Log.i(TAG, "Empty stored device token"); + return false; + } + + Jwts.parser() + .require("ack_id", ackId) + .require("device_id", deviceToken) + .verifyWith((PublicKey) pubKey) + .build() + .parseSignedClaims(signature); + + } catch (MissingClaimException e) { + Log.i(TAG, "Missing claim: " + e.getMessage()); + return false; + } catch (IncorrectClaimException e) { + Log.i(TAG, "Incorrect claim: " + e.getMessage()); + return false; + } catch (JwtException e) { + Log.i(TAG, "Cannot verify JWT: " + e.getMessage()); + return false; + } catch (Exception e) { + Log.i(TAG, "Exception while parsing JWT: " + e.getMessage()); + return false; + } + + return true; + } + + private static void addNotificationExtras(NotificationCompat.Builder notification, Bundle bundle) { + Bundle userInfoBundle = bundle.getBundle("userInfo"); + if (userInfoBundle == null) userInfoBundle = new Bundle(); + + putIfNotNull(userInfoBundle, "channel_id", bundle.getString("channel_id")); + putIfNotNull(userInfoBundle, "post_id", bundle.getString("post_id")); + putIfNotNull(userInfoBundle, "root_id", bundle.getString("root_id")); + putIfNotNull(userInfoBundle, "is_crt_enabled", bundle.getString("is_crt_enabled")); + putIfNotNull(userInfoBundle, "server_url", bundle.getString("server_url")); + + notification.addExtras(userInfoBundle); + } + + @SuppressLint("UnspecifiedImmutableFlag") + private static void addNotificationReplyAction(Context context, NotificationCompat.Builder notification, + Bundle bundle, int notificationId) { + String postId = bundle.getString("post_id"); + String serverUrl = bundle.getString("server_url"); + boolean canReply = bundle.containsKey("category") && + Objects.equals(bundle.getString("category"), CATEGORY_CAN_REPLY); + + if (TextUtils.isEmpty(postId) || serverUrl == null || !canReply) return; + + Intent replyIntent = new Intent(context, NotificationReplyBroadcastReceiver.class); + replyIntent.setAction(KEY_TEXT_REPLY); + replyIntent.putExtra(NOTIFICATION_ID, notificationId); + replyIntent.putExtra(NOTIFICATION, bundle); + + PendingIntent replyPendingIntent; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + replyPendingIntent = PendingIntent.getBroadcast(context, notificationId, replyIntent, + PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + } else { + replyPendingIntent = PendingIntent.getBroadcast(context, notificationId, replyIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + } + + RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel("Reply").build(); + + NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( + R.drawable.ic_notif_action_reply, "Reply", replyPendingIntent) + .addRemoteInput(remoteInput) + .setAllowGeneratedReplies(true) + .build(); + + notification.setShowWhen(true).addAction(replyAction); + } + + private static void setNotificationMessagingStyle(Context context, + NotificationCompat.Builder notification, Bundle bundle) { + notification.setStyle(getMessagingStyle(context, bundle)); + } + + private static NotificationCompat.MessagingStyle getMessagingStyle(Context context, Bundle bundle) { + final String serverUrl = bundle.getString("server_url"); + final String type = bundle.getString("type"); + String urlOverride = bundle.getString("override_icon_url"); + + Person.Builder sender = new Person.Builder().setKey("me").setName("Me"); + + if (serverUrl != null && type != null && !type.equals(PUSH_TYPE_SESSION)) { + try { + Bitmap avatar = userAvatar(context, serverUrl, "me", urlOverride); + if (avatar != null) sender.setIcon(IconCompat.createWithBitmap(avatar)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(sender.build()); + String conversationTitle = getConversationTitle(bundle); + setMessagingStyleConversationTitle(messagingStyle, conversationTitle, bundle); + addMessagingStyleMessages(context, messagingStyle, conversationTitle, bundle); + + return messagingStyle; + } + + private static void addMessagingStyleMessages(Context context, + NotificationCompat.MessagingStyle messagingStyle, + String conversationTitle, Bundle bundle) { + String message = bundle.getString("message", bundle.getString("body")); + String senderId = bundle.getString("sender_id"); + final String serverUrl = bundle.getString("server_url"); + final String type = bundle.getString("type"); + String urlOverride = bundle.getString("override_icon_url"); + + if (senderId == null) senderId = "sender_id"; + String senderName = getSenderName(bundle); + + if (conversationTitle == null || !TextUtils.isEmpty(senderName.trim())) { + message = removeSenderNameFromMessage(message, senderName); + } + + long timestamp = new Date().getTime(); + Person.Builder sender = new Person.Builder().setKey(senderId).setName(senderName); + + if (serverUrl != null && type != null && !type.equals(PUSH_TYPE_SESSION)) { + try { + Bitmap avatar = userAvatar(context, serverUrl, senderId, urlOverride); + if (avatar != null) sender.setIcon(IconCompat.createWithBitmap(avatar)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + messagingStyle.addMessage(message, timestamp, sender.build()); + } + + private static void setNotificationIcons(Context context, NotificationCompat.Builder notification, Bundle bundle) { + String channelName = getConversationTitle(bundle); + String senderName = bundle.getString("sender_name"); + String serverUrl = bundle.getString("server_url"); + String urlOverride = bundle.getString("override_icon_url"); + + notification.setSmallIcon(R.mipmap.ic_notification); + + if (serverUrl != null && channelName.equals(senderName)) { + try { + String senderId = bundle.getString("sender_id"); + Bitmap avatar = userAvatar(context, serverUrl, senderId, urlOverride); + if (avatar != null) notification.setLargeIcon(avatar); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private static void setNotificationGroup(NotificationCompat.Builder notification, + String channelId, boolean setAsSummary) { + notification.setGroup(channelId); + if (setAsSummary) notification.setGroupSummary(true); + } + + private static void setNotificationBadgeType(NotificationCompat.Builder notification) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + notification.setBadgeIconType(NotificationCompat.BADGE_ICON_LARGE); + } + } + + private static void setNotificationChannel(Context context, NotificationCompat.Builder notification) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return; + if (mHighImportanceChannel == null) createNotificationChannels(context); + notification.setChannelId(mHighImportanceChannel.getId()); + } + + @SuppressLint("UnspecifiedImmutableFlag") + private static void setNotificationDeleteIntent(Context context, NotificationCompat.Builder notification, + Bundle bundle, int notificationId) { + final String PUSH_NOTIFICATION_EXTRA_NAME = "pushNotification"; + Intent delIntent = new Intent(context, NotificationDismissService.class); + delIntent.putExtra(NOTIFICATION_ID, notificationId); + delIntent.putExtra(PUSH_NOTIFICATION_EXTRA_NAME, bundle); + PendingIntent deleteIntent = PendingIntent.getService(context, + (int) System.currentTimeMillis(), delIntent, + PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); + notification.setDeleteIntent(deleteIntent); + } + + private static void setMessagingStyleConversationTitle( + NotificationCompat.MessagingStyle messagingStyle, String conversationTitle, Bundle bundle) { + String channelName = getConversationTitle(bundle); + String senderName = bundle.getString("sender_name"); + if (TextUtils.isEmpty(senderName)) senderName = getSenderName(bundle); + + if (conversationTitle != null && !channelName.equals(senderName)) { + messagingStyle.setConversationTitle(conversationTitle); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + messagingStyle.setGroupConversation(true); + } + } + } + + private static String getConversationTitle(Bundle bundle) { + String title = bundle.getString("channel_name"); + if (TextUtils.isEmpty(title)) title = bundle.getString("sender_name"); + if (TextUtils.isEmpty(title)) title = bundle.getString("title", ""); + return title; + } + + private static String getSenderName(Bundle bundle) { + String senderName = bundle.getString("sender_name"); + if (senderName != null) return senderName; + + String channelName = bundle.getString("channel_name"); + if (channelName != null && channelName.startsWith("@")) return channelName; + + String message = bundle.getString("message"); + if (message != null) { + String name = message.split(":")[0]; + if (!name.equals(message)) return name; + } + + return getConversationTitle(bundle); + } + + private static String removeSenderNameFromMessage(String message, String senderName) { + int index = message.indexOf(senderName); + if (index == 0) message = message.substring(senderName.length()); + return message.replaceFirst(": ", "").trim(); + } + + private static Bitmap getCircleBitmap(Bitmap bitmap) { + final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); + final Canvas canvas = new Canvas(output); + final Paint paint = new Paint(); + final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); + final RectF rectF = new RectF(rect); + + paint.setAntiAlias(true); + canvas.drawARGB(0, 0, 0, 0); + paint.setColor(Color.RED); + canvas.drawOval(rectF, paint); + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); + canvas.drawBitmap(bitmap, rect, rect, paint); + bitmap.recycle(); + + return output; + } + + private static Bitmap userAvatar(final Context context, @NonNull final String serverUrl, + final String userId, final String urlOverride) throws IOException { + try { + Response response; + Double lastUpdateAt = 0.0; + + if (!TextUtils.isEmpty(urlOverride)) { + Request request = new Request.Builder().url(urlOverride).build(); + response = client.newCall(request).execute(); + } else { + DatabaseHelper dbHelper = DatabaseHelper.Companion.getInstance(); + if (dbHelper != null) { + MattermostDatabase db = dbHelper.getDatabaseForServer(context, serverUrl); + if (db != null) { + lastUpdateAt = db.getLastPictureUpdate(userId); + if (lastUpdateAt == null) lastUpdateAt = 0.0; + } + } + + Bitmap cached = bitmapCache.bitmap(userId, lastUpdateAt, serverUrl); + if (cached != null) { + return getCircleBitmap(cached.copy(cached.getConfig(), false)); + } + + bitmapCache.removeBitmap(userId, serverUrl); + response = Network.INSTANCE.getSync(serverUrl, "api/v4/users/" + userId + "/image", null); + } + + if (response.code() == 200 && response.body() != null) { + byte[] bytes = response.body().bytes(); + Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); + if (TextUtils.isEmpty(urlOverride) && !TextUtils.isEmpty(userId)) { + bitmapCache.insertBitmap(bitmap.copy(bitmap.getConfig(), false), userId, lastUpdateAt, serverUrl); + } + return getCircleBitmap(bitmap); + } + + return null; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + private static void putIfNotNull(Bundle bundle, String key, String value) { + if (value != null) bundle.putString(key, value); + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/AppLifecycleTracker.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/AppLifecycleTracker.kt new file mode 100644 index 0000000..3c4e958 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/AppLifecycleTracker.kt @@ -0,0 +1,31 @@ +package com.tokilabs.mattermost_push_plugin + +import android.app.Activity +import android.app.Application +import android.os.Bundle + +object AppLifecycleTracker : Application.ActivityLifecycleCallbacks { + var isInForeground = false + private set + + private var activeActivities = 0 + + override fun onActivityStarted(activity: Activity) { + activeActivities++ + isInForeground = true + } + + override fun onActivityStopped(activity: Activity) { + activeActivities-- + if (activeActivities <= 0) { + activeActivities = 0 + isInForeground = false + } + } + + override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {} + override fun onActivityResumed(activity: Activity) {} + override fun onActivityPaused(activity: Activity) {} + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {} + override fun onActivityDestroyed(activity: Activity) {} +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/LaunchIntentHelper.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/LaunchIntentHelper.kt new file mode 100644 index 0000000..d8fec6b --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/LaunchIntentHelper.kt @@ -0,0 +1,15 @@ +package com.tokilabs.mattermost_push_plugin + +import android.content.Context +import android.content.Intent +import android.os.Bundle + +object LaunchIntentHelper { + fun forBundle(context: Context, bundle: Bundle): Intent { + val base = context.packageManager.getLaunchIntentForPackage(context.packageName) + ?: Intent(Intent.ACTION_MAIN).apply { setPackage(context.packageName) } + base.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP + base.putExtras(bundle) + return base + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/MattermostFirebaseMessagingService.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/MattermostFirebaseMessagingService.kt new file mode 100644 index 0000000..0561002 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/MattermostFirebaseMessagingService.kt @@ -0,0 +1,219 @@ +package com.tokilabs.mattermost_push_plugin + +import android.app.PendingIntent +import android.os.Bundle +import android.os.Handler +import android.os.Looper +import android.util.Log +import com.google.firebase.messaging.FirebaseMessagingService +import com.google.firebase.messaging.RemoteMessage +import com.tokilabs.mattermost_push_plugin.helpers.CustomPushNotificationHelper +import com.tokilabs.mattermost_push_plugin.helpers.DatabaseHelper +import com.tokilabs.mattermost_push_plugin.helpers.NotificationHelper +import com.tokilabs.mattermost_push_plugin.helpers.PushNotificationDataHelper +import io.flutter.embedding.engine.FlutterEngineCache +import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch + +class MattermostFirebaseMessagingService : FirebaseMessagingService() { + + private val dataHelper by lazy { PushNotificationDataHelper(this) } + + companion object { + private const val TAG = "MattermostFCM" + } + + override fun onCreate() { + super.onCreate() + // Service can be started before plugin attaches; init DB defensively. + DatabaseHelper.init(applicationContext) + } + + override fun onNewToken(token: String) { + super.onNewToken(token) + Log.i(TAG, "New FCM token: $token") + Handler(Looper.getMainLooper()).post { + PushNotificationEvents.eventSink?.success( + mapOf("type" to "token_refresh", "token" to token), + ) + } + } + + @OptIn(DelicateCoroutinesApi::class) + override fun onMessageReceived(remoteMessage: RemoteMessage) { + super.onMessageReceived(remoteMessage) + Log.i(TAG, ">>> onMessageReceived ENTER, dataSize=${remoteMessage.data.size}") + + try { + val data = remoteMessage.data + if (data.isEmpty()) return + + val bundle = Bundle().apply { + data.forEach { (k, v) -> putString(k, v) } + } + + val type = bundle.getString("type") + val ackId = bundle.getString("ack_id") + val postId = bundle.getString("post_id") + val channelId = bundle.getString("channel_id") + val signature = bundle.getString("signature") + val isIdLoaded = bundle.getString("id_loaded") == "true" + val notificationId = try { + NotificationHelper.getNotificationId(bundle) + } catch (e: Exception) { + Log.e(TAG, "getNotificationId failed: ${e.message}") + System.currentTimeMillis().toInt() + } + + var serverUrl = bundle.getString("server_url") + if (serverUrl == null) { + try { + val dbHelper = DatabaseHelper.getInstance() + val serverId = bundle.getString("server_id") + if (serverId != null && dbHelper != null) { + serverUrl = dbHelper.getServerUrlForIdentifier(serverId) + } + if (serverUrl == null) { + serverUrl = dbHelper?.onlyServerUrl + } + } catch (e: Exception) { + Log.e(TAG, "DB lookup failed: ${e.message}") + } + if (serverUrl != null) { + bundle.putString("server_url", serverUrl) + } + } + + Log.i(TAG, "onMessageReceived type=$type channelId=$channelId ackId=$ackId serverUrl=$serverUrl") + + GlobalScope.launch { + try { + handlePushNotificationInCoroutine( + serverUrl, type, channelId, ackId, + isIdLoaded, notificationId, postId, signature, bundle, + ) + } catch (e: Exception) { + Log.e(TAG, "Error handling notification: ${e.message}") + e.printStackTrace() + } + } + } catch (e: Exception) { + Log.e(TAG, ">>> onMessageReceived CRASH: ${e.message}") + e.printStackTrace() + } + } + + private suspend fun handlePushNotificationInCoroutine( + serverUrl: String?, + type: String?, + channelId: String?, + ackId: String?, + isIdLoaded: Boolean, + notificationId: Int, + postId: String?, + signature: String?, + bundle: Bundle, + ) { + val currentBundle = bundle + + if (ackId != null && serverUrl != null) { + val response = ReceiptDelivery.send(ackId, serverUrl, postId, type, isIdLoaded) + if (isIdLoaded && response != null) { + if (!currentBundle.containsKey("server_url")) { + response.putString("server_url", serverUrl) + } + currentBundle.putAll(response) + } + } + + if (!CustomPushNotificationHelper.verifySignature(this, signature, serverUrl, ackId)) { + Log.i(TAG, "Notification skipped: signature verification failed") + return + } + + finishProcessingNotification(serverUrl, type, channelId, notificationId, currentBundle) + } + + private suspend fun finishProcessingNotification( + serverUrl: String?, + type: String?, + channelId: String?, + notificationId: Int, + bundle: Bundle, + ) { + val currentBundle = bundle + val isFlutterRunning = isFlutterEngineRunning() + + when (type) { + CustomPushNotificationHelper.PUSH_TYPE_MESSAGE, + CustomPushNotificationHelper.PUSH_TYPE_SESSION, + -> { + if (!isFlutterRunning || !isAppInForeground()) { + var createSummary = type == CustomPushNotificationHelper.PUSH_TYPE_MESSAGE + + if (type == CustomPushNotificationHelper.PUSH_TYPE_MESSAGE && channelId != null) { + serverUrl?.let { + val notificationResult = dataHelper.fetchAndStoreDataForPushNotification(currentBundle, isFlutterRunning) + notificationResult?.let { result -> + currentBundle.putBundle("data", result) + } + } + createSummary = NotificationHelper.addNotificationToPreferences(this, notificationId, currentBundle) + } + + buildAndPostNotification(notificationId, createSummary, currentBundle) + } + } + CustomPushNotificationHelper.PUSH_TYPE_CLEAR -> + NotificationHelper.clearChannelOrThreadNotifications(this, currentBundle) + } + + if (isFlutterRunning) { + notifyReceivedToFlutter(currentBundle) + } + } + + private fun notifyReceivedToFlutter(bundle: Bundle) { + val data = bundleToMap(bundle) + Log.i(TAG, "Sending notification event to Flutter: type=${data["type"]}") + PushNotificationEvents.send(data) + } + + private fun buildAndPostNotification(notificationId: Int, createSummary: Boolean, bundle: Bundle) { + val intent = LaunchIntentHelper.forBundle(this, bundle) + val pendingIntent = PendingIntent.getActivity( + this, notificationId, intent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, + ) + + val notification = CustomPushNotificationHelper.createNotificationBuilder(this, pendingIntent, bundle, false).build() + + if (createSummary) { + val summary = CustomPushNotificationHelper.createNotificationBuilder(this, pendingIntent, bundle, true).build() + NotificationHelper.postNotification(this, summary, notificationId + 1) + } + NotificationHelper.postNotification(this, notification, notificationId) + } + + private fun isFlutterEngineRunning(): Boolean { + if (PushNotificationEvents.isFlutterAttached) return true + return FlutterEngineCache.getInstance().contains(MattermostPushPlugin.FLUTTER_ENGINE_ID) + } + + private fun isAppInForeground(): Boolean { + return AppLifecycleTracker.isInForeground + } + + private fun bundleToMap(bundle: Bundle): Map { + val map = mutableMapOf() + for (key in bundle.keySet()) { + val value = bundle.get(key) + map[key] = when (value) { + is Bundle -> bundleToMap(value) + else -> value + } + } + return map + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/MattermostPushPlugin.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/MattermostPushPlugin.kt new file mode 100644 index 0000000..55c1936 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/MattermostPushPlugin.kt @@ -0,0 +1,191 @@ +package com.tokilabs.mattermost_push_plugin + +import android.app.Application +import android.content.Context +import android.content.Intent +import com.tokilabs.mattermost_push_plugin.helpers.CustomPushNotificationHelper +import com.tokilabs.mattermost_push_plugin.helpers.DatabaseHelper +import com.tokilabs.mattermost_push_plugin.helpers.Network +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.embedding.engine.plugins.activity.ActivityAware +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding +import io.flutter.plugin.common.EventChannel +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result +import io.flutter.plugin.common.PluginRegistry + +class MattermostPushPlugin : + FlutterPlugin, + ActivityAware, + EventChannel.StreamHandler, + MethodCallHandler { + + companion object { + const val CHANNEL_EVENTS = "com.tokilabs.mattermost/notifications" + const val CHANNEL_ACTIONS = "com.tokilabs.mattermost/notification_actions" + const val FLUTTER_ENGINE_ID = "main_engine" + const val SIGNING_PREFS = "mattermost_signing" + } + + private var methodChannel: MethodChannel? = null + private var eventChannel: EventChannel? = null + private var applicationContext: Context? = null + private var lifecycleApplication: Application? = null + private var activityBinding: ActivityPluginBinding? = null + + private val newIntentListener = PluginRegistry.NewIntentListener { intent -> + val payload = intentPayload(intent) + if (payload != null) { + PushNotificationEvents.send(payload) + } + false + } + + override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { + val context = binding.applicationContext + applicationContext = context + + DatabaseHelper.init(context) + CustomPushNotificationHelper.createNotificationChannels(context) + + registerLifecycleCallbacks(context) + + methodChannel = MethodChannel(binding.binaryMessenger, CHANNEL_ACTIONS).also { + it.setMethodCallHandler(this) + } + eventChannel = EventChannel(binding.binaryMessenger, CHANNEL_EVENTS).also { + it.setStreamHandler(this) + } + + PushNotificationEvents.isFlutterAttached = true + } + + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { + methodChannel?.setMethodCallHandler(null) + eventChannel?.setStreamHandler(null) + methodChannel = null + eventChannel = null + unregisterLifecycleCallbacks() + PushNotificationEvents.isFlutterAttached = false + PushNotificationEvents.setEventSink(null) + PushNotificationEvents.clearPending() + applicationContext = null + } + + private fun registerLifecycleCallbacks(context: Context) { + val application = context.applicationContext as? Application ?: context as? Application ?: return + if (lifecycleApplication === application) return + lifecycleApplication?.unregisterActivityLifecycleCallbacks(AppLifecycleTracker) + application.registerActivityLifecycleCallbacks(AppLifecycleTracker) + lifecycleApplication = application + } + + private fun unregisterLifecycleCallbacks() { + lifecycleApplication?.unregisterActivityLifecycleCallbacks(AppLifecycleTracker) + lifecycleApplication = null + } + + override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { + PushNotificationEvents.setEventSink(events) + } + + override fun onCancel(arguments: Any?) { + PushNotificationEvents.setEventSink(null) + } + + override fun onAttachedToActivity(binding: ActivityPluginBinding) { + activityBinding = binding + binding.addOnNewIntentListener(newIntentListener) + val payload = intentPayload(binding.activity.intent) + if (payload != null) { + PushNotificationEvents.send(payload) + } + } + + override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { + activityBinding = binding + binding.addOnNewIntentListener(newIntentListener) + } + + override fun onDetachedFromActivity() { + activityBinding?.removeOnNewIntentListener(newIntentListener) + activityBinding = null + } + + override fun onDetachedFromActivityForConfigChanges() { + activityBinding?.removeOnNewIntentListener(newIntentListener) + activityBinding = null + } + + internal fun intentPayload(intent: Intent?): Map? { + val extras = intent?.extras ?: return null + if (extras.isEmpty) return null + val data = mutableMapOf() + for (key in extras.keySet()) { + data[key] = extras.get(key) + } + if (data.isEmpty()) return null + return data + mapOf( + "type" to (data["type"] ?: "opened"), + "userInteraction" to true, + ) + } + + override fun onMethodCall(call: MethodCall, result: Result) { + val context = applicationContext + when (call.method) { + "saveDeviceToken" -> { + val token = call.argument("token") + if (token != null) { + DatabaseHelper.getInstance()?.saveDeviceToken(token) + result.success(null) + } else { + result.error("INVALID_ARG", "token is null", null) + } + } + "getDeviceToken" -> { + result.success(DatabaseHelper.getInstance()?.getDeviceToken()) + } + "setAuthToken" -> { + val serverUrl = call.argument("serverUrl") + val token = call.argument("token") + val identifier = call.argument("identifier") + if (serverUrl != null && token != null) { + Network.setToken(serverUrl, token) + DatabaseHelper.getInstance()?.saveServerUrl(serverUrl, identifier) + result.success(null) + } else { + result.error("INVALID_ARG", "serverUrl or token is null", null) + } + } + "setSigningKey" -> { + val serverUrl = call.argument("serverUrl") + val signingKey = call.argument("signingKey") + if (serverUrl != null && signingKey != null && context != null) { + context.getSharedPreferences(SIGNING_PREFS, Context.MODE_PRIVATE) + .edit() + .putString("signing_key_$serverUrl", signingKey) + .apply() + result.success(null) + } else { + result.error("INVALID_ARG", "serverUrl or signingKey is null", null) + } + } + "clearAuthToken" -> { + val serverUrl = call.argument("serverUrl") + if (serverUrl != null) { + Network.clearToken(serverUrl) + result.success(null) + } else { + result.error("INVALID_ARG", "serverUrl is null", null) + } + } + "getPlatformVersion" -> { + result.success("Android ${android.os.Build.VERSION.RELEASE}") + } + else -> result.notImplemented() + } + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/PushNotificationEvents.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/PushNotificationEvents.kt new file mode 100644 index 0000000..0585671 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/PushNotificationEvents.kt @@ -0,0 +1,53 @@ +package com.tokilabs.mattermost_push_plugin + +import android.os.Handler +import android.os.Looper +import io.flutter.plugin.common.EventChannel + +object PushNotificationEvents { + @Volatile + var isFlutterAttached: Boolean = false + + private val mainHandler = Handler(Looper.getMainLooper()) + private val pending = ArrayDeque>() + private val lock = Any() + + @Volatile + private var sink: EventChannel.EventSink? = null + + val eventSink: EventChannel.EventSink? + get() = sink + + fun setEventSink(newSink: EventChannel.EventSink?) { + val drain: List> + synchronized(lock) { + sink = newSink + if (newSink == null) { + return + } + drain = pending.toList() + pending.clear() + } + for (data in drain) { + mainHandler.post { newSink?.success(data) } + } + } + + fun send(data: Map) { + val current: EventChannel.EventSink? + synchronized(lock) { + current = sink + if (current == null) { + pending.addLast(data) + return + } + } + mainHandler.post { current?.success(data) } + } + + fun clearPending() { + synchronized(lock) { + pending.clear() + } + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/BitmapCache.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/BitmapCache.kt new file mode 100644 index 0000000..7dc5a05 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/BitmapCache.kt @@ -0,0 +1,24 @@ +package com.tokilabs.mattermost_push_plugin.helpers + +import android.graphics.Bitmap +import android.util.LruCache + +class BitmapCache { + private data class CacheKey(val userId: String, val serverUrl: String) + private data class CacheEntry(val bitmap: Bitmap, val lastUpdateAt: Double) + + private val cache = LruCache(20) + + fun bitmap(userId: String, lastUpdateAt: Double, serverUrl: String): Bitmap? { + val entry = cache.get(CacheKey(userId, serverUrl)) ?: return null + return if (entry.lastUpdateAt == lastUpdateAt) entry.bitmap else null + } + + fun insertBitmap(bitmap: Bitmap, userId: String, lastUpdateAt: Double, serverUrl: String) { + cache.put(CacheKey(userId, serverUrl), CacheEntry(bitmap, lastUpdateAt)) + } + + fun removeBitmap(userId: String, serverUrl: String) { + cache.remove(CacheKey(userId, serverUrl)) + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/DatabaseHelper.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/DatabaseHelper.kt new file mode 100644 index 0000000..8ef28a2 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/DatabaseHelper.kt @@ -0,0 +1,83 @@ +package com.tokilabs.mattermost_push_plugin.helpers + +import android.content.Context +import android.util.Log +import com.tokilabs.mattermost_push_plugin.helpers.db.GlobalDatabase +import com.tokilabs.mattermost_push_plugin.helpers.db.GlobalEntity +import com.tokilabs.mattermost_push_plugin.helpers.db.MattermostDatabase +import com.tokilabs.mattermost_push_plugin.helpers.db.ServerEntity + +class DatabaseHelper private constructor(private val context: Context) { + + companion object { + private const val TAG = "DatabaseHelper" + private const val DEVICE_TOKEN_KEY = "deviceToken" + + @Volatile + private var instance: DatabaseHelper? = null + + fun getInstance(): DatabaseHelper? = instance + + fun init(context: Context): DatabaseHelper { + return instance ?: synchronized(this) { + instance ?: DatabaseHelper(context.applicationContext).also { instance = it } + } + } + } + + private val globalDb by lazy { GlobalDatabase.getInstance(context) } + + fun getDeviceToken(): String? { + return try { + globalDb.globalDao().getValue(DEVICE_TOKEN_KEY) + } catch (e: Exception) { + Log.e(TAG, "getDeviceToken error: ${e.message}") + null + } + } + + fun saveDeviceToken(token: String) { + try { + globalDb.globalDao().upsert(GlobalEntity(DEVICE_TOKEN_KEY, token)) + Log.i(TAG, "Device token saved") + } catch (e: Exception) { + Log.e(TAG, "saveDeviceToken error: ${e.message}") + } + } + + val onlyServerUrl: String? + get() = try { + val servers = globalDb.serversDao().getAll() + if (servers.size == 1) servers.first().url else null + } catch (e: Exception) { + null + } + + fun getServerUrlForIdentifier(serverId: String): String? { + return try { + globalDb.serversDao().getAll() + .firstOrNull { it.identifier == serverId }?.url + } catch (e: Exception) { + null + } + } + + fun saveServerUrl(serverUrl: String, identifier: String? = null) { + try { + globalDb.serversDao().upsert( + ServerEntity(url = serverUrl, dbPath = "", identifier = identifier), + ) + } catch (e: Exception) { + Log.e(TAG, "saveServerUrl error: ${e.message}") + } + } + + fun getDatabaseForServer(context: Context, serverUrl: String): MattermostDatabase? { + return try { + MattermostDatabase.getInstance(context, serverUrl) + } catch (e: Exception) { + Log.e(TAG, "getDatabaseForServer error for $serverUrl: ${e.message}") + null + } + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/Network.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/Network.kt new file mode 100644 index 0000000..cea42ce --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/Network.kt @@ -0,0 +1,103 @@ +package com.tokilabs.mattermost_push_plugin.helpers + +import android.util.Log +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import okhttp3.Response +import org.json.JSONObject +import java.util.concurrent.TimeUnit + +object Network { + private val client = OkHttpClient.Builder() + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .build() + + private val JSON_MEDIA_TYPE = "application/json; charset=utf-8".toMediaType() + private const val TAG = "NomadNetwork" + + private val tokenCache = mutableMapOf() + + fun setToken(serverUrl: String, token: String) { + tokenCache[serverUrl] = token + } + + fun clearToken(serverUrl: String) { + tokenCache.remove(serverUrl) + } + + fun postSync(serverUrl: String, endpoint: String, body: JSONObject, headers: Map? = null): Response { + val url = buildUrl(serverUrl, endpoint) + val requestBody = body.toString().toRequestBody(JSON_MEDIA_TYPE) + val requestBuilder = Request.Builder() + .url(url) + .post(requestBody) + .addHeader("Content-Type", "application/json") + + tokenCache[serverUrl]?.let { requestBuilder.addHeader("Authorization", "Bearer $it") } + headers?.forEach { (k, v) -> requestBuilder.addHeader(k, v) } + + Log.i(TAG, "POST $url") + return client.newCall(requestBuilder.build()).execute() + } + + fun post( + serverUrl: String, + endpoint: String, + body: JSONObject, + headers: Map? = null, + onSuccess: (JSONObject?) -> Unit, + onFailure: (Exception) -> Unit, + ) { + val url = buildUrl(serverUrl, endpoint) + val requestBody = body.toString().toRequestBody(JSON_MEDIA_TYPE) + val requestBuilder = Request.Builder() + .url(url) + .post(requestBody) + .addHeader("Content-Type", "application/json") + + tokenCache[serverUrl]?.let { requestBuilder.addHeader("Authorization", "Bearer $it") } + headers?.forEach { (k, v) -> requestBuilder.addHeader(k, v) } + + Log.i(TAG, "POST async $url") + client.newCall(requestBuilder.build()).enqueue(object : okhttp3.Callback { + override fun onFailure(call: okhttp3.Call, e: java.io.IOException) { + Log.e(TAG, "POST failed: ${e.message}") + onFailure(e) + } + + override fun onResponse(call: okhttp3.Call, response: Response) { + try { + val responseBody = response.body?.string() + val json = if (!responseBody.isNullOrEmpty()) JSONObject(responseBody) else null + onSuccess(json) + } catch (e: Exception) { + Log.e(TAG, "POST response parse error: ${e.message}") + onSuccess(null) + } + } + }) + } + + fun getSync(serverUrl: String, endpoint: String, headers: Map? = null): Response { + val url = buildUrl(serverUrl, endpoint) + val requestBuilder = Request.Builder() + .url(url) + .get() + + tokenCache[serverUrl]?.let { requestBuilder.addHeader("Authorization", "Bearer $it") } + headers?.forEach { (k, v) -> requestBuilder.addHeader(k, v) } + + Log.i(TAG, "GET $url") + return client.newCall(requestBuilder.build()).execute() + } + + private fun buildUrl(serverUrl: String, endpoint: String): String { + val base = serverUrl.trimEnd('/') + val path = endpoint.trimStart('/') + return "$base/$path" + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/NotificationHelper.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/NotificationHelper.kt new file mode 100644 index 0000000..33edfd3 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/NotificationHelper.kt @@ -0,0 +1,75 @@ +package com.tokilabs.mattermost_push_plugin.helpers + +import android.app.NotificationManager +import android.content.Context +import android.os.Bundle +import android.util.Log +import androidx.core.app.NotificationManagerCompat + +object NotificationHelper { + private const val TAG = "NotificationHelper" + const val MESSAGE_NOTIFICATION_ID = -1 + + private val notificationPreferences = mutableMapOf() + + fun getNotificationId(bundle: Bundle): Int { + val postId = bundle.getString("post_id") + return postId?.hashCode() ?: MESSAGE_NOTIFICATION_ID + } + + fun addNotificationToPreferences(context: Context, notificationId: Int, bundle: Bundle): Boolean { + val channelId = bundle.getString("channel_id") ?: return true + val rootId = bundle.getString("root_id") + val isCRTEnabled = bundle.getString("is_crt_enabled") == "true" + val groupId = if (isCRTEnabled && !rootId.isNullOrEmpty()) rootId else channelId + + val isFirst = notificationPreferences.none { (_, b) -> + val bGroupId = if (isCRTEnabled && !b.getString("root_id").isNullOrEmpty()) + b.getString("root_id") else b.getString("channel_id") + bGroupId == groupId + } + + notificationPreferences[notificationId] = bundle + return isFirst + } + + fun clearChannelOrThreadNotifications(context: Context, bundle: Bundle) { + val channelId = bundle.getString("channel_id") ?: return + val rootId = bundle.getString("root_id") + val isCRTEnabled = bundle.getString("is_crt_enabled") == "true" + val targetGroupId = if (isCRTEnabled && !rootId.isNullOrEmpty()) rootId else channelId + + val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + val toRemove = mutableListOf() + + notificationPreferences.forEach { (id, b) -> + val bRootId = b.getString("root_id") + val bChannelId = b.getString("channel_id") + val bGroupId = if (isCRTEnabled && !bRootId.isNullOrEmpty()) bRootId else bChannelId + if (bGroupId == targetGroupId) { + notificationManager.cancel(id) + toRemove.add(id) + Log.i(TAG, "Cancelled notification id=$id for group=$targetGroupId") + } + } + + toRemove.forEach { notificationPreferences.remove(it) } + } + + fun dismissNotification(context: Context, bundle: Bundle) { + val notificationId = getNotificationId(bundle) + val notificationManager = NotificationManagerCompat.from(context) + notificationManager.cancel(notificationId) + notificationPreferences.remove(notificationId) + Log.i(TAG, "Dismissed notification id=$notificationId") + } + + fun postNotification(context: Context, notification: android.app.Notification, notificationId: Int) { + try { + val notificationManager = NotificationManagerCompat.from(context) + notificationManager.notify(notificationId, notification) + } catch (e: SecurityException) { + Log.e(TAG, "No notification permission: ${e.message}") + } + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/PushNotificationDataHelper.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/PushNotificationDataHelper.kt new file mode 100644 index 0000000..d528075 --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/PushNotificationDataHelper.kt @@ -0,0 +1,182 @@ +package com.tokilabs.mattermost_push_plugin.helpers + +import android.content.Context +import android.os.Bundle +import android.util.Log +import com.tokilabs.mattermost_push_plugin.helpers.db.MattermostDatabase +import com.tokilabs.mattermost_push_plugin.helpers.db.SystemEntity +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock +import kotlinx.coroutines.withContext + +class PushNotificationDataHelper(private val context: Context) { + + suspend fun fetchAndStoreDataForPushNotification(initialData: Bundle, isFlutterInit: Boolean): Bundle? { + return withContext(Dispatchers.Default) { + PushNotificationDataRunnable.start(context, initialData, isFlutterInit) + } + } +} + +object PushNotificationDataRunnable { + private const val TAG = "PushNotifDataHelper" + private val mutex = Mutex() + + suspend fun start(context: Context, initialData: Bundle, isFlutterInit: Boolean): Bundle? { + mutex.withLock { + val serverUrl = initialData.getString("server_url") ?: return null + val dbHelper = DatabaseHelper.getInstance() ?: run { + Log.e(TAG, "DatabaseHelper not initialized") + return null + } + val db = dbHelper.getDatabaseForServer(context, serverUrl) + + var result: Bundle? = null + + try { + if (db != null) { + val teamId = initialData.getString("team_id") + val channelId = initialData.getString("channel_id") + val postId = initialData.getString("post_id") + val rootId = initialData.getString("root_id") + val isCRTEnabled = initialData.getString("is_crt_enabled") == "true" + val ackId = initialData.getString("ack_id") + + Log.i(TAG, "Start fetching notification data server=$serverUrl channel=$channelId ack=$ackId") + + val notificationData = Bundle() + + if (!teamId.isNullOrEmpty()) { + fetchTeamIfNeeded(db, serverUrl, teamId)?.let { + notificationData.putBundle("team", it) + } + } + + if (channelId != null && postId != null) { + fetchMyChannel(db, channelId)?.let { notificationData.putBundle("channel", it) } + + fetchPosts(db, serverUrl, channelId, isCRTEnabled, rootId)?.let { + notificationData.putBundle("posts", it) + } + + if (isCRTEnabled && !rootId.isNullOrEmpty()) { + fetchThread(db, serverUrl, rootId)?.let { + notificationData.putBundle("thread", it) + } + } + + fetchNeededUsers(serverUrl, channelId)?.let { + notificationData.putParcelableArray("users", it.toTypedArray()) + } + } + + result = notificationData + + if (!isFlutterInit) { + saveToDatabase(db, notificationData, teamId, channelId, isCRTEnabled) + } + + Log.i(TAG, "Done processing push notification server=$serverUrl channel=$channelId ack=$ackId") + } + } catch (e: Exception) { + Log.e(TAG, "Error processing push notification: ${e.message}") + e.printStackTrace() + } finally { + Log.i(TAG, "DONE fetching notification data") + } + + return result + } + } + + private fun fetchTeamIfNeeded(db: MattermostDatabase, serverUrl: String, teamId: String): Bundle? { + val team = db.teamDao().getTeam(teamId) ?: return null + return Bundle().apply { + putString("id", team.id) + putString("display_name", team.display_name) + } + } + + private fun fetchMyChannel(db: MattermostDatabase, channelId: String): Bundle? { + val channel = db.channelDao().getChannel(channelId) ?: return null + return Bundle().apply { + putString("id", channel.id) + putString("display_name", channel.display_name) + putString("type", channel.type) + putString("team_id", channel.team_id) + } + } + + private fun fetchPosts( + db: MattermostDatabase, + serverUrl: String, + channelId: String, + isCRTEnabled: Boolean, + rootId: String?, + ): Bundle? { + val posts = if (isCRTEnabled && rootId != null) { + db.postDao().getThreadPosts(rootId) + } else { + db.postDao().getPostsForChannel(channelId) + } + if (posts.isEmpty()) return null + return Bundle().apply { + posts.forEachIndexed { i, post -> + putBundle("post_$i", Bundle().apply { + putString("id", post.id) + putString("message", post.message) + putString("user_id", post.user_id) + putLong("create_at", post.create_at) + }) + } + } + } + + private fun fetchThread(db: MattermostDatabase, serverUrl: String, rootId: String): Bundle? { + val posts = db.postDao().getThreadPosts(rootId) + if (posts.isEmpty()) return null + return Bundle().apply { + putInt("reply_count", posts.size) + } + } + + private fun fetchNeededUsers(serverUrl: String, channelId: String): List? { + // [FOLLOW-UP] 현재 DB 스키마에는 `channel_members` 테이블이 존재하지 않습니다. + // 따라서 특정 채널의 멤버 유저들을 쿼리할 방법이 제한적이므로, + // 필요 유저 fetch 로직은 명시적 follow-up으로 분류하고 null을 반환합니다. + Log.i(TAG, "fetchNeededUsers: channelId=$channelId (No channel_members table in DB, classified as follow-up)") + return null + } + + private fun saveToDatabase( + db: MattermostDatabase, + data: Bundle, + teamId: String?, + channelId: String?, + isCRTEnabled: Boolean, + ) { + channelId ?: return + try { + val json = org.json.JSONObject().apply { + data.keySet()?.forEach { key -> + val value = data.get(key) + if (value is Bundle) { + // nested Bundle serialization + val subJson = org.json.JSONObject() + value.keySet()?.forEach { subKey -> + subJson.put(subKey, value.get(subKey)) + } + put(key, subJson) + } else { + put(key, value) + } + } + } + db.systemDao().upsert(SystemEntity("pendingNotification_$channelId", json.toString())) + Log.i(TAG, "saveToDatabase: Successfully saved pendingNotification_$channelId to DB") + } catch (e: Exception) { + Log.e(TAG, "saveToDatabase error: ${e.message}") + } + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/GlobalDatabase.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/GlobalDatabase.kt new file mode 100644 index 0000000..ee6898c --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/GlobalDatabase.kt @@ -0,0 +1,34 @@ +package com.tokilabs.mattermost_push_plugin.helpers.db + +import android.content.Context +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase + +@Database( + entities = [GlobalEntity::class, ServerEntity::class], + version = 1, + exportSchema = false, +) +abstract class GlobalDatabase : RoomDatabase() { + abstract fun globalDao(): GlobalDao + abstract fun serversDao(): ServersDao + + companion object { + @Volatile private var instance: GlobalDatabase? = null + + fun getInstance(context: Context): GlobalDatabase { + return instance ?: synchronized(this) { + instance ?: Room.databaseBuilder( + context.applicationContext, + GlobalDatabase::class.java, + "mattermost_global.db", + ) + .allowMainThreadQueries() + .fallbackToDestructiveMigration() + .build() + .also { instance = it } + } + } + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/GlobalEntities.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/GlobalEntities.kt new file mode 100644 index 0000000..a491afa --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/GlobalEntities.kt @@ -0,0 +1,49 @@ +package com.tokilabs.mattermost_push_plugin.helpers.db + +import androidx.room.ColumnInfo +import androidx.room.Dao +import androidx.room.Entity +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.PrimaryKey +import androidx.room.Query + +@Entity(tableName = "Global") +data class GlobalEntity( + @PrimaryKey val id: String, + val value: String, +) + +@Dao +interface GlobalDao { + @Query("SELECT value FROM Global WHERE id = :id LIMIT 1") + fun getValue(id: String): String? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: GlobalEntity) +} + +@Entity(tableName = "Servers") +data class ServerEntity( + @PrimaryKey val url: String, + @ColumnInfo(name = "db_path") val dbPath: String, + val identifier: String? = null, +) + +@Dao +interface ServersDao { + @Query("SELECT * FROM Servers WHERE url = :url LIMIT 1") + fun getServer(url: String): ServerEntity? + + @Query("SELECT COUNT(*) FROM Servers") + fun count(): Int + + @Query("SELECT url FROM Servers LIMIT 1") + fun getFirstUrl(): String? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: ServerEntity) + + @Query("SELECT * FROM Servers") + fun getAll(): List +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/MattermostDatabase.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/MattermostDatabase.kt new file mode 100644 index 0000000..63a039d --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/MattermostDatabase.kt @@ -0,0 +1,50 @@ +package com.tokilabs.mattermost_push_plugin.helpers.db + +import android.content.Context +import androidx.room.Database +import androidx.room.Room +import androidx.room.RoomDatabase + +@Database( + entities = [ + ConfigEntity::class, UserEntity::class, SystemEntity::class, + ChannelEntity::class, PostEntity::class, TeamEntity::class + ], + version = 2, + exportSchema = false, +) +abstract class MattermostDatabase : RoomDatabase() { + abstract fun configDao(): ConfigDao + abstract fun userDao(): UserDao + abstract fun systemDao(): SystemDao + abstract fun channelDao(): ChannelDao + abstract fun postDao(): PostDao + abstract fun teamDao(): TeamDao + + fun queryConfigServerVersion(): String? = configDao().getValue("Version") + + fun queryConfigSigningKey(): String? = configDao().getValue("AsymmetricSigningPublicKey") + + fun getLastPictureUpdate(userId: String): Double? { + val id = if (userId == "me") systemDao().getValue("currentUserId") ?: userId else userId + return userDao().getLastPictureUpdate(id) + } + + companion object { + @Volatile private var instances = mutableMapOf() + + fun getInstance(context: Context, serverUrl: String): MattermostDatabase { + return instances.getOrPut(serverUrl) { + val dbName = "mattermost_server_${serverUrl.hashCode()}.db" + Room.databaseBuilder( + context.applicationContext, + MattermostDatabase::class.java, + dbName, + ) + .allowMainThreadQueries() + .fallbackToDestructiveMigration() + .build() + } + } + } +} diff --git a/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/ServerEntities.kt b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/ServerEntities.kt new file mode 100644 index 0000000..d76d69a --- /dev/null +++ b/android/src/main/kotlin/com/tokilabs/mattermost_push_plugin/helpers/db/ServerEntities.kt @@ -0,0 +1,128 @@ +package com.tokilabs.mattermost_push_plugin.helpers.db + +import androidx.room.ColumnInfo +import androidx.room.Dao +import androidx.room.Entity +import androidx.room.Insert +import androidx.room.OnConflictStrategy +import androidx.room.PrimaryKey +import androidx.room.Query + +@Entity(tableName = "Config") +data class ConfigEntity( + @PrimaryKey val id: String, + val value: String?, +) + +@Dao +interface ConfigDao { + @Query("SELECT value FROM Config WHERE id = :id LIMIT 1") + fun getValue(id: String): String? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: ConfigEntity) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsertAll(entities: List) +} + +@Entity(tableName = "User") +data class UserEntity( + @PrimaryKey val id: String, + @ColumnInfo(name = "last_picture_update") val lastPictureUpdate: Double = 0.0, + val username: String? = null, + val email: String? = null, + @ColumnInfo(name = "first_name") val firstName: String? = null, + @ColumnInfo(name = "last_name") val lastName: String? = null, + val roles: String? = null, +) + +@Dao +interface UserDao { + @Query("SELECT last_picture_update FROM User WHERE id = :userId LIMIT 1") + fun getLastPictureUpdate(userId: String): Double? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: UserEntity) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsertAll(entities: List) +} + +@Entity(tableName = "System") +data class SystemEntity( + @PrimaryKey val id: String, + val value: String?, +) + +@Dao +interface SystemDao { + @Query("SELECT value FROM System WHERE id = :id LIMIT 1") + fun getValue(id: String): String? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: SystemEntity) +} + +// Channel 테이블 +@Entity(tableName = "Channel") +data class ChannelEntity( + @PrimaryKey val id: String, + val display_name: String? = null, + val type: String? = null, // O=public, P=private, D=DM, G=Group + val team_id: String? = null, + val delete_at: Long = 0 +) + +@Dao +interface ChannelDao { + @Query("SELECT * FROM Channel WHERE id = :id LIMIT 1") + fun getChannel(id: String): ChannelEntity? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: ChannelEntity) +} + +// Post 테이블 +@Entity(tableName = "Post") +data class PostEntity( + @PrimaryKey val id: String, + val channel_id: String? = null, + val root_id: String? = null, + val user_id: String? = null, + val message: String? = null, + val create_at: Long = 0, + val delete_at: Long = 0 +) + +@Dao +interface PostDao { + @Query("SELECT * FROM Post WHERE channel_id = :channelId ORDER BY create_at DESC LIMIT 20") + fun getPostsForChannel(channelId: String): List + + @Query("SELECT * FROM Post WHERE root_id = :rootId ORDER BY create_at ASC") + fun getThreadPosts(rootId: String): List + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: PostEntity) + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsertAll(entities: List) +} + +// Team 테이블 +@Entity(tableName = "Team") +data class TeamEntity( + @PrimaryKey val id: String, + val display_name: String? = null, + val name: String? = null +) + +@Dao +interface TeamDao { + @Query("SELECT * FROM Team WHERE id = :id LIMIT 1") + fun getTeam(id: String): TeamEntity? + + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun upsert(entity: TeamEntity) +} diff --git a/android/src/main/res/drawable-hdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-hdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..db4dc25 Binary files /dev/null and b/android/src/main/res/drawable-hdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-mdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-mdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..d34c7a5 Binary files /dev/null and b/android/src/main/res/drawable-mdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-night-hdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-night-hdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..db4dc25 Binary files /dev/null and b/android/src/main/res/drawable-night-hdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-night-mdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-night-mdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..d34c7a5 Binary files /dev/null and b/android/src/main/res/drawable-night-mdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-night-xhdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-night-xhdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..84c30ef Binary files /dev/null and b/android/src/main/res/drawable-night-xhdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-night-xxhdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-night-xxhdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..7bc94bf Binary files /dev/null and b/android/src/main/res/drawable-night-xxhdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-night-xxxhdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-night-xxxhdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..aec3580 Binary files /dev/null and b/android/src/main/res/drawable-night-xxxhdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-xhdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-xhdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..84c30ef Binary files /dev/null and b/android/src/main/res/drawable-xhdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-xxhdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-xxhdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..7bc94bf Binary files /dev/null and b/android/src/main/res/drawable-xxhdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/drawable-xxxhdpi/ic_notif_action_reply.png b/android/src/main/res/drawable-xxxhdpi/ic_notif_action_reply.png new file mode 100644 index 0000000..aec3580 Binary files /dev/null and b/android/src/main/res/drawable-xxxhdpi/ic_notif_action_reply.png differ diff --git a/android/src/main/res/mipmap-hdpi/ic_notification.png b/android/src/main/res/mipmap-hdpi/ic_notification.png new file mode 100644 index 0000000..9e82206 Binary files /dev/null and b/android/src/main/res/mipmap-hdpi/ic_notification.png differ diff --git a/android/src/main/res/mipmap-mdpi/ic_notification.png b/android/src/main/res/mipmap-mdpi/ic_notification.png new file mode 100644 index 0000000..b3bcc05 Binary files /dev/null and b/android/src/main/res/mipmap-mdpi/ic_notification.png differ diff --git a/android/src/main/res/mipmap-xhdpi/ic_notification.png b/android/src/main/res/mipmap-xhdpi/ic_notification.png new file mode 100644 index 0000000..45d5d8c Binary files /dev/null and b/android/src/main/res/mipmap-xhdpi/ic_notification.png differ diff --git a/android/src/main/res/mipmap-xxhdpi/ic_notification.png b/android/src/main/res/mipmap-xxhdpi/ic_notification.png new file mode 100644 index 0000000..c97157d Binary files /dev/null and b/android/src/main/res/mipmap-xxhdpi/ic_notification.png differ diff --git a/android/src/main/res/mipmap-xxxhdpi/ic_notification.png b/android/src/main/res/mipmap-xxxhdpi/ic_notification.png new file mode 100644 index 0000000..7746a7e Binary files /dev/null and b/android/src/main/res/mipmap-xxxhdpi/ic_notification.png differ diff --git a/android/src/test/kotlin/com/tokilabs/mattermost_push_plugin/MattermostPushPluginTest.kt b/android/src/test/kotlin/com/tokilabs/mattermost_push_plugin/MattermostPushPluginTest.kt new file mode 100644 index 0000000..50ed1ac --- /dev/null +++ b/android/src/test/kotlin/com/tokilabs/mattermost_push_plugin/MattermostPushPluginTest.kt @@ -0,0 +1,27 @@ +package com.tokilabs.mattermost_push_plugin + +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import org.mockito.Mockito +import kotlin.test.Test + +/* + * This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation. + * + * Once you have built the plugin's example app, you can run these tests from the command + * line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or + * you can run them directly from IDEs that support JUnit such as Android Studio. + */ + +internal class MattermostPushPluginTest { + @Test + fun onMethodCall_getPlatformVersion_returnsExpectedValue() { + val plugin = MattermostPushPlugin() + + val call = MethodCall("getPlatformVersion", null) + val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java) + plugin.onMethodCall(call, mockResult) + + Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE) + } +} diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..3820a95 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,45 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.build/ +.buildlog/ +.history +.svn/ +.swiftpm/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins-dependencies +.pub-cache/ +.pub/ +/build/ +/coverage/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..f073e2e --- /dev/null +++ b/example/README.md @@ -0,0 +1,17 @@ +# mattermost_push_plugin_example + +Demonstrates how to use the mattermost_push_plugin plugin. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Learn Flutter](https://docs.flutter.dev/get-started/learn-flutter) +- [Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Flutter learning resources](https://docs.flutter.dev/reference/learning-resources) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 0000000..0d29021 --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,28 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at https://dart.dev/lints. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/android/.gitignore b/example/android/.gitignore new file mode 100644 index 0000000..be3943c --- /dev/null +++ b/example/android/.gitignore @@ -0,0 +1,14 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java +.cxx/ + +# Remember to never publicly share your keystore. +# See https://flutter.dev/to/reference-keystore +key.properties +**/*.keystore +**/*.jks diff --git a/example/android/app/build.gradle.kts b/example/android/app/build.gradle.kts new file mode 100644 index 0000000..6e91790 --- /dev/null +++ b/example/android/app/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + id("com.android.application") + id("kotlin-android") + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id("dev.flutter.flutter-gradle-plugin") +} + +android { + namespace = "com.tokilabs.mattermost_push_plugin_example" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_17.toString() + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId = "com.tokilabs.mattermost_push_plugin_example" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig = signingConfigs.getByName("debug") + } + } +} + +flutter { + source = "../.." +} diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..399f698 --- /dev/null +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a1ac300 --- /dev/null +++ b/example/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/example/android/app/src/main/kotlin/com/tokilabs/mattermost_push_plugin_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/tokilabs/mattermost_push_plugin_example/MainActivity.kt new file mode 100644 index 0000000..1ecb664 --- /dev/null +++ b/example/android/app/src/main/kotlin/com/tokilabs/mattermost_push_plugin_example/MainActivity.kt @@ -0,0 +1,5 @@ +package com.tokilabs.mattermost_push_plugin_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity : FlutterActivity() diff --git a/example/android/app/src/main/res/drawable-v21/launch_background.xml b/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 0000000..f74085f --- /dev/null +++ b/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/example/android/app/src/main/res/drawable/launch_background.xml b/example/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 0000000..304732f --- /dev/null +++ b/example/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..db77bb4 Binary files /dev/null and b/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..17987b7 Binary files /dev/null and b/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..09d4391 Binary files /dev/null and b/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..d5f1c8d Binary files /dev/null and b/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..4d6372e Binary files /dev/null and b/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000..06952be --- /dev/null +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..cb1ef88 --- /dev/null +++ b/example/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/example/android/app/src/profile/AndroidManifest.xml b/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 0000000..399f698 --- /dev/null +++ b/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/example/android/build.gradle.kts b/example/android/build.gradle.kts new file mode 100644 index 0000000..dbee657 --- /dev/null +++ b/example/android/build.gradle.kts @@ -0,0 +1,24 @@ +allprojects { + repositories { + google() + mavenCentral() + } +} + +val newBuildDir: Directory = + rootProject.layout.buildDirectory + .dir("../../build") + .get() +rootProject.layout.buildDirectory.value(newBuildDir) + +subprojects { + val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name) + project.layout.buildDirectory.value(newSubprojectBuildDir) +} +subprojects { + project.evaluationDependsOn(":app") +} + +tasks.register("clean") { + delete(rootProject.layout.buildDirectory) +} diff --git a/example/android/gradle.properties b/example/android/gradle.properties new file mode 100644 index 0000000..d5da727 --- /dev/null +++ b/example/android/gradle.properties @@ -0,0 +1,6 @@ +org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError +android.useAndroidX=true +# This builtInKotlin flag was added automatically by Flutter migrator +android.builtInKotlin=false +# This newDsl flag was added automatically by Flutter migrator +android.newDsl=false diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..e4ef43f --- /dev/null +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip diff --git a/example/android/settings.gradle.kts b/example/android/settings.gradle.kts new file mode 100644 index 0000000..ca7fe06 --- /dev/null +++ b/example/android/settings.gradle.kts @@ -0,0 +1,26 @@ +pluginManagement { + val flutterSdkPath = + run { + val properties = java.util.Properties() + file("local.properties").inputStream().use { properties.load(it) } + val flutterSdkPath = properties.getProperty("flutter.sdk") + require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" } + flutterSdkPath + } + + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") + + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +plugins { + id("dev.flutter.flutter-plugin-loader") version "1.0.0" + id("com.android.application") version "8.11.1" apply false + id("org.jetbrains.kotlin.android") version "2.2.20" apply false +} + +include(":app") diff --git a/example/integration_test/plugin_integration_test.dart b/example/integration_test/plugin_integration_test.dart new file mode 100644 index 0000000..dfa71fe --- /dev/null +++ b/example/integration_test/plugin_integration_test.dart @@ -0,0 +1,14 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +import 'package:mattermost_push_plugin/mattermost_push_plugin.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('singleton instance is accessible', (WidgetTester tester) async { + expect(MattermostPushPlugin.instance, isNotNull); + expect(MattermostPushPlugin.notificationChannelName, + 'com.tokilabs.mattermost/notifications'); + }); +} diff --git a/example/ios/.gitignore b/example/ios/.gitignore new file mode 100644 index 0000000..7a7f987 --- /dev/null +++ b/example/ios/.gitignore @@ -0,0 +1,34 @@ +**/dgph +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/ephemeral/ +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000..391a902 --- /dev/null +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + + diff --git a/example/ios/Flutter/Debug.xcconfig b/example/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000..ec97fc6 --- /dev/null +++ b/example/ios/Flutter/Debug.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include "Generated.xcconfig" diff --git a/example/ios/Flutter/Release.xcconfig b/example/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000..c4855bf --- /dev/null +++ b/example/ios/Flutter/Release.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include "Generated.xcconfig" diff --git a/example/ios/Podfile b/example/ios/Podfile new file mode 100644 index 0000000..620e46e --- /dev/null +++ b/example/ios/Podfile @@ -0,0 +1,43 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '13.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..4cff943 --- /dev/null +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,620 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 331C8085294A63A400263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 97C146E61CF9000F007C117D /* Project object */; + proxyType = 1; + remoteGlobalIDString = 97C146ED1CF9000F007C117D; + remoteInfo = Runner; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 331C8082294A63A400263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C807B294A618700263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + 331C8082294A63A400263BE5 /* RunnerTests */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + 331C8081294A63A400263BE5 /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */, + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, + ); + path = Runner; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 331C8080294A63A400263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C807D294A63A400263BE5 /* Sources */, + 331C807F294A63A400263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C8086294A63A400263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C8081294A63A400263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = YES; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 331C8080294A63A400263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 97C146ED1CF9000F007C117D; + }; + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1100; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + 331C8080294A63A400263BE5 /* RunnerTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 331C807F294A63A400263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 331C807D294A63A400263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + 7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 331C8086294A63A400263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 97C146ED1CF9000F007C117D /* Runner */; + targetProxy = 331C8085294A63A400263BE5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 249021D3217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 249021D4217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Profile; + }; + 331C8088294A63A400263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Debug; + }; + 331C8089294A63A400263BE5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Release; + }; + 331C808A294A63A400263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C8088294A63A400263BE5 /* Debug */, + 331C8089294A63A400263BE5 /* Release */, + 331C808A294A63A400263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 249021D3217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 249021D4217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..e3773d4 --- /dev/null +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1d526a1 --- /dev/null +++ b/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..f9b0d7c --- /dev/null +++ b/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000..c30b367 --- /dev/null +++ b/example/ios/Runner/AppDelegate.swift @@ -0,0 +1,16 @@ +import Flutter +import UIKit + +@main +@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } + + func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) { + GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry) + } +} diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d36b1fa --- /dev/null +++ b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,122 @@ +{ + "images" : [ + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "20x20", + "idiom" : "iphone", + "filename" : "Icon-App-20x20@3x.png", + "scale" : "3x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "iphone", + "filename" : "Icon-App-29x29@3x.png", + "scale" : "3x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "iphone", + "filename" : "Icon-App-40x40@3x.png", + "scale" : "3x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@2x.png", + "scale" : "2x" + }, + { + "size" : "60x60", + "idiom" : "iphone", + "filename" : "Icon-App-60x60@3x.png", + "scale" : "3x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@1x.png", + "scale" : "1x" + }, + { + "size" : "20x20", + "idiom" : "ipad", + "filename" : "Icon-App-20x20@2x.png", + "scale" : "2x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@1x.png", + "scale" : "1x" + }, + { + "size" : "29x29", + "idiom" : "ipad", + "filename" : "Icon-App-29x29@2x.png", + "scale" : "2x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@1x.png", + "scale" : "1x" + }, + { + "size" : "40x40", + "idiom" : "ipad", + "filename" : "Icon-App-40x40@2x.png", + "scale" : "2x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@1x.png", + "scale" : "1x" + }, + { + "size" : "76x76", + "idiom" : "ipad", + "filename" : "Icon-App-76x76@2x.png", + "scale" : "2x" + }, + { + "size" : "83.5x83.5", + "idiom" : "ipad", + "filename" : "Icon-App-83.5x83.5@2x.png", + "scale" : "2x" + }, + { + "size" : "1024x1024", + "idiom" : "ios-marketing", + "filename" : "Icon-App-1024x1024@1x.png", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png new file mode 100644 index 0000000..dc9ada4 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png new file mode 100644 index 0000000..7353c41 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png new file mode 100644 index 0000000..797d452 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png new file mode 100644 index 0000000..6ed2d93 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png new file mode 100644 index 0000000..4cd7b00 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png new file mode 100644 index 0000000..fe73094 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png new file mode 100644 index 0000000..321773c Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png new file mode 100644 index 0000000..797d452 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png new file mode 100644 index 0000000..502f463 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png new file mode 100644 index 0000000..0ec3034 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png new file mode 100644 index 0000000..0ec3034 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png new file mode 100644 index 0000000..e9f5fea Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png new file mode 100644 index 0000000..84ac32a Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png new file mode 100644 index 0000000..8953cba Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png new file mode 100644 index 0000000..0467bf1 Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json new file mode 100644 index 0000000..0bedcf2 --- /dev/null +++ b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "LaunchImage.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "LaunchImage@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png differ diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png differ diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png new file mode 100644 index 0000000..9da19ea Binary files /dev/null and b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png differ diff --git a/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md new file mode 100644 index 0000000..89c2725 --- /dev/null +++ b/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md @@ -0,0 +1,5 @@ +# Launch Screen Assets + +You can customize the launch screen with your own desired assets by replacing the image files in this directory. + +You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. \ No newline at end of file diff --git a/example/ios/Runner/Base.lproj/LaunchScreen.storyboard b/example/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..f2e259c --- /dev/null +++ b/example/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/ios/Runner/Base.lproj/Main.storyboard b/example/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000..f3c2851 --- /dev/null +++ b/example/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist new file mode 100644 index 0000000..f920c38 --- /dev/null +++ b/example/ios/Runner/Info.plist @@ -0,0 +1,70 @@ + + + + + CADisableMinimumFrameDurationOnPhone + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Mattermost Push Plugin + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + mattermost_push_plugin_example + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneClassName + UIWindowScene + UISceneConfigurationName + flutter + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UIApplicationSupportsIndirectInputEvents + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/example/ios/Runner/Runner-Bridging-Header.h b/example/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000..308a2a5 --- /dev/null +++ b/example/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1 @@ +#import "GeneratedPluginRegistrant.h" diff --git a/example/ios/Runner/SceneDelegate.swift b/example/ios/Runner/SceneDelegate.swift new file mode 100644 index 0000000..b9ce8ea --- /dev/null +++ b/example/ios/Runner/SceneDelegate.swift @@ -0,0 +1,6 @@ +import Flutter +import UIKit + +class SceneDelegate: FlutterSceneDelegate { + +} diff --git a/example/ios/RunnerTests/RunnerTests.swift b/example/ios/RunnerTests/RunnerTests.swift new file mode 100644 index 0000000..a65375d --- /dev/null +++ b/example/ios/RunnerTests/RunnerTests.swift @@ -0,0 +1,27 @@ +import Flutter +import UIKit +import XCTest + + +@testable import mattermost_push_plugin + +// This demonstrates a simple unit test of the Swift portion of this plugin's implementation. +// +// See https://developer.apple.com/documentation/xctest for more information about using XCTest. + +class RunnerTests: XCTestCase { + + func testGetPlatformVersion() { + let plugin = MattermostPushPlugin() + + let call = FlutterMethodCall(methodName: "getPlatformVersion", arguments: []) + + let resultExpectation = expectation(description: "result block must be called.") + plugin.handle(call) { result in + XCTAssertEqual(result as! String, "iOS " + UIDevice.current.systemVersion) + resultExpectation.fulfill() + } + waitForExpectations(timeout: 1) + } + +} diff --git a/example/lib/main.dart b/example/lib/main.dart new file mode 100644 index 0000000..ad992b3 --- /dev/null +++ b/example/lib/main.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; +import 'package:mattermost_push_plugin/mattermost_push_plugin.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + String? _deviceToken; + + @override + void initState() { + super.initState(); + MattermostPushPlugin.instance.onDeviceTokenReady = (token) { + if (!mounted) return; + setState(() => _deviceToken = token); + }; + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar(title: const Text('Mattermost push plugin example')), + body: Center( + child: Text('Device token: ${_deviceToken ?? 'pending'}'), + ), + ), + ); + } +} diff --git a/example/macos/.gitignore b/example/macos/.gitignore new file mode 100644 index 0000000..746adbb --- /dev/null +++ b/example/macos/.gitignore @@ -0,0 +1,7 @@ +# Flutter-related +**/Flutter/ephemeral/ +**/Pods/ + +# Xcode-related +**/dgph +**/xcuserdata/ diff --git a/example/macos/Flutter/Flutter-Debug.xcconfig b/example/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 0000000..4b81f9b --- /dev/null +++ b/example/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/example/macos/Flutter/Flutter-Release.xcconfig b/example/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 0000000..5caa9d1 --- /dev/null +++ b/example/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift new file mode 100644 index 0000000..688c1ee --- /dev/null +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -0,0 +1,16 @@ +// +// Generated file. Do not edit. +// + +import FlutterMacOS +import Foundation + +import firebase_core +import firebase_messaging +import mattermost_push_plugin + +func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) + FLTFirebaseMessagingPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseMessagingPlugin")) + MattermostPushPlugin.register(with: registry.registrar(forPlugin: "MattermostPushPlugin")) +} diff --git a/example/macos/Podfile b/example/macos/Podfile new file mode 100644 index 0000000..ff5ddb3 --- /dev/null +++ b/example/macos/Podfile @@ -0,0 +1,42 @@ +platform :osx, '10.15' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + + flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/example/macos/Runner.xcodeproj/project.pbxproj b/example/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..09b819c --- /dev/null +++ b/example/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,705 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 331C80D8294CF71000263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C80D7294CF71000263BE5 /* RunnerTests.swift */; }; + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 331C80D9294CF71000263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC10EC2044A3C60003C045; + remoteInfo = Runner; + }; + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 331C80D5294CF71000263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 331C80D7294CF71000263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* mattermost_push_plugin_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "mattermost_push_plugin_example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 331C80D2294CF70F00263BE5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 331C80D6294CF71000263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C80D7294CF71000263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 331C80D6294CF71000263BE5 /* RunnerTests */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* mattermost_push_plugin_example.app */, + 331C80D5294CF71000263BE5 /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 331C80D4294CF70F00263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C80DE294CF71000263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C80D1294CF70F00263BE5 /* Sources */, + 331C80D2294CF70F00263BE5 /* Frameworks */, + 331C80D3294CF70F00263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C80DA294CF71000263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C80D5294CF71000263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* mattermost_push_plugin_example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = YES; + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 331C80D4294CF70F00263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 33CC10EC2044A3C60003C045; + }; + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 331C80D4294CF70F00263BE5 /* RunnerTests */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 331C80D3294CF70F00263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 331C80D1294CF70F00263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C80D8294CF71000263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 331C80DA294CF71000263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC10EC2044A3C60003C045 /* Runner */; + targetProxy = 331C80D9294CF71000263BE5 /* PBXContainerItemProxy */; + }; + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 331C80DB294CF71000263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/mattermost_push_plugin_example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/mattermost_push_plugin_example"; + }; + name = Debug; + }; + 331C80DC294CF71000263BE5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/mattermost_push_plugin_example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/mattermost_push_plugin_example"; + }; + name = Release; + }; + 331C80DD294CF71000263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/mattermost_push_plugin_example.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/mattermost_push_plugin_example"; + }; + name = Profile; + }; + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 331C80DE294CF71000263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C80DB294CF71000263BE5 /* Debug */, + 331C80DC294CF71000263BE5 /* Release */, + 331C80DD294CF71000263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..41db94c --- /dev/null +++ b/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/example/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1d526a1 --- /dev/null +++ b/example/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/example/macos/Runner/AppDelegate.swift b/example/macos/Runner/AppDelegate.swift new file mode 100644 index 0000000..b3c1761 --- /dev/null +++ b/example/macos/Runner/AppDelegate.swift @@ -0,0 +1,13 @@ +import Cocoa +import FlutterMacOS + +@main +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } +} diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..a2ec33f --- /dev/null +++ b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_16.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_64.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_128.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_1024.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png new file mode 100644 index 0000000..82b6f9d Binary files /dev/null and b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png differ diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png new file mode 100644 index 0000000..13b35eb Binary files /dev/null and b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png differ diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png new file mode 100644 index 0000000..0a3f5fa Binary files /dev/null and b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png differ diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png new file mode 100644 index 0000000..bdb5722 Binary files /dev/null and b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png differ diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png new file mode 100644 index 0000000..f083318 Binary files /dev/null and b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png differ diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png new file mode 100644 index 0000000..326c0e7 Binary files /dev/null and b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png differ diff --git a/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png new file mode 100644 index 0000000..2f1632c Binary files /dev/null and b/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png differ diff --git a/example/macos/Runner/Base.lproj/MainMenu.xib b/example/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 0000000..80e867a --- /dev/null +++ b/example/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,343 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/macos/Runner/Configs/AppInfo.xcconfig b/example/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 0000000..ec904a0 --- /dev/null +++ b/example/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = mattermost_push_plugin_example + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = com.tokilabs.mattermostPushPluginExample + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2026 com.tokilabs. All rights reserved. diff --git a/example/macos/Runner/Configs/Debug.xcconfig b/example/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 0000000..36b0fd9 --- /dev/null +++ b/example/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/example/macos/Runner/Configs/Release.xcconfig b/example/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 0000000..dff4f49 --- /dev/null +++ b/example/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/example/macos/Runner/Configs/Warnings.xcconfig b/example/macos/Runner/Configs/Warnings.xcconfig new file mode 100644 index 0000000..42bcbf4 --- /dev/null +++ b/example/macos/Runner/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/example/macos/Runner/DebugProfile.entitlements b/example/macos/Runner/DebugProfile.entitlements new file mode 100644 index 0000000..dddb8a3 --- /dev/null +++ b/example/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/example/macos/Runner/Info.plist b/example/macos/Runner/Info.plist new file mode 100644 index 0000000..4789daa --- /dev/null +++ b/example/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/example/macos/Runner/MainFlutterWindow.swift b/example/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 0000000..3cc05eb --- /dev/null +++ b/example/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,15 @@ +import Cocoa +import FlutterMacOS + +class MainFlutterWindow: NSWindow { + override func awakeFromNib() { + let flutterViewController = FlutterViewController() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + + super.awakeFromNib() + } +} diff --git a/example/macos/Runner/Release.entitlements b/example/macos/Runner/Release.entitlements new file mode 100644 index 0000000..852fa1a --- /dev/null +++ b/example/macos/Runner/Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/example/macos/RunnerTests/RunnerTests.swift b/example/macos/RunnerTests/RunnerTests.swift new file mode 100644 index 0000000..9c912e8 --- /dev/null +++ b/example/macos/RunnerTests/RunnerTests.swift @@ -0,0 +1,28 @@ +import Cocoa +import FlutterMacOS +import XCTest + + +@testable import mattermost_push_plugin + +// This demonstrates a simple unit test of the Swift portion of this plugin's implementation. +// +// See https://developer.apple.com/documentation/xctest for more information about using XCTest. + +class RunnerTests: XCTestCase { + + func testGetPlatformVersion() { + let plugin = MattermostPushPlugin() + + let call = FlutterMethodCall(methodName: "getPlatformVersion", arguments: []) + + let resultExpectation = expectation(description: "result block must be called.") + plugin.handle(call) { result in + XCTAssertEqual(result as! String, + "macOS " + ProcessInfo.processInfo.operatingSystemVersionString) + resultExpectation.fulfill() + } + waitForExpectations(timeout: 1) + } + +} diff --git a/example/pubspec.lock b/example/pubspec.lock new file mode 100644 index 0000000..7bcc2fd --- /dev/null +++ b/example/pubspec.lock @@ -0,0 +1,352 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _flutterfire_internals: + dependency: transitive + description: + name: _flutterfire_internals + sha256: ff0a84a2734d9e1089f8aedd5c0af0061b82fb94e95260d943404e0ef2134b11 + url: "https://pub.dev" + source: hosted + version: "1.3.59" + async: + dependency: transitive + description: + name: async + sha256: e2eb0491ba5ddb6177742d2da23904574082139b07c1e33b8503b9f46f3e1a37 + url: "https://pub.dev" + source: hosted + version: "2.13.1" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + characters: + dependency: transitive + description: + name: characters + sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b + url: "https://pub.dev" + source: hosted + version: "1.4.1" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + sha256: "41e005c33bd814be4d3096aff55b1908d419fde52ca656c8c47719ec745873cd" + url: "https://pub.dev" + source: hosted + version: "1.0.9" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + url: "https://pub.dev" + source: hosted + version: "1.3.3" + file: + dependency: transitive + description: + name: file + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + url: "https://pub.dev" + source: hosted + version: "7.0.1" + firebase_core: + dependency: transitive + description: + name: firebase_core + sha256: "7be63a3f841fc9663342f7f3a011a42aef6a61066943c90b1c434d79d5c995c5" + url: "https://pub.dev" + source: hosted + version: "3.15.2" + firebase_core_platform_interface: + dependency: transitive + description: + name: firebase_core_platform_interface + sha256: "0ecda14c1bfc9ed8cac303dd0f8d04a320811b479362a9a4efb14fd331a473ce" + url: "https://pub.dev" + source: hosted + version: "6.0.3" + firebase_core_web: + dependency: transitive + description: + name: firebase_core_web + sha256: "0ed0dc292e8f9ac50992e2394e9d336a0275b6ae400d64163fdf0a8a8b556c37" + url: "https://pub.dev" + source: hosted + version: "2.24.1" + firebase_messaging: + dependency: transitive + description: + name: firebase_messaging + sha256: "60be38574f8b5658e2f22b7e311ff2064bea835c248424a383783464e8e02fcc" + url: "https://pub.dev" + source: hosted + version: "15.2.10" + firebase_messaging_platform_interface: + dependency: transitive + description: + name: firebase_messaging_platform_interface + sha256: "685e1771b3d1f9c8502771ccc9f91485b376ffe16d553533f335b9183ea99754" + url: "https://pub.dev" + source: hosted + version: "4.6.10" + firebase_messaging_web: + dependency: transitive + description: + name: firebase_messaging_web + sha256: "0d1be17bc89ed3ff5001789c92df678b2e963a51b6fa2bdb467532cc9dbed390" + url: "https://pub.dev" + source: hosted + version: "3.10.10" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_driver: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1" + url: "https://pub.dev" + source: hosted + version: "6.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + integration_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" + url: "https://pub.dev" + source: hosted + version: "11.0.2" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" + url: "https://pub.dev" + source: hosted + version: "3.0.10" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + lints: + dependency: transitive + description: + name: lints + sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df" + url: "https://pub.dev" + source: hosted + version: "6.1.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 + url: "https://pub.dev" + source: hosted + version: "0.12.19" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" + url: "https://pub.dev" + source: hosted + version: "0.13.0" + mattermost_push_plugin: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "0.0.1" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + platform: + dependency: transitive + description: + name: platform + sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" + url: "https://pub.dev" + source: hosted + version: "3.1.6" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" + process: + dependency: transitive + description: + name: process + sha256: c6248e4526673988586e8c00bb22a49210c258dc91df5227d5da9748ecf79744 + url: "https://pub.dev" + source: hosted + version: "5.0.5" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + source_span: + dependency: transitive + description: + name: source_span + sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab" + url: "https://pub.dev" + source: hosted + version: "1.10.2" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" + source: hosted + version: "1.12.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + sync_http: + dependency: transitive + description: + name: sync_http + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + test_api: + dependency: transitive + description: + name: test_api + sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a" + url: "https://pub.dev" + source: hosted + version: "0.7.10" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b + url: "https://pub.dev" + source: hosted + version: "2.2.0" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "0016aef94fc66495ac78af5859181e3f3bf2026bd8eecc72b9565601e19ab360" + url: "https://pub.dev" + source: hosted + version: "15.2.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + webdriver: + dependency: transitive + description: + name: webdriver + sha256: "2f3a14ca026957870cfd9c635b83507e0e51d8091568e90129fbf805aba7cade" + url: "https://pub.dev" + source: hosted + version: "3.1.0" +sdks: + dart: ">=3.11.3 <4.0.0" + flutter: ">=3.22.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml new file mode 100644 index 0000000..71b15f3 --- /dev/null +++ b/example/pubspec.yaml @@ -0,0 +1,85 @@ +name: mattermost_push_plugin_example +description: "Demonstrates how to use the mattermost_push_plugin plugin." +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +environment: + sdk: ^3.11.3 + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + mattermost_push_plugin: + # When depending on this package from a real application you should use: + # mattermost_push_plugin: ^x.y.z + # See https://dart.dev/tools/pub/dependencies#version-constraints + # The example app is bundled with the plugin so we use a path dependency on + # the parent directory to use the current plugin's version. + path: ../ + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.8 + +dev_dependencies: + integration_test: + sdk: flutter + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^6.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/to/resolution-aware-images + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/to/asset-from-package + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/to/font-from-package diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart new file mode 100644 index 0000000..bfcef05 --- /dev/null +++ b/example/test/widget_test.dart @@ -0,0 +1,19 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:mattermost_push_plugin_example/main.dart'; + +void main() { + testWidgets('renders pending device token placeholder', + (WidgetTester tester) async { + await tester.pumpWidget(const MyApp()); + + expect( + find.byWidgetPredicate( + (Widget widget) => + widget is Text && (widget.data?.startsWith('Device token:') ?? false), + ), + findsOneWidget, + ); + }); +} diff --git a/ios/.gitignore b/ios/.gitignore new file mode 100644 index 0000000..034771f --- /dev/null +++ b/ios/.gitignore @@ -0,0 +1,38 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +.generated/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/Generated.xcconfig +/Flutter/ephemeral/ +/Flutter/flutter_export_environment.sh diff --git a/ios/Assets/.gitkeep b/ios/Assets/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/ios/Classes/MattermostPushPlugin.swift b/ios/Classes/MattermostPushPlugin.swift new file mode 100644 index 0000000..4d190a7 --- /dev/null +++ b/ios/Classes/MattermostPushPlugin.swift @@ -0,0 +1,19 @@ +import Flutter +import UIKit + +public class MattermostPushPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "mattermost_push_plugin", binaryMessenger: registrar.messenger()) + let instance = MattermostPushPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + switch call.method { + case "getPlatformVersion": + result("iOS " + UIDevice.current.systemVersion) + default: + result(FlutterMethodNotImplemented) + } + } +} diff --git a/ios/Resources/PrivacyInfo.xcprivacy b/ios/Resources/PrivacyInfo.xcprivacy new file mode 100644 index 0000000..a34b7e2 --- /dev/null +++ b/ios/Resources/PrivacyInfo.xcprivacy @@ -0,0 +1,14 @@ + + + + + NSPrivacyTrackingDomains + + NSPrivacyAccessedAPITypes + + NSPrivacyCollectedDataTypes + + NSPrivacyTracking + + + diff --git a/ios/mattermost_push_plugin.podspec b/ios/mattermost_push_plugin.podspec new file mode 100644 index 0000000..eedefa2 --- /dev/null +++ b/ios/mattermost_push_plugin.podspec @@ -0,0 +1,29 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint mattermost_push_plugin.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'mattermost_push_plugin' + s.version = '0.0.1' + s.summary = 'A new Flutter plugin project.' + s.description = <<-DESC +A new Flutter plugin project. + DESC + s.homepage = 'http://example.com' + s.license = { :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + s.dependency 'Flutter' + s.platform = :ios, '13.0' + + # Flutter.framework does not contain a i386 slice. + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } + s.swift_version = '5.0' + + # If your plugin requires a privacy manifest, for example if it uses any + # required reason APIs, update the PrivacyInfo.xcprivacy file to describe your + # plugin's privacy impact, and then uncomment this line. For more information, + # see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files + # s.resource_bundles = {'mattermost_push_plugin_privacy' => ['Resources/PrivacyInfo.xcprivacy']} +end diff --git a/lib/mattermost_push_plugin.dart b/lib/mattermost_push_plugin.dart new file mode 100644 index 0000000..b4cf623 --- /dev/null +++ b/lib/mattermost_push_plugin.dart @@ -0,0 +1,3 @@ +export 'src/mattermost_push_plugin.dart'; +export 'src/notification_opened_event.dart'; +export 'src/push_notification_type.dart'; diff --git a/lib/src/mattermost_push_plugin.dart b/lib/src/mattermost_push_plugin.dart new file mode 100644 index 0000000..e8346ee --- /dev/null +++ b/lib/src/mattermost_push_plugin.dart @@ -0,0 +1,218 @@ +import 'dart:async'; + +import 'package:firebase_messaging/firebase_messaging.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'notification_opened_event.dart'; +import 'push_notification_type.dart'; + +const String _kNotificationChannelName = + 'com.tokilabs.mattermost/notifications'; +const String _kActionChannelName = + 'com.tokilabs.mattermost/notification_actions'; +const String _kDeviceTokenPrefix = 'android_rn'; + +class MattermostPushPlugin { + MattermostPushPlugin._(); + static final MattermostPushPlugin instance = MattermostPushPlugin._(); + + @visibleForTesting + static const String notificationChannelName = _kNotificationChannelName; + @visibleForTesting + static const String actionChannelName = _kActionChannelName; + + static const EventChannel _notificationChannel = EventChannel( + _kNotificationChannelName, + ); + static const MethodChannel _actionChannel = MethodChannel( + _kActionChannelName, + ); + + StreamSubscription? _channelSubscription; + + final StreamController> _notificationController = + StreamController>.broadcast(); + Stream> get onNotification => + _notificationController.stream; + + final StreamController _openedController = + StreamController.broadcast(); + Stream get onNotificationOpened => + _openedController.stream; + + void Function(String serverUrl, String channelId)? onNavigateToChannel; + void Function(String serverUrl, String rootId)? onNavigateToThread; + void Function(String deviceToken)? onDeviceTokenReady; + + Future initialize() async { + _listenNativeChannel(); + _listenFcmTokenRefresh(); + await _requestPermission(); + } + + void dispose() { + _channelSubscription?.cancel(); + _notificationController.close(); + _openedController.close(); + } + + void _listenNativeChannel() { + _channelSubscription = _notificationChannel.receiveBroadcastStream().listen( + (dynamic event) { + if (event is Map) { + handleNativeEvent(Map.from(event)); + } + }, + onError: (error) => + debugPrint('[PushNotification] EventChannel error: $error'), + ); + } + + void _listenFcmTokenRefresh() { + FirebaseMessaging.instance.onTokenRefresh.listen((token) async { + await _saveDeviceToken(token); + }); + } + + Future _requestPermission() async { + final settings = await FirebaseMessaging.instance.requestPermission( + alert: true, + badge: true, + sound: true, + ); + debugPrint( + '[PushNotification] Permission: ${settings.authorizationStatus}', + ); + + final token = await FirebaseMessaging.instance.getToken(); + if (token != null) await _saveDeviceToken(token); + } + + @visibleForTesting + void handleNativeEvent(Map data) { + final type = data['type'] as String?; + + switch (type) { + case PushNotificationType.message: + _handleMessageNotification(data); + break; + case PushNotificationType.clear: + _handleClearNotification(data); + break; + case PushNotificationType.session: + _handleSessionNotification(data); + break; + case PushNotificationType.tokenRefresh: + final token = data['token'] as String?; + if (token != null) _saveDeviceToken(token); + break; + case PushNotificationType.opened: + _handleNotificationOpened(data); + break; + } + + if (!_notificationController.isClosed) { + _notificationController.add(data); + } + } + + void _handleMessageNotification(Map data) { + final isUserInteraction = data['userInteraction'] == true; + if (isUserInteraction) { + _handleNotificationOpened(data); + } + } + + void _handleClearNotification(Map data) { + debugPrint('[PushNotification] Clear: channelId=${data['channel_id']}'); + } + + void _handleSessionNotification(Map data) { + debugPrint( + '[PushNotification] Session expired: serverUrl=${data['server_url']}', + ); + } + + void _handleNotificationOpened(Map data) { + final event = NotificationOpenedEvent.fromMap(data); + + debugPrint( + '[PushNotification] Opened: channelId=${event.channelId} rootId=${event.rootId}', + ); + + if (!_openedController.isClosed) { + _openedController.add(event); + } + + final serverUrl = event.serverUrl; + if (serverUrl == null) return; + + if (event.isCRTEnabled && + event.rootId != null && + event.rootId!.isNotEmpty) { + onNavigateToThread?.call(serverUrl, event.rootId!); + } else if (event.channelId != null) { + onNavigateToChannel?.call(serverUrl, event.channelId!); + } + } + + Future setAuthToken( + String serverUrl, + String token, { + String? identifier, + }) async { + try { + await _actionChannel.invokeMethod('setAuthToken', { + 'serverUrl': serverUrl, + 'token': token, + 'identifier': identifier, + }); + debugPrint('[PushNotification] Auth token saved for $serverUrl'); + } catch (e) { + debugPrint('[PushNotification] Failed to save auth token: $e'); + } + } + + Future clearAuthToken(String serverUrl) async { + try { + await _actionChannel.invokeMethod('clearAuthToken', { + 'serverUrl': serverUrl, + }); + } catch (e) { + debugPrint('[PushNotification] Failed to clear auth token: $e'); + } + } + + Future setSigningKey(String serverUrl, String signingKey) async { + try { + await _actionChannel.invokeMethod('setSigningKey', { + 'serverUrl': serverUrl, + 'signingKey': signingKey, + }); + } catch (e) { + debugPrint('[PushNotification] Failed to save signing key: $e'); + } + } + + Future _saveDeviceToken(String token) async { + try { + final formattedToken = '$_kDeviceTokenPrefix-v2:$token'; + await _actionChannel.invokeMethod('saveDeviceToken', { + 'token': formattedToken, + }); + debugPrint('[PushNotification] Device token saved'); + onDeviceTokenReady?.call(formattedToken); + } catch (e) { + debugPrint('[PushNotification] Failed to save device token: $e'); + } + } + + Future getDeviceToken() async { + try { + return await _actionChannel.invokeMethod('getDeviceToken'); + } catch (e) { + return null; + } + } +} diff --git a/lib/src/notification_opened_event.dart b/lib/src/notification_opened_event.dart new file mode 100644 index 0000000..54d201c --- /dev/null +++ b/lib/src/notification_opened_event.dart @@ -0,0 +1,22 @@ +class NotificationOpenedEvent { + final String? serverUrl; + final String? channelId; + final String? rootId; + final bool isCRTEnabled; + + const NotificationOpenedEvent({ + this.serverUrl, + this.channelId, + this.rootId, + this.isCRTEnabled = false, + }); + + factory NotificationOpenedEvent.fromMap(Map data) { + return NotificationOpenedEvent( + serverUrl: data['server_url'] as String?, + channelId: data['channel_id'] as String?, + rootId: data['root_id'] as String?, + isCRTEnabled: data['is_crt_enabled'] == 'true', + ); + } +} diff --git a/lib/src/push_notification_type.dart b/lib/src/push_notification_type.dart new file mode 100644 index 0000000..7dc9279 --- /dev/null +++ b/lib/src/push_notification_type.dart @@ -0,0 +1,7 @@ +class PushNotificationType { + static const String message = 'message'; + static const String clear = 'clear'; + static const String session = 'session'; + static const String tokenRefresh = 'token_refresh'; + static const String opened = 'opened'; +} diff --git a/macos/Classes/MattermostPushPlugin.swift b/macos/Classes/MattermostPushPlugin.swift new file mode 100644 index 0000000..941cc80 --- /dev/null +++ b/macos/Classes/MattermostPushPlugin.swift @@ -0,0 +1,19 @@ +import Cocoa +import FlutterMacOS + +public class MattermostPushPlugin: NSObject, FlutterPlugin { + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "mattermost_push_plugin", binaryMessenger: registrar.messenger) + let instance = MattermostPushPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + switch call.method { + case "getPlatformVersion": + result("macOS " + ProcessInfo.processInfo.operatingSystemVersionString) + default: + result(FlutterMethodNotImplemented) + } + } +} diff --git a/macos/Resources/PrivacyInfo.xcprivacy b/macos/Resources/PrivacyInfo.xcprivacy new file mode 100644 index 0000000..918d80b --- /dev/null +++ b/macos/Resources/PrivacyInfo.xcprivacy @@ -0,0 +1,12 @@ + + + + + NSPrivacyTrackingDomains + + NSPrivacyCollectedDataTypes + + NSPrivacyTracking + + + diff --git a/macos/mattermost_push_plugin.podspec b/macos/mattermost_push_plugin.podspec new file mode 100644 index 0000000..0b5426b --- /dev/null +++ b/macos/mattermost_push_plugin.podspec @@ -0,0 +1,30 @@ +# +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. +# Run `pod lib lint mattermost_push_plugin.podspec` to validate before publishing. +# +Pod::Spec.new do |s| + s.name = 'mattermost_push_plugin' + s.version = '0.0.1' + s.summary = 'A new Flutter plugin project.' + s.description = <<-DESC +A new Flutter plugin project. + DESC + s.homepage = 'http://example.com' + s.license = { :file => '../LICENSE' } + s.author = { 'Your Company' => 'email@example.com' } + + s.source = { :path => '.' } + s.source_files = 'Classes/**/*' + + # If your plugin requires a privacy manifest, for example if it collects user + # data, update the PrivacyInfo.xcprivacy file to describe your plugin's + # privacy impact, and then uncomment this line. For more information, + # see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files + # s.resource_bundles = {'mattermost_push_plugin_privacy' => ['Resources/PrivacyInfo.xcprivacy']} + + s.dependency 'FlutterMacOS' + + s.platform = :osx, '10.11' + s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } + s.swift_version = '5.0' +end diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..9e9d32b --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,30 @@ +name: mattermost_push_plugin +description: "Mattermost push notification Flutter plugin. Android-first; iOS/macOS scaffold only." +version: 0.0.1 +publish_to: 'none' +homepage: + +environment: + sdk: ^3.11.3 + flutter: '>=3.3.0' + +dependencies: + flutter: + sdk: flutter + firebase_messaging: ^15.2.5 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^6.0.0 + +flutter: + plugin: + platforms: + android: + package: com.tokilabs.mattermost_push_plugin + pluginClass: MattermostPushPlugin + ios: + pluginClass: MattermostPushPlugin + macos: + pluginClass: MattermostPushPlugin diff --git a/test/mattermost_push_plugin_test.dart b/test/mattermost_push_plugin_test.dart new file mode 100644 index 0000000..b9edadf --- /dev/null +++ b/test/mattermost_push_plugin_test.dart @@ -0,0 +1,179 @@ +import 'dart:async'; + +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mattermost_push_plugin/mattermost_push_plugin.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + group('NotificationOpenedEvent.fromMap', () { + test('parses server_url, channel_id, root_id, is_crt_enabled', () { + final event = NotificationOpenedEvent.fromMap({ + 'server_url': 'https://mm.example.com', + 'channel_id': 'channel-123', + 'root_id': 'root-456', + 'is_crt_enabled': 'true', + }); + + expect(event.serverUrl, 'https://mm.example.com'); + expect(event.channelId, 'channel-123'); + expect(event.rootId, 'root-456'); + expect(event.isCRTEnabled, isTrue); + }); + + test('defaults isCRTEnabled to false when flag is absent or non-true', () { + final missing = NotificationOpenedEvent.fromMap({ + 'server_url': 'https://mm.example.com', + 'channel_id': 'channel-123', + }); + expect(missing.isCRTEnabled, isFalse); + + final falsy = NotificationOpenedEvent.fromMap({ + 'is_crt_enabled': 'false', + }); + expect(falsy.isCRTEnabled, isFalse); + }); + }); + + group('MattermostPushPlugin.handleNativeEvent', () { + late MattermostPushPlugin plugin; + final actionChannel = MethodChannel(MattermostPushPlugin.actionChannelName); + + setUp(() { + plugin = MattermostPushPlugin.instance; + plugin.onNavigateToChannel = null; + plugin.onNavigateToThread = null; + plugin.onDeviceTokenReady = null; + }); + + tearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(actionChannel, null); + }); + + test('opened event emits NotificationOpenedEvent on stream', () async { + final future = plugin.onNotificationOpened.first; + + plugin.handleNativeEvent({ + 'type': PushNotificationType.opened, + 'server_url': 'https://mm.example.com', + 'channel_id': 'channel-123', + }); + + final event = await future; + expect(event.serverUrl, 'https://mm.example.com'); + expect(event.channelId, 'channel-123'); + }); + + test( + 'message event with userInteraction routes through opened handler', + () async { + String? navServer; + String? navChannel; + plugin.onNavigateToChannel = (s, c) { + navServer = s; + navChannel = c; + }; + + plugin.handleNativeEvent({ + 'type': PushNotificationType.message, + 'userInteraction': true, + 'server_url': 'https://mm.example.com', + 'channel_id': 'channel-xyz', + }); + + expect(navServer, 'https://mm.example.com'); + expect(navChannel, 'channel-xyz'); + }, + ); + + test('opened event with CRT and rootId routes to thread callback', () { + String? navServer; + String? navRoot; + plugin.onNavigateToThread = (s, r) { + navServer = s; + navRoot = r; + }; + + plugin.handleNativeEvent({ + 'type': PushNotificationType.opened, + 'server_url': 'https://mm.example.com', + 'channel_id': 'channel-123', + 'root_id': 'root-789', + 'is_crt_enabled': 'true', + }); + + expect(navServer, 'https://mm.example.com'); + expect(navRoot, 'root-789'); + }); + + test('opened event without server_url skips navigation callbacks', () { + var channelCalled = false; + var threadCalled = false; + plugin.onNavigateToChannel = (_, _) => channelCalled = true; + plugin.onNavigateToThread = (_, _) => threadCalled = true; + + plugin.handleNativeEvent({ + 'type': PushNotificationType.opened, + 'channel_id': 'channel-123', + }); + + expect(channelCalled, isFalse); + expect(threadCalled, isFalse); + }); + + test('every event is forwarded to onNotification stream', () async { + final future = plugin.onNotification.first; + + plugin.handleNativeEvent({ + 'type': PushNotificationType.clear, + 'channel_id': 'channel-123', + }); + + final raw = await future; + expect(raw['type'], PushNotificationType.clear); + expect(raw['channel_id'], 'channel-123'); + }); + + test( + 'token_refresh event saves formatted device token and invokes callback', + () async { + String? channelToken; + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(actionChannel, (call) async { + if (call.method == 'saveDeviceToken') { + final args = call.arguments as Map; + channelToken = args['token'] as String?; + } + return null; + }); + + final completer = Completer(); + plugin.onDeviceTokenReady = completer.complete; + + plugin.handleNativeEvent({ + 'type': PushNotificationType.tokenRefresh, + 'token': 'raw-token', + }); + + final callbackToken = await completer.future; + expect(channelToken, 'android_rn-v2:raw-token'); + expect(callbackToken, 'android_rn-v2:raw-token'); + }, + ); + }); + + group('Channel constants', () { + test('notification and action channel names are preserved', () { + expect( + MattermostPushPlugin.notificationChannelName, + 'com.tokilabs.mattermost/notifications', + ); + expect( + MattermostPushPlugin.actionChannelName, + 'com.tokilabs.mattermost/notification_actions', + ); + }); + }); +}