Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/code-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Code Formatting

on:
push:

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Dart
uses: dart-lang/setup-dart@v1
with:
sdk: stable

- name: Run format check
run: make format-check
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## UPCOMING

**Plugin**
- Updated Batch to 3.3

**Profile**
- Added `setTopicPreferences(List<String>? topics)` to `BatchProfileAttributeEditor` class to set or reset the profile topic preferences.
- Added `addToTopicPreferences(List<String> topics)` to `BatchProfileAttributeEditor` class to add topics to the profile topic preferences.
- Added `removeFromTopicPreferences(List<String> topics)` to `BatchProfileAttributeEditor` class to remove topics from the profile topic preferences.

**Push**
- Added `requestNotificationAuthorizationAsync()`to request notification authorization and return a promise that resolve with the authorization result.

Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: docs doc doc-ios doc-android build-ios-doc setup-build-ios flutter-setup
.PHONY: docs doc doc-ios doc-android build-ios-doc setup-build-ios flutter-setup format format-check

# Common Flutter setup - run once to avoid redundancy
flutter-setup:
Expand Down Expand Up @@ -82,3 +82,9 @@ doc-ios: build-ios-doc
doc-android:
rm -rf api_docs/flutter-android-api-reference
cd example/android && ./gradlew :batch_flutter:generateJavadocRelease

format:
dart format lib

format-check:
dart format lib -o none --set-exit-if-changed
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
formatter:
page_width: 100
trailing_commas: preserve
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ android {
}

dependencies {
api 'com.batch.android:batch-sdk:3.1.+'
api 'com.batch.android:batch-sdk:3.3.+'
//noinspection GradleDynamicVersion
implementation 'androidx.appcompat:appcompat:1.2.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@ private static void editProfileAttributes(Map<String, Object> parameters) throws
}
break;
}
case "SET_TOPIC_PREFERENCES": {
Object value = operationDescription.get("value");
if (value == null) {
editor.setTopicPreferences(null);
break;
}

editor.setTopicPreferences(new ArrayList<>(getTypedParameter(operationDescription, "value", ArrayList.class)));
break;
}
case "ADD_TO_TOPIC_PREFERENCES": {
editor.addToTopicPreferences(new ArrayList<>(getTypedParameter(operationDescription, "value", ArrayList.class)));
break;
}
case "REMOVE_FROM_TOPIC_PREFERENCES": {
editor.removeFromTopicPreferences(new ArrayList<>(getTypedParameter(operationDescription, "value", ArrayList.class)));
break;
}
case "SET_ATTRIBUTE": {
String key = getTypedParameter(operationDescription, "key", String.class);
String type = getTypedParameter(operationDescription, "type", String.class);
Expand Down
16 changes: 8 additions & 8 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PODS:
- Batch (3.1.0)
- Batch (3.3.0)
- batch_flutter (3.0.0):
- Batch (~> 3.1.0)
- Batch (~> 3.3.0)
- Flutter
- batch_flutter/Tests (3.0.0):
- Batch (~> 3.1.0)
- Batch (~> 3.3.0)
- Flutter
- BatchExtension (4.0.0)
- Flutter (1.0.0)
Expand Down Expand Up @@ -33,12 +33,12 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"

SPEC CHECKSUMS:
Batch: 47c1df1f301078fc01b9f9531faeed8f18a9bac0
batch_flutter: 8ee966aebb5c381bf990f60abe7b6aabb1cc51f2
Batch: eadfdd781276a94730fc456abb994c259b8dc2ac
batch_flutter: 52cc6d3d6fd8deb163c43c3ebb6768683e3182f5
BatchExtension: ee10c31cc737d66a9c339a1e70e7c787b5988676
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78

PODFILE CHECKSUM: 41d7fb270f6b26ab3bf4c5441ef0bb80b305699a

COCOAPODS: 1.16.2
COCOAPODS: 1.15.2
4 changes: 4 additions & 0 deletions example/lib/plugin_test_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class _PluginTestMenuState extends State<PluginTestMenu> {
.removeFromArray("push_optin", "handball")
.setLanguage("pt")
.setRegion("BR")
.setTopicPreferences(["topic3", "topic1"])
.addToTopicPreferences(["topic2"])
.removeFromTopicPreferences(["topic3"])
.save();
}

Expand All @@ -158,6 +161,7 @@ class _PluginTestMenuState extends State<PluginTestMenu> {
.setPhoneNumber(null)
.setLanguage(null)
.setRegion(null)
.setTopicPreferences(null)
.save();
BatchUser.instance.clearInstallationData();
}
Expand Down
2 changes: 1 addition & 1 deletion ios/batch_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.source = { :path => '.' }
s.source_files = 'batch_flutter/Sources/batch_flutter/**/*'
s.dependency 'Flutter'
s.dependency 'Batch', '~> 3.1.0'
s.dependency 'Batch', '~> 3.3.0'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
Expand Down
4 changes: 2 additions & 2 deletions ios/batch_flutter/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ios/batch_flutter/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
.library(name: "batch-flutter", targets: ["batch_flutter"]),
],
dependencies: [
.package(url: "https://github.com/BatchLabs/Batch-iOS-SDK", from: "3.1.0"),
.package(url: "https://github.com/BatchLabs/Batch-iOS-SDK", from: "3.3.0"),
],
targets: [
.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ extension Bridge {
case setEmailMarketingSubscription = "SET_EMAIL_MARKETING_SUBSCRIPTION"
case setPhoneNumber = "SET_PHONE_NUMBER"
case setSMSMarketingSubscription = "SET_SMS_MARKETING_SUBSCRIPTION"
case setTopicPreferences = "SET_TOPIC_PREFERENCES"
case addToTopicPreferences = "ADD_TO_TOPIC_PREFERENCES"
case removeFromTopicPreferences = "REMOVE_FROM_TOPIC_PREFERENCES"
case setAttribute = "SET_ATTRIBUTE"
case removeAttribute = "REMOVE_ATTRIBUTE"
case addToStringArray = "ADD_TO_ARRAY"
Expand Down Expand Up @@ -106,6 +109,29 @@ extension Bridge {
throw BridgeError.makeBadArgumentError(argumentName: rawOperation + ".value")
}
break;
case .setTopicPreferences:
let rawValue = operationDescription["value"]
if rawValue == nil || rawValue is NSNull {
try? profileAttributeEditor.setTopicPreferences(nil)
} else {
guard let value = rawValue as? [String] else {
throw BridgeError.makeBadArgumentError(argumentName: rawOperation + ".value")
}
try? profileAttributeEditor.setTopicPreferences(value)
}
break;
case .addToTopicPreferences:
guard let value = operationDescription["value"] as? [String] else {
throw BridgeError.makeBadArgumentError(argumentName: rawOperation + ".value")
}
try? profileAttributeEditor.addToTopicPreferences(value)
break;
case .removeFromTopicPreferences:
guard let value = operationDescription["value"] as? [String] else {
throw BridgeError.makeBadArgumentError(argumentName: rawOperation + ".value")
}
try? profileAttributeEditor.removeFromTopicPreferences(value)
break;
case .setLanguage:
let rawValue = operationDescription["value"]
if rawValue == nil || rawValue is NSNull {
Expand Down
3 changes: 2 additions & 1 deletion lib/batch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Batch {
/// });
/// ```
void setAutomaticDataCollection(Map<String, bool> dataCollectionConfig) {
_channel.invokeMethod('setAutomaticDataCollection', {"dataCollectionConfig": dataCollectionConfig});
_channel
.invokeMethod('setAutomaticDataCollection', {"dataCollectionConfig": dataCollectionConfig});
}
}
22 changes: 8 additions & 14 deletions lib/batch_inbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class BatchInbox {
/// Set [limit] to be the maximum number of notifications to fetch, ever.
/// This allows you to let Batch manage the upper limit itself, so you can
/// be sure not to use a crazy amount of memory.
Future<BatchInboxFetcher> getFetcherForInstallation(
{int? maxPageSize, int? limit}) async {
Future<BatchInboxFetcher> getFetcherForInstallation({int? maxPageSize, int? limit}) async {
var fetcher = BatchInboxFetcherInstallationImpl();
await fetcher.init(maxPageSize: maxPageSize, limit: limit);
return fetcher;
Expand All @@ -42,8 +41,7 @@ class BatchInbox {
required String authenticationKey,
int? maxPageSize,
int? limit}) async {
var fetcher = BatchInboxFetcherUserImpl(
user: userIdentifier, authKey: authenticationKey);
var fetcher = BatchInboxFetcherUserImpl(user: userIdentifier, authKey: authenticationKey);
await fetcher.init(maxPageSize: maxPageSize, limit: limit);
return fetcher;
}
Expand Down Expand Up @@ -115,8 +113,7 @@ abstract class BatchInboxFetcher {
/// Calling [fetchNewNotifications()]/[fetchNextPage()] right away
/// might cause notifications to come as unread, as the server needs time to
/// process your request.
Future<void> markNotificationAsRead(
BatchInboxNotificationContent notification);
Future<void> markNotificationAsRead(BatchInboxNotificationContent notification);

/// Marks all notifications as read.
/// Note: Please refresh your copy of the notifications using [allNotifications]
Expand All @@ -131,15 +128,13 @@ abstract class BatchInboxFetcher {
/// Calling [fetchNewNotifications()]/[fetchNextPage()] right away
/// might cause notifications to still be present, as the server needs time to
/// process your request.
Future<void> markNotificationAsDeleted(
BatchInboxNotificationContent notification);
Future<void> markNotificationAsDeleted(BatchInboxNotificationContent notification);

/// Display the landing message attached to a BatchInboxNotificationContent.
/// Do nothing if no message is attached.
///
/// Note that this method will work even if Batch is in do not disturb mode.
Future<void> displayNotificationLandingMessage(
BatchInboxNotificationContent notification);
Future<void> displayNotificationLandingMessage(BatchInboxNotificationContent notification);

/// Call this once you're finished with this fetcher to release the native
/// object and free all memory. Usually, this should be called
Expand All @@ -161,8 +156,8 @@ enum BatchInboxNotificationSource { unknown, campaign, transactional, trigger }
class BatchInboxNotificationContent {
/// Internal constructor.
/// <nodoc>
BatchInboxNotificationContent(this.id, this.title, this.body, this.isUnread,
this.date, this.source, this.payload, this.hasLandingMessage);
BatchInboxNotificationContent(this.id, this.title, this.body, this.isUnread, this.date,
this.source, this.payload, this.hasLandingMessage);

/// The unique notification identifier. Do not make assumptions about its format: it can change at any time.
final String id;
Expand Down Expand Up @@ -201,8 +196,7 @@ class BatchInboxNotificationContent {

/// Describes a fetch operation result
class BatchInboxFetchResult {
BatchInboxFetchResult(
{required this.notifications, required this.endReached});
BatchInboxFetchResult({required this.notifications, required this.endReached});

/// Fetched notifications.
final List<BatchInboxNotificationContent> notifications;
Expand Down
6 changes: 2 additions & 4 deletions lib/batch_messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import 'package:flutter/services.dart';
/// Provides messaging related functionality, such as do not disturb.
/// Do not instanciate this: use the `instance` static property.
class BatchMessaging {
static const MethodChannel _channel =
const MethodChannel('batch_flutter.messaging');
static const MethodChannel _channel = const MethodChannel('batch_flutter.messaging');

/// Batch Messaging module singleton.
static BatchMessaging instance = new BatchMessaging();
Expand All @@ -24,8 +23,7 @@ class BatchMessaging {
/// While DnD is disabled by default, the default state can be configured
/// in your Info.plist/AndroidManifest.xml
void setDoNotDisturbEnabled(bool enableDoNotDisturb) {
_channel.invokeMethod(
'messaging.setDoNotDisturbEnabled', {'enabled': enableDoNotDisturb});
_channel.invokeMethod('messaging.setDoNotDisturbEnabled', {'enabled': enableDoNotDisturb});
}

/// Shows the currently enqueued message, if any.
Expand Down
Loading
Loading