Merge pull request #230 from GetStream/nash/migrate-to-enum
[Flutter-SDK] Migrate to push enum
This commit is contained in:
@@ -46,6 +46,26 @@ const String KEY_TOKEN = 'KEY_TOKEN';
|
|||||||
/// The key used to save the apiKey to sharedPreferences
|
/// The key used to save the apiKey to sharedPreferences
|
||||||
const String KEY_API_KEY = 'KEY_API_KEY';
|
const String KEY_API_KEY = 'KEY_API_KEY';
|
||||||
|
|
||||||
|
/// Provider used to send push notifications.
|
||||||
|
enum PushProvider {
|
||||||
|
/// Send notifications using Google's Firebase Cloud Messaging
|
||||||
|
firebase,
|
||||||
|
|
||||||
|
/// Send notifications using Apple's Push Notification service
|
||||||
|
apn
|
||||||
|
}
|
||||||
|
|
||||||
|
extension on PushProvider {
|
||||||
|
/// Returns the string notion for [PushProvider].
|
||||||
|
String get name {
|
||||||
|
if (this == PushProvider.apn) {
|
||||||
|
return 'apn';
|
||||||
|
} else {
|
||||||
|
return 'firebase';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The official Dart client for Stream Chat,
|
/// The official Dart client for Stream Chat,
|
||||||
/// a service for building chat applications.
|
/// a service for building chat applications.
|
||||||
/// This library can be used on any Dart project and on both mobile and web apps with Flutter.
|
/// This library can be used on any Dart project and on both mobile and web apps with Flutter.
|
||||||
@@ -1002,10 +1022,10 @@ class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Add a device for Push Notifications.
|
/// Add a device for Push Notifications.
|
||||||
Future<EmptyResponse> addDevice(String id, String pushProvider) async {
|
Future<EmptyResponse> addDevice(String id, PushProvider pushProvider) async {
|
||||||
final response = await post('/devices', data: {
|
final response = await post('/devices', data: {
|
||||||
'id': id,
|
'id': id,
|
||||||
'push_provider': pushProvider,
|
'push_provider': pushProvider.name,
|
||||||
});
|
});
|
||||||
return decode<EmptyResponse>(response.data, EmptyResponse.fromJson);
|
return decode<EmptyResponse>(response.data, EmptyResponse.fromJson);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,13 +266,17 @@ void main() {
|
|||||||
|
|
||||||
when(mockDio.post<String>('/devices', data: {
|
when(mockDio.post<String>('/devices', data: {
|
||||||
'id': 'test-id',
|
'id': 'test-id',
|
||||||
'push_provider': 'test',
|
'push_provider': 'firebase',
|
||||||
})).thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
})).thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
||||||
|
|
||||||
await client.addDevice('test-id', 'test');
|
await client.addDevice('test-id', PushProvider.firebase);
|
||||||
|
|
||||||
verify(mockDio.post<String>('/devices',
|
verify(
|
||||||
data: {'id': 'test-id', 'push_provider': 'test'})).called(1);
|
mockDio.post<String>(
|
||||||
|
'/devices',
|
||||||
|
data: {'id': 'test-id', 'push_provider': 'firebase'},
|
||||||
|
),
|
||||||
|
).called(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getDevices', () async {
|
test('getDevices', () async {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ void initNotifications(Client client) {
|
|||||||
if (connector.token.value != null) {
|
if (connector.token.value != null) {
|
||||||
client.addDevice(
|
client.addDevice(
|
||||||
connector.token.value,
|
connector.token.value,
|
||||||
Platform.isAndroid ? 'firebase' : 'apn',
|
Platform.isAndroid ? PushProvider.firebase : PushProvider.apn,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user