Skip to content

Commit 9b32652

Browse files
committed
Merge branch 'feature/archiving-messages'
2 parents 8a959c9 + 01055bb commit 9b32652

39 files changed

+2103
-472
lines changed

.vscode/launch.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "courier_flutter",
9+
"request": "launch",
10+
"type": "dart"
11+
},
12+
{
13+
"name": "courier_flutter (profile mode)",
14+
"request": "launch",
15+
"type": "dart",
16+
"flutterMode": "profile"
17+
},
18+
{
19+
"name": "courier_flutter (release mode)",
20+
"request": "launch",
21+
"type": "dart",
22+
"flutterMode": "release"
23+
},
24+
{
25+
"name": "example",
26+
"cwd": "example",
27+
"request": "launch",
28+
"type": "dart"
29+
},
30+
{
31+
"name": "example (profile mode)",
32+
"cwd": "example",
33+
"request": "launch",
34+
"type": "dart",
35+
"flutterMode": "profile"
36+
},
37+
{
38+
"name": "example (release mode)",
39+
"cwd": "example",
40+
"request": "launch",
41+
"type": "dart",
42+
"flutterMode": "release"
43+
}
44+
]
45+
}

android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ buildscript {
1111
}
1212

1313
dependencies {
14-
classpath 'com.android.tools.build:gradle:7.1.3'
14+
classpath 'com.android.tools.build:gradle:8.1.4'
1515
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1616
}
1717
}
@@ -28,7 +28,7 @@ apply plugin: 'kotlin-android'
2828

2929
android {
3030

31-
compileSdkVersion 34
31+
compileSdk 34
3232

3333
defaultConfig {
3434
minSdkVersion 23
@@ -51,6 +51,6 @@ android {
5151

5252
dependencies {
5353
implementation 'com.google.code.gson:gson:2.11.0'
54-
api 'com.github.trycourier:courier-android:4.4.1'
55-
api 'com.google.firebase:firebase-messaging-ktx:24.0.0'
54+
api 'com.github.trycourier:courier-android:5.1.8'
55+
api 'com.google.firebase:firebase-messaging-ktx:24.1.0'
5656
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

android/src/main/kotlin/com/courier/courier_flutter/SharedMethodHandler.kt

Lines changed: 101 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import com.courier.android.models.remove
77
import com.courier.android.modules.addAuthenticationListener
88
import com.courier.android.modules.addInboxListener
99
import com.courier.android.modules.archiveMessage
10+
import com.courier.android.modules.archivedMessages
1011
import com.courier.android.modules.clickMessage
1112
import com.courier.android.modules.fcmToken
13+
import com.courier.android.modules.feedMessages
1214
import com.courier.android.modules.fetchNextInboxPage
1315
import com.courier.android.modules.getToken
1416
import com.courier.android.modules.inboxPaginationLimit
@@ -24,6 +26,7 @@ import com.courier.android.modules.tenantId
2426
import com.courier.android.modules.tokens
2527
import com.courier.android.modules.unreadMessage
2628
import com.courier.android.modules.userId
29+
import com.courier.android.ui.inbox.InboxMessageFeed
2730
import com.courier.courier_flutter.CourierPlugin.Companion.TAG
2831
import io.flutter.embedding.engine.plugins.FlutterPlugin
2932
import io.flutter.plugin.common.MethodCall
@@ -123,7 +126,8 @@ internal class SharedMethodHandler(channel: CourierFlutterChannel, private val b
123126
// Create the listener
124127
val listener = Courier.shared.addAuthenticationListener { userId ->
125128
CourierFlutterChannel.EVENTS.invokeMethod(binding.binaryMessenger, method = "auth.state_changed", mapOf(
126-
"userId" to userId
129+
"userId" to userId,
130+
"id" to listenerId
127131
))
128132
}
129133

@@ -230,9 +234,19 @@ internal class SharedMethodHandler(channel: CourierFlutterChannel, private val b
230234

231235
}
232236

233-
"inbox.get_messages" -> {
237+
"inbox.get_feed_messages" -> {
234238

235-
val messages = Courier.shared.inboxMessages ?: emptyList()
239+
val messages = Courier.shared.feedMessages
240+
241+
val json = messages.map { it.toJson() }
242+
243+
result.success(json)
244+
245+
}
246+
247+
"inbox.get_archived_messages" -> {
248+
249+
val messages = Courier.shared.archivedMessages
236250

237251
val json = messages.map { it.toJson() }
238252

@@ -250,9 +264,15 @@ internal class SharedMethodHandler(channel: CourierFlutterChannel, private val b
250264

251265
"inbox.fetch_next_page" -> {
252266

253-
val messages = Courier.shared.fetchNextInboxPage()
267+
val params = call.arguments as? HashMap<*, *> ?: throw MissingParameter("params")
254268

255-
val json = messages.map { it.toJson() }
269+
val feed = params.extract("feed") as String
270+
271+
val inboxFeed = if (feed == "archived") InboxMessageFeed.ARCHIVE else InboxMessageFeed.FEED
272+
273+
val res = Courier.shared.fetchNextInboxPage(feed = inboxFeed)
274+
275+
val json = res?.toJson()
256276

257277
result.success(json)
258278

@@ -265,31 +285,99 @@ internal class SharedMethodHandler(channel: CourierFlutterChannel, private val b
265285
val listenerId = params.extract("listenerId") as String
266286

267287
val listener = Courier.shared.addInboxListener(
268-
onInitialLoad = {
288+
onLoading = {
269289
CourierFlutterChannel.EVENTS.invokeMethod(
270290
messenger = binding.binaryMessenger,
271291
method = "auth.state_changed",
272-
arguments = null
292+
arguments = mapOf(
293+
"id" to listenerId
294+
)
273295
)
274296
},
275297
onError = { error ->
276298
CourierFlutterChannel.EVENTS.invokeMethod(
277299
messenger = binding.binaryMessenger,
278300
method = "inbox.listener_error",
279301
arguments = mapOf(
302+
"id" to listenerId,
280303
"error" to error.message
281304
)
282305
)
283306
},
284-
onMessagesChanged = { messages, unreadMessageCount, totalMessageCount, canPaginate ->
307+
onUnreadCountChanged = { count ->
308+
CourierFlutterChannel.EVENTS.invokeMethod(
309+
messenger = binding.binaryMessenger,
310+
method = "inbox.listener_unread_count_changed",
311+
arguments = mapOf(
312+
"id" to listenerId,
313+
"count" to count
314+
)
315+
)
316+
},
317+
onFeedChanged = { messageSet ->
318+
CourierFlutterChannel.EVENTS.invokeMethod(
319+
messenger = binding.binaryMessenger,
320+
method = "inbox.listener_feed_changed",
321+
arguments = mapOf(
322+
"id" to listenerId,
323+
"messageSet" to messageSet.toJson(),
324+
)
325+
)
326+
},
327+
onArchiveChanged = { messageSet ->
328+
CourierFlutterChannel.EVENTS.invokeMethod(
329+
messenger = binding.binaryMessenger,
330+
method = "inbox.listener_archive_changed",
331+
arguments = mapOf(
332+
"id" to listenerId,
333+
"messageSet" to messageSet.toJson(),
334+
)
335+
)
336+
},
337+
onPageAdded = { feed, page ->
338+
CourierFlutterChannel.EVENTS.invokeMethod(
339+
messenger = binding.binaryMessenger,
340+
method = "inbox.listener_page_added",
341+
arguments = mapOf(
342+
"id" to listenerId,
343+
"feed" to if (feed == InboxMessageFeed.ARCHIVE) "archived" else "feed",
344+
"page" to page.toJson(),
345+
)
346+
)
347+
},
348+
onMessageChanged = { feed, index, message ->
349+
CourierFlutterChannel.EVENTS.invokeMethod(
350+
messenger = binding.binaryMessenger,
351+
method = "inbox.listener_message_changed",
352+
arguments = mapOf(
353+
"id" to listenerId,
354+
"feed" to if (feed == InboxMessageFeed.ARCHIVE) "archived" else "feed",
355+
"index" to index,
356+
"message" to message.toJson(),
357+
)
358+
)
359+
},
360+
onMessageAdded = { feed, index, message ->
361+
CourierFlutterChannel.EVENTS.invokeMethod(
362+
messenger = binding.binaryMessenger,
363+
method = "inbox.listener_message_added",
364+
arguments = mapOf(
365+
"id" to listenerId,
366+
"feed" to if (feed == InboxMessageFeed.ARCHIVE) "archived" else "feed",
367+
"index" to index,
368+
"message" to message.toJson(),
369+
)
370+
)
371+
},
372+
onMessageRemoved = { feed, index, message ->
285373
CourierFlutterChannel.EVENTS.invokeMethod(
286374
messenger = binding.binaryMessenger,
287-
method = "inbox.listener_messages_changed",
375+
method = "inbox.listener_message_removed",
288376
arguments = mapOf(
289-
"messages" to messages.map { it.toJson() },
290-
"unreadMessageCount" to unreadMessageCount,
291-
"totalMessageCount" to totalMessageCount,
292-
"canPaginate" to canPaginate,
377+
"id" to listenerId,
378+
"feed" to if (feed == InboxMessageFeed.ARCHIVE) "archived" else "feed",
379+
"index" to index,
380+
"message" to message.toJson(),
293381
)
294382
)
295383
}

example/android/app/build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ if (keystorePropertiesFile.exists()) {
3535
}
3636

3737
android {
38-
compileSdkVersion flutter.compileSdkVersion
38+
39+
compileSdkVersion 34
40+
compileSdk 34
3941
ndkVersion flutter.ndkVersion
4042

4143
compileOptions {
42-
sourceCompatibility JavaVersion.VERSION_1_8
43-
targetCompatibility JavaVersion.VERSION_1_8
44+
sourceCompatibility JavaVersion.VERSION_17
45+
targetCompatibility JavaVersion.VERSION_17
4446
}
4547

4648
kotlinOptions {
47-
jvmTarget = '1.8'
49+
jvmTarget = '17'
4850
}
4951

5052
sourceSets {
@@ -60,7 +62,7 @@ android {
6062
// TODO: Updates needed to support the Courier android package
6163
minSdkVersion 23
6264
targetSdkVersion 34
63-
compileSdkVersion 34
65+
targetSdk 34
6466

6567
versionCode flutterVersionCode.toInteger()
6668
versionName flutterVersionName

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.courier.courier_flutter_sample">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- The INTERNET permission is required for development. Specifically,
43
the Flutter tool needs it to communicate with the running application
54
to allow setting breakpoints, to provide hot reload, etc.

example/android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.courier.courier_flutter_sample">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32

43
<uses-permission android:name="android.permission.INTERNET" />
54

@@ -11,7 +10,7 @@
1110
android:name="${applicationName}"
1211
android:icon="@mipmap/ic_launcher">
1312
<activity
14-
android:name="com.courier.courier_flutter_sample.MainActivity"
13+
android:name="com.courier.courier_flutter.MainActivity"
1514
android:exported="true"
1615
android:launchMode="singleTop"
1716
android:theme="@style/LaunchTheme"
@@ -33,7 +32,7 @@
3332
</activity>
3433

3534
<service
36-
android:name="com.courier.courier_flutter_sample.ExampleService"
35+
android:name="com.courier.courier_flutter.ExampleService"
3736
android:exported="false">
3837
<intent-filter>
3938
<action android:name="com.google.firebase.MESSAGING_EVENT" />

example/android/app/src/main/kotlin/com/courier/courier_flutter_sample/ExampleService.kt renamed to example/android/app/src/main/kotlin/com/courier/courier_flutter/ExampleService.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
package com.courier.courier_flutter_sample
1+
package com.courier.courier_flutter
22

33
import android.annotation.SuppressLint
4-
import com.courier.android.notifications.presentNotification
54
import com.courier.android.service.CourierService
65
import com.google.firebase.messaging.RemoteMessage
76

@@ -21,11 +20,11 @@ class ExampleService: CourierService() {
2120
// For details on how to customize an Android notification, check here:
2221
// https://developer.android.com/develop/ui/views/notifications/build-notification
2322

24-
message.presentNotification(
25-
context = this,
26-
handlingClass = MainActivity::class.java,
27-
icon = android.R.drawable.ic_dialog_info
28-
)
23+
// message.presentNotification(
24+
// context = this,
25+
// handlingClass = MainActivity::class.java,
26+
// icon = android.R.drawable.ic_dialog_dialer
27+
// )
2928

3029
}
3130

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.courier.courier_flutter
2+
3+
class MainActivity: CourierFlutterActivity()

example/android/app/src/main/kotlin/com/courier/courier_flutter_sample/MainActivity.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)