Skip to content

Commit

Permalink
Pull request #22: Klatypov MM-4615 message storage
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-flutter from klatypov-MM-4615-message_storage to main

Squashed commit of the following:

commit 68348621e86f3b0b02ef4d1e0b105df402969ebb
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 14:25:11 2021 +0300

    Fix review issues

commit a3911d3e4f799c27de0577e3d6b35de0964b2e83
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 14:16:39 2021 +0300

    Fix review issues

commit e70dd8a6dd31ffa32ff135bf4a3ce99a4c14f80b
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 13:05:31 2021 +0300

    Update dependencies

commit 776cb40e21624bc5b2f8a2bf5f1741057710ef09
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 12:48:03 2021 +0300

    Fix iOS build

commit d0fc8a21ea4ab95ef1997cfcab84bdfcb5e5213e
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 12:36:42 2021 +0300

    Move back missed changes

commit 2d5895152f766e4577611baffeadb5b562d3a09e
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 01:35:16 2021 +0300

    Fix iOS build

commit 87afebd79a38c53820f73414d4372129c63a5c81
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 01:21:28 2021 +0300

    Remove unused code

commit c5310696d0b5b2112210a650418c6e44dcfa06c7
Author: Konstantin Latypov <[email protected]>
Date:   Thu Dec 16 01:14:51 2021 +0300

    Add default message storage

commit 62b04ecc63cc47381a81394a0e0d93817ea2f88a
Merge: 687d2c0 2689fea a5901e4
Author: Konstantin Latypov <[email protected]>
Date:   Fri Dec 10 07:54:38 2021 +0300

    Merge branch 'main', remote-tracking branch 'origin' into klatypov-MM-4615-message_storage

commit 687d2c039476b092d32b49edb068c151b8fae072
Author: Konstantin Latypov <[email protected]>
Date:   Thu Nov 18 13:03:37 2021 +0300

    Change dart config

commit 71e59bf7a4b435d0569cc1f76b727bdcf4049fc7
Author: Konstantin Latypov <[email protected]>
Date:   Mon Nov 8 14:59:06 2021 +0300

    Add default messagestorage support

commit 2689fea40bda75cddbf3fa14674dd21561b31751
Author: Konstantin Latypov <[email protected]>
Date:   Thu Aug 12 14:52:17 2021 +0300

    initial commit
  • Loading branch information
Konstantin Latypov authored and Konstantin Latypov committed Dec 16, 2021
1 parent a5901e4 commit 84123f8
Show file tree
Hide file tree
Showing 17 changed files with 379 additions and 104 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@
* Fixed support for lists in customAttributes for Installation and User classes on Android

## 0.4.2
* Update Android SDK
* Update Android SDK

## 0.5.0
* Added Default MessageStorage support
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
}

dependencies {
implementation ('com.infobip:infobip-mobile-messaging-android-sdk:5.3.5@aar') {
implementation ('com.infobip:infobip-mobile-messaging-android-sdk:5.3.6@aar') {
transitive = true
}
implementation 'com.google.android.material:material:1.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Configuration {

List<NotificationCategory> notificationCategories;

boolean defaultMessageStorage;

public class AndroidSettings {
/// The firebase sender ID of your Application
String firebaseSenderId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public enum ErrorCodes {
SAVE_INSTALLATION("SAVE_INSTALLATION_ERROR"),
PERSONALIZE("PERSONALIZE_ERROR"),
DEPERSONALIZE_INSTALLATION("DEPERSONALIZE_INSTALLATION_ERROR"),
CUSTOM_EVENT("CUSTOM_EVENT_ERROR");
CUSTOM_EVENT("CUSTOM_EVENT_ERROR"),
MESSAGE_STORAGE_ERROR("MESSAGE_STORAGE_ERROR");

private final String code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.infobip.mobile.messaging.interactive.NotificationAction;
import org.infobip.mobile.messaging.interactive.NotificationCategory;
import org.infobip.mobile.messaging.chat.InAppChat;
import org.infobip.mobile.messaging.storage.SQLiteMessageStore;

import java.util.List;

Expand Down Expand Up @@ -46,6 +47,10 @@ public MobileMessaging.Builder configurationBuilder() {
}
}

if (configuration.defaultMessageStorage) {
builder.withMessageStore(SQLiteMessageStore.class);
}

// Notification
Context context = activity.getApplicationContext();
NotificationSettings.Builder notificationBuilder = new NotificationSettings.Builder(activity.getApplicationContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
import org.infobip.mobile.messaging.mobileapi.InternalSdkError;
import org.infobip.mobile.messaging.mobileapi.MobileMessagingError;
import org.infobip.mobile.messaging.mobileapi.Result;
import org.infobip.mobile.messaging.storage.MessageStore;
import org.infobip.mobile.messaging.util.PreferenceHelper;
import org.infobip.plugins.mobilemessaging.flutter.common.Configuration;
import org.infobip.plugins.mobilemessaging.flutter.common.ErrorCodes;
import org.infobip.plugins.mobilemessaging.flutter.common.InitHelper;
import org.infobip.plugins.mobilemessaging.flutter.common.InstallationJson;
import org.infobip.plugins.mobilemessaging.flutter.common.PersonalizationCtx;
import org.infobip.plugins.mobilemessaging.flutter.common.UserJson;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -154,6 +156,18 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
case "resetMessageCounter":
resetMessageCounter();
break;
case "defaultMessageStorage_find":
defaultMessageStorage_find(call, result);
break;
case "defaultMessageStorage_findAll":
defaultMessageStorage_findAll(result);
break;
case "defaultMessageStorage_delete":
defaultMessageStorage_delete(call, result);
break;
case "defaultMessageStorage_deleteAll":
defaultMessageStorage_deleteAll(result);
break;
default:
result.notImplemented();
break;
Expand Down Expand Up @@ -367,6 +381,24 @@ private static JSONObject messageToJSON(Message message) {
}
}

/**
* Creates array of json objects from list of messages
*
* @param messages list of messages
* @return array of jsons representing messages
*/
private static JSONArray messagesToJSONArray(@NonNull Message messages[]) {
JSONArray array = new JSONArray();
for (Message message : messages) {
JSONObject json = messageToJSON(message);
if (json == null) {
continue;
}
array.put(json);
}
return array;
}

public static class StreamHandler implements EventChannel.StreamHandler {

private EventChannel.EventSink eventSink;
Expand Down Expand Up @@ -408,7 +440,7 @@ private boolean sendEvent(String event, Object payload) {
}

if (eventSink != null) {
Log.d(TAG, "Send event to Flutter: " + event);
Log.d(TAG, "Send event to flutter: " + event);
eventSink.success(eventData.toString());
} else {
Log.d(TAG, "add event to cached: " + event);
Expand All @@ -434,7 +466,7 @@ private boolean sendEvent(String event) {
}

if (eventSink != null) {
Log.d(TAG, "Send event to Flutter: " + event);
Log.d(TAG, "Send event to flutter: " + event);
eventSink.success(eventData.toString());
} else {
Log.d(TAG, "add event to cached: " + event);
Expand Down Expand Up @@ -616,6 +648,63 @@ private void resetMessageCounter() {
InAppChat.getInstance(activity.getApplication()).resetMessageCounter();
}

private synchronized void defaultMessageStorage_find(MethodCall call, final MethodChannel.Result result) {
String messageId = call.argument("messageId");
MessageStore messageStore = MobileMessaging.getInstance(activity.getApplicationContext()).getMessageStore();
if (messageStore == null) {
result.error(ErrorCodes.MESSAGE_STORAGE_ERROR.getErrorCode(), "Message storage does not exist", null);
return;
}

for (Message m : messageStore.findAll(activity.getApplicationContext())) {
if (messageId.equals(m.getMessageId())) {
result.success(messageToJSON(m).toString());
return;
}
}
result.success(null);
}

private synchronized void defaultMessageStorage_findAll(final MethodChannel.Result result) {
MessageStore messageStore = MobileMessaging.getInstance(activity.getApplicationContext()).getMessageStore();
if (messageStore == null) {
result.error(ErrorCodes.MESSAGE_STORAGE_ERROR.getErrorCode(), "Message storage does not exist", null);
return;
}
List<Message> messages = messageStore.findAll(activity.getApplicationContext());
result.success(messagesToJSONArray(messages.toArray(new Message[messages.size()])));
}

private synchronized void defaultMessageStorage_delete(MethodCall call, final MethodChannel.Result result) {
String messageId = call.argument("messageId");
MessageStore messageStore = MobileMessaging.getInstance(activity.getApplicationContext()).getMessageStore();
if (messageStore == null) {
result.error(ErrorCodes.MESSAGE_STORAGE_ERROR.getErrorCode(), "Message storage does not exist", null);
return;
}

List<Message> messagesToKeep = new ArrayList<Message>();
for (Message m : messageStore.findAll(activity.getApplicationContext())) {
if (messageId.equals(m.getMessageId())) {
continue;
}
messagesToKeep.add(m);
}
messageStore.deleteAll(activity.getApplicationContext());
messageStore.save(activity.getApplicationContext(), messagesToKeep.toArray(new Message[messagesToKeep.size()]));
result.success(null);
}

private synchronized void defaultMessageStorage_deleteAll(final MethodChannel.Result result) {
MessageStore messageStore = MobileMessaging.getInstance(activity.getApplicationContext()).getMessageStore();
if (messageStore == null) {
result.error(ErrorCodes.MESSAGE_STORAGE_ERROR.getErrorCode(), "Message storage does not exist", null);
return;
}
messageStore.deleteAll(activity.getApplicationContext());
result.success(null);
}

@NonNull
private MobileMessaging.ResultListener<CustomEvent> customEventResultListener(final MethodChannel.Result resultCallbacks) {
return new MobileMessaging.ResultListener<CustomEvent>() {
Expand Down
26 changes: 13 additions & 13 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ PODS:
- Flutter (1.0.0)
- infobip_mobilemessaging (0.0.1):
- Flutter
- MobileMessaging/Core (= 9.2.8)
- MobileMessaging/Geofencing (= 9.2.8)
- MobileMessaging/InAppChat (= 9.2.8)
- MobileMessaging (9.2.8):
- MobileMessaging/CocoaLumberjack (= 9.2.8)
- MobileMessaging/CocoaLumberjack (9.2.8):
- MobileMessaging/Core (= 9.2.10)
- MobileMessaging/Geofencing (= 9.2.10)
- MobileMessaging/InAppChat (= 9.2.10)
- MobileMessaging (9.2.10):
- MobileMessaging/CocoaLumberjack (= 9.2.10)
- MobileMessaging/CocoaLumberjack (9.2.10):
- CocoaLumberjack (= 3.6)
- MobileMessaging/Core
- MobileMessaging/Core (9.2.8)
- MobileMessaging/Geofencing (9.2.8):
- MobileMessaging/Core (9.2.10)
- MobileMessaging/Geofencing (9.2.10):
- MobileMessaging/Core
- MobileMessaging/InAppChat (9.2.8):
- MobileMessaging/InAppChat (9.2.10):
- MobileMessaging/Core
- package_info_plus (0.4.5):
- Flutter
Expand All @@ -42,11 +42,11 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
CocoaLumberjack: 78b0c238666f4f58db069738ec176f4519557516
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
infobip_mobilemessaging: a540f1fe94d2877ba656e0c0d8a6a5a175df47d9
MobileMessaging: 2ef057c1e80dac035f8d29ffabc839492b5d7421
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
infobip_mobilemessaging: 06b68ef87a13f44c8e28eb98a1681108e56500a0
MobileMessaging: f130ec2523facbb49c9c1b04c62b0a2e3b2b655d
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e

PODFILE CHECKSUM: 7c1cfed60f7a053b419fa4b2392d308f9ca04995

COCOAPODS: 1.11.0
COCOAPODS: 1.10.1
11 changes: 6 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ handleDeeplinkEvent(Message message) {
}

var storedFunction = (Message message) => handleDeeplinkEvent(message);

class _MyAppState extends State<MyApp> {
@override
void initState() {
Expand All @@ -75,8 +74,9 @@ class _MyAppState extends State<MyApp> {

await InfobipMobilemessaging.init(Configuration(
applicationCode: "Your Application Code",
androidSettings: AndroidSettings(firebaseSenderId: "Your Firebase ID"),
inAppChatEnabled: true,
androidSettings: AndroidSettings(firebaseSenderId: "Your Firebase ID"),
defaultMessageStorage: true,
iosSettings: IOSSettings(
notificationTypes: ["alert", "badge", "sound"],
forceCleanup: false,
Expand All @@ -100,7 +100,9 @@ class _MyAppState extends State<MyApp> {
message.title +
" body: " +
message.body),
_HomePageState.addLibraryEvent("Message Received")
_HomePageState.addLibraryEvent("Message Received"),
print("defaultMessageStorage().findAll():"),
print(InfobipMobilemessaging.defaultMessageStorage().findAll())
});
InfobipMobilemessaging.on(
LibraryEvent.USER_UPDATED,
Expand Down Expand Up @@ -133,12 +135,11 @@ class _MyAppState extends State<MyApp> {
event.toString()),
_HomePageState.addLibraryEvent("Notification Action Tapped")
});

InfobipMobilemessaging.on(
LibraryEvent.NOTIFICATION_TAPPED,
(Message message) => {
print(
'Callback. NOTIFICATION_TAPPED event: ' + message.toString()),
"Callback. NOTIFICATION_TAPPED event:" + message.toString()),
_HomePageState.addLibraryEvent("Notification Tapped"),
if (message.chat) {print('Chat Message Tapped')}
});
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.0"
version: "0.2.1"
js:
dependency: transitive
description:
Expand Down
13 changes: 7 additions & 6 deletions ios/Classes/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class Configuration {
static let inAppChatEnabled = "inAppChatEnabled"
static let forceCleanup = "forceCleanup"
static let logging = "logging"
// static let defaultMessageStorage = "defaultMessageStorage"
static let defaultMessageStorage = "defaultMessageStorage"
static let notificationTypes = "notificationTypes"
// static let messageStorage = "messageStorage"
static let pluginVersion = "pluginVersion"
static let notificationCategories = "notificationCategories"
static let webViewSettings = "webViewSettings"
Expand All @@ -32,7 +31,7 @@ class Configuration {
// let geofencingEnabled: Bool
let inAppChatEnabled: Bool
// let messageStorageEnabled: Bool
// let defaultMessageStorage: Bool
let defaultMessageStorage: Bool
let notificationType: MMUserNotificationType
let forceCleanup: Bool
let logging: Bool
Expand All @@ -44,9 +43,9 @@ class Configuration {
init?(rawConfig: [String: AnyObject]) {
guard let appCode = rawConfig[Configuration.Keys.applicationCode] as? String,
let ios = rawConfig["iosSettings"] as? [String: AnyObject] else
{
return nil
}
{
return nil
}

self.appCode = appCode
self.inAppChatEnabled = rawConfig[Configuration.Keys.inAppChatEnabled].unwrap(orDefault: false)
Expand All @@ -67,6 +66,8 @@ class Configuration {

self.pluginVersion = rawConfig[Configuration.Keys.pluginVersion].unwrap(orDefault: "unknown")

self.defaultMessageStorage = rawConfig[Configuration.Keys.defaultMessageStorage].unwrap(orDefault: false)

self.categories = (rawConfig[Configuration.Keys.notificationCategories] as? [[String: Any]])?.compactMap(MMNotificationCategory.init)

if let notificationTypeNames = ios[Configuration.Keys.notificationTypes] as? [String] {
Expand Down
Loading

0 comments on commit 84123f8

Please sign in to comment.