diff --git a/lib/infobip_mobilemessaging.dart b/lib/infobip_mobilemessaging.dart index 374dcd5..499dcea 100644 --- a/lib/infobip_mobilemessaging.dart +++ b/lib/infobip_mobilemessaging.dart @@ -232,6 +232,11 @@ class InfobipMobilemessaging { await _channel.invokeMethod('stopConnection'); } + /// Fetches messages from Inbox. + /// Requires token, externalUserId, and filterOptions. + /// Example: + /// ```dart + /// var inbox = await fetchInboxMessages('jwtToken', 'yourId', FilterOptions()); static Future fetchInboxMessages( String token, String externalUserId, FilterOptions filterOptions) async { return Inbox.fromJson(jsonDecode(await _channel.invokeMethod( @@ -244,6 +249,13 @@ class InfobipMobilemessaging { ))); } + /// Fetches messages from Inbox without token - recommended only for sandbox + /// applications. For production apps use fetchInboxMessages with token. + /// Requires externalUserId, and filterOptions. + /// + /// Example: + /// ```dart + /// var inbox = await fetchInboxMessagesWithoutToken('yourId', FilterOptions()); static Future fetchInboxMessagesWithoutToken( String externalUserId, FilterOptions filterOptions) async { return Inbox.fromJson(jsonDecode(await _channel.invokeMethod( @@ -255,13 +267,17 @@ class InfobipMobilemessaging { ))); } + /// Sets Inbox messages as seen. + /// Requires externalUserId and List of IDs of messages to be marked as seen. static Future setInboxMessagesSeen( String externalUserId, List messageIds) async { - await _channel.invokeMethod('setInboxMessagesSeen', - { - 'externalUserId': externalUserId, - 'messageIds': messageIds, - },); + await _channel.invokeMethod( + 'setInboxMessagesSeen', + { + 'externalUserId': externalUserId, + 'messageIds': messageIds, + }, + ); } static Future markMessagesSeen(List messageIds) async { diff --git a/lib/models/inbox/inbox.dart b/lib/models/inbox/inbox.dart index 26eed14..47247d0 100644 --- a/lib/models/inbox/inbox.dart +++ b/lib/models/inbox/inbox.dart @@ -1,5 +1,10 @@ import 'inbox_message.dart'; +/// An Inbox class. +/// +/// Has countTotal - total number of messages in Inbox for the externalUserId, +/// countUnread - total number of unread messages, and messages - List of Inbox +/// messages. class Inbox { final List? messages; final int? countTotal; diff --git a/lib/models/inbox/inbox_message.dart b/lib/models/inbox/inbox_message.dart index c77cdba..a9163bd 100644 --- a/lib/models/inbox/inbox_message.dart +++ b/lib/models/inbox/inbox_message.dart @@ -1,39 +1,127 @@ -import 'package:infobip_mobilemessaging/models/message.dart'; +import 'package:flutter/foundation.dart'; -class InboxMessage extends Message { - final String? topic; - final bool? seen; +/// A message stored in the inbox. +/// +/// InboxMessage always has a special topic, has sentTimestamp - milliseconds +/// from epoch in UTC, and seen status. To mark message as seen, use special +/// markMessagesSeen. +class InboxMessage { + final String messageId; + final String topic; + final bool seen; + final String? title; + final String? body; + final String? sound; + final bool? vibrate; // Android only + final String? icon; // Android only + final bool? silent; + final String? category; // Android only + final Map? customPayload; + final String? internalData; + final String? contentUrl; + final Map? originalPayload; // iOS only + final String? browserUrl; + final String? deeplink; + final String? webViewUrl; + final String? inAppOpenTitle; + final String? inAppDismissTitle; + final num? sentTimestamp; InboxMessage({ - required super.messageId, - super.title, - super.body, - super.sound, - super.silent, - super.customPayload, - super.internalData, - super.receivedTimestamp, - super.seenDate, - super.contentUrl, - super.originalPayload, - super.vibrate, - super.icon, - super.category, - super.browserUrl, - super.deeplink, - super.webViewUrl, - super.inAppOpenTitle, - super.inAppDismissTitle, - this.seen, - this.topic, + required this.messageId, + required this.seen, + required this.topic, + this.title, + this.body, + this.sound, + this.vibrate, + this.icon, + this.silent, + this.category, + this.customPayload, + this.internalData, + this.contentUrl, + this.originalPayload, + this.browserUrl, + this.deeplink, + this.webViewUrl, + this.inAppOpenTitle, + this.inAppDismissTitle, + this.sentTimestamp, }); InboxMessage.fromJson(Map json) - : topic = json['inboxData'] != null + : messageId = json['messageId'], + topic = json['inboxData'] != null ? json['inboxData']['inbox']['topic'] : json['topic'], seen = json['inboxData'] != null ? json['inboxData']['inbox']['seen'] : json['seen'], - super.fromJson(json); + title = json['title'], + body = json['body'], + sound = json['sound'], + vibrate = json['vibrate'], + icon = json['icon'], + silent = json['silent'], + category = json['category'], + customPayload = json['customPayload'], + internalData = json['internalData'], + contentUrl = json['contentUrl'], + originalPayload = json['originalPayload'], + browserUrl = json['browserUrl'], + deeplink = json['deeplink'], + webViewUrl = json['webViewUrl'], + inAppOpenTitle = json['inAppOpenTitle'], + inAppDismissTitle = json['inAppDismissTitle'], + sentTimestamp = json['sentTimestamp']; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is InboxMessage && + runtimeType == other.runtimeType && + messageId == other.messageId && + seen == other.seen && + topic == other.topic && + title == other.title && + body == other.body && + sound == other.sound && + vibrate == other.vibrate && + icon == other.icon && + silent == other.silent && + category == other.category && + mapEquals(customPayload, other.customPayload) && + internalData == other.internalData && + contentUrl == other.contentUrl && + mapEquals(originalPayload, other.originalPayload) && + browserUrl == other.browserUrl && + deeplink == other.deeplink && + webViewUrl == other.webViewUrl && + inAppOpenTitle == other.inAppOpenTitle && + inAppDismissTitle == other.inAppDismissTitle && + sentTimestamp == other.sentTimestamp; + + @override + int get hashCode => + messageId.hashCode ^ + seen.hashCode ^ + topic.hashCode ^ + title.hashCode ^ + body.hashCode ^ + sound.hashCode ^ + vibrate.hashCode ^ + icon.hashCode ^ + silent.hashCode ^ + category.hashCode ^ + customPayload.hashCode ^ + internalData.hashCode ^ + contentUrl.hashCode ^ + originalPayload.hashCode ^ + browserUrl.hashCode ^ + deeplink.hashCode ^ + webViewUrl.hashCode ^ + inAppOpenTitle.hashCode ^ + inAppDismissTitle.hashCode ^ + sentTimestamp.hashCode; }