Skip to content

Commit

Permalink
Pull request #66: Aboldyrev MM-6367 inbox times
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-flutter from aboldyrev-MM-6367-inbox-times to main

Squashed commit of the following:

commit e6af92dcfda62aa9659adfca75f90dc552a6ac02
Author: Alexander Boldyrev <[email protected]>
Date:   Thu Apr 25 15:13:29 2024 +0300

    - refactoring

commit 732ab20d1e5ad7a344a15c5d15c98aa160e38335
Author: Alexander Boldyrev <[email protected]>
Date:   Thu Apr 25 14:23:05 2024 +0300

    - receivedTimestamp

commit 5131556e2a21384653b368ef5cc060c426a5df28
Author: Alexander Boldyrev <[email protected]>
Date:   Tue Apr 23 16:46:10 2024 +0300

    - receivedTimestamp

commit 5eddc9ca16af5378aef16df0d2e981bfd32244d4
Author: Alexander Boldyrev <[email protected]>
Date:   Tue Apr 23 10:41:27 2024 +0300

    - inbox message model
  • Loading branch information
alboldy-ib committed Apr 25, 2024
1 parent af6b020 commit a666ada
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 32 deletions.
26 changes: 21 additions & 5 deletions lib/infobip_mobilemessaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Inbox> fetchInboxMessages(
String token, String externalUserId, FilterOptions filterOptions) async {
return Inbox.fromJson(jsonDecode(await _channel.invokeMethod(
Expand All @@ -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<Inbox> fetchInboxMessagesWithoutToken(
String externalUserId, FilterOptions filterOptions) async {
return Inbox.fromJson(jsonDecode(await _channel.invokeMethod(
Expand All @@ -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<void> setInboxMessagesSeen(
String externalUserId, List<String> messageIds) async {
await _channel.invokeMethod('setInboxMessagesSeen',
{
'externalUserId': externalUserId,
'messageIds': messageIds,
},);
await _channel.invokeMethod(
'setInboxMessagesSeen',
{
'externalUserId': externalUserId,
'messageIds': messageIds,
},
);
}

static Future<void> markMessagesSeen(List<String> messageIds) async {
Expand Down
5 changes: 5 additions & 0 deletions lib/models/inbox/inbox.dart
Original file line number Diff line number Diff line change
@@ -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<InboxMessage>? messages;
final int? countTotal;
Expand Down
142 changes: 115 additions & 27 deletions lib/models/inbox/inbox_message.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic>? customPayload;
final String? internalData;
final String? contentUrl;
final Map<String, dynamic>? 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<String, dynamic> 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;
}

0 comments on commit a666ada

Please sign in to comment.