Skip to content

Commit

Permalink
Rename properties to isSubscribed and isPushDisabled
Browse files Browse the repository at this point in the history
Renaming Subscription State properties from:
- `subscribed` to `isSubscribed`
- `userSubscriptionSetting` to `isPushDisabled`
  • Loading branch information
nan-li committed Aug 14, 2021
1 parent bd5ecff commit 0bb0512
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions lib/src/permission.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class OSPermissionStateChanges extends JSONStringRepresentable {
class OSDeviceState extends JSONStringRepresentable {

bool hasNotificationPermission = false;
bool pushDisabled = false;
bool subscribed = false;
bool isPushDisabled = false;
bool isSubscribed = false;
bool emailSubscribed = false;
bool smsSubscribed = false;
String? userId;
Expand All @@ -100,8 +100,8 @@ class OSDeviceState extends JSONStringRepresentable {

OSDeviceState(Map<String, dynamic> json) {
this.hasNotificationPermission = json['hasNotificationPermission'] as bool;
this.pushDisabled = json['pushDisabled'] as bool;
this.subscribed = json['subscribed'] as bool;
this.isPushDisabled = json['isPushDisabled'] as bool;
this.isSubscribed = json['isSubscribed'] as bool;
this.emailSubscribed = json['emailSubscribed'] as bool;
this.smsSubscribed = json['smsSubscribed'] as bool;
this.userId = json['userId'] as String?;
Expand All @@ -116,8 +116,8 @@ class OSDeviceState extends JSONStringRepresentable {
String jsonRepresentation() {
return convertToJsonString({
'hasNotificationPermission': this.hasNotificationPermission,
'isPushDisabled': this.pushDisabled,
'isSubscribed': this.subscribed,
'isPushDisabled': this.isPushDisabled,
'isSubscribed': this.isSubscribed,
'userId': this.userId,
'pushToken': this.pushToken,
'isEmailSubscribed': this.emailSubscribed,
Expand Down
14 changes: 7 additions & 7 deletions lib/src/subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import 'package:onesignal_flutter/src/utils.dart';
class OSSubscriptionState extends JSONStringRepresentable {
/// Indicates if you have ever called setSubscription(false) to
/// programmatically disable notifications for this user
bool userSubscriptionSetting = false;
bool isPushDisabled = false;

/// A boolean parameter that indicates if the user
/// is subscribed to your app with OneSignal
/// This is only true if the `userId`, `pushToken`, and
/// `userSubscriptionSetting` parameters are defined/true.
bool subscribed = false;
/// `isPushDisabled` parameters are defined/true.
bool isSubscribed = false;

/// The current user's User ID (AKA playerID) with OneSignal
String? userId; //the user's 'playerId' on OneSignal
Expand All @@ -19,8 +19,8 @@ class OSSubscriptionState extends JSONStringRepresentable {
String? pushToken;

OSSubscriptionState(Map<String, dynamic> json) {
this.subscribed = json['subscribed'] as bool;
this.userSubscriptionSetting = json['userSubscriptionSetting'] as bool;
this.isSubscribed = json['isSubscribed'] as bool;
this.isPushDisabled = json['isPushDisabled'] as bool;

if (json.containsKey('userId')) this.userId = json['userId'] as String?;
if (json.containsKey('pushToken'))
Expand All @@ -29,8 +29,8 @@ class OSSubscriptionState extends JSONStringRepresentable {

String jsonRepresentation() {
return convertToJsonString({
'subscribed': this.subscribed,
'userSubscriptionSetting': this.userSubscriptionSetting,
'isSubscribed': this.isSubscribed,
'isPushDisabled': this.isPushDisabled,
'pushToken': this.pushToken,
'userId': this.userId
});
Expand Down
8 changes: 4 additions & 4 deletions test.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"subscription_changed_test" : {
"from": {
"subscribed": false,
"userSubscriptionSetting": true,
"isSubscribed": false,
"isPushDisabled": true,
"pushToken": "07afbb0b4cb6e7ae5e81efc7fd5d35267ea9a4f12120045aebe29945e52ea30e",
"userId": null
},
"to": {
"subscribed": true,
"userSubscriptionSetting": true,
"isSubscribed": true,
"isPushDisabled": true,
"pushToken": "07afbb0b4cb6e7ae5e81efc7fd5d35267ea9a4f12120045aebe29945e52ea30e",
"userId": "c1b395fc-3b17-4c18-aaa6-195cd3461311"
}
Expand Down
10 changes: 5 additions & 5 deletions test/subscription_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ void main() {
subscriptionChanges.to.pushToken, subscriptionChanges.from.pushToken);
});

test('expect subscription correctly parses `subscribed`', () {
expect(subscriptionChanges.to.subscribed,
!subscriptionChanges.from.subscribed);
test('expect subscription correctly parses `isSubscribed`', () {
expect(subscriptionChanges.to.isSubscribed,
!subscriptionChanges.from.isSubscribed);
});

test('expect subscription correctly parses `userSubscriptionSetting`', () {
expect(subscriptionChanges.to.userSubscriptionSetting, true);
test('expect subscription correctly parses `isPushDisabled`', () {
expect(subscriptionChanges.to.isPushDisabled, true);
});

// Email Subscription State Tests
Expand Down

0 comments on commit 0bb0512

Please sign in to comment.