Merge branch 'develop' into v4
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
## Upcoming
|
||||
|
||||
✅ Added
|
||||
|
||||
- Added `push_provider_name` to `addDevice` API call
|
||||
|
||||
## 4.0.0-beta.2
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
@@ -64,7 +64,7 @@ class StreamChatClient {
|
||||
StreamChatClient(
|
||||
String apiKey, {
|
||||
this.logLevel = Level.WARNING,
|
||||
LogHandlerFunction? logHandlerFunction,
|
||||
this.logHandlerFunction = StreamChatClient.defaultLogHandler,
|
||||
RetryPolicy? retryPolicy,
|
||||
@Deprecated('''
|
||||
Location is now deprecated in favor of the new edge server. Will be removed in v4.0.0.
|
||||
@@ -77,7 +77,6 @@ class StreamChatClient {
|
||||
WebSocket? ws,
|
||||
AttachmentFileUploader? attachmentFileUploader,
|
||||
}) {
|
||||
this.logHandlerFunction = logHandlerFunction ?? _defaultLogHandler;
|
||||
logger.info('Initiating new StreamChatClient');
|
||||
|
||||
final options = StreamHttpClientOptions(
|
||||
@@ -134,7 +133,7 @@ class StreamChatClient {
|
||||
'${CurrentPlatform.name}-'
|
||||
'${PACKAGE_VERSION.split('+')[0]}';
|
||||
|
||||
/// Additionals headers for all requests
|
||||
/// Additional headers for all requests
|
||||
static Map<String, Object?> additionalHeaders = {};
|
||||
|
||||
ChatPersistenceClient? _originalChatPersistenceClient;
|
||||
@@ -189,7 +188,7 @@ class StreamChatClient {
|
||||
/// final client = StreamChatClient("stream-chat-api-key",
|
||||
/// logHandlerFunction: myLogHandlerFunction);
|
||||
///```
|
||||
late LogHandlerFunction logHandlerFunction;
|
||||
final LogHandlerFunction logHandlerFunction;
|
||||
|
||||
StreamSubscription<ConnectionStatus>? _connectionStatusSubscription;
|
||||
|
||||
@@ -214,17 +213,18 @@ class StreamChatClient {
|
||||
Stream<ConnectionStatus> get wsConnectionStatusStream =>
|
||||
_wsConnectionStatusController.stream.distinct();
|
||||
|
||||
LogHandlerFunction get _defaultLogHandler => (LogRecord record) {
|
||||
print(
|
||||
'${record.time} '
|
||||
'${_levelEmojiMapper[record.level] ?? record.level.name} '
|
||||
'${record.loggerName} ${record.message} ',
|
||||
);
|
||||
if (record.error != null) print(record.error);
|
||||
if (record.stackTrace != null) print(record.stackTrace);
|
||||
};
|
||||
/// Default log handler function for the [StreamChatClient] logger.
|
||||
static void defaultLogHandler(LogRecord record) {
|
||||
print(
|
||||
'${record.time} '
|
||||
'${_levelEmojiMapper[record.level] ?? record.level.name} '
|
||||
'${record.loggerName} ${record.message} ',
|
||||
);
|
||||
if (record.error != null) print(record.error);
|
||||
if (record.stackTrace != null) print(record.stackTrace);
|
||||
}
|
||||
|
||||
///
|
||||
/// Default logger for the [StreamChatClient].
|
||||
Logger detachedLogger(String name) => Logger.detached(name)
|
||||
..level = logLevel
|
||||
..onRecord.listen(logHandlerFunction);
|
||||
@@ -820,8 +820,16 @@ class StreamChatClient {
|
||||
);
|
||||
|
||||
/// Add a device for Push Notifications.
|
||||
Future<EmptyResponse> addDevice(String id, PushProvider pushProvider) =>
|
||||
_chatApi.device.addDevice(id, pushProvider);
|
||||
Future<EmptyResponse> addDevice(
|
||||
String id,
|
||||
PushProvider pushProvider, {
|
||||
String? pushProviderName,
|
||||
}) =>
|
||||
_chatApi.device.addDevice(
|
||||
id,
|
||||
pushProvider,
|
||||
pushProviderName: pushProviderName,
|
||||
);
|
||||
|
||||
/// Gets a list of user devices.
|
||||
Future<ListDevicesResponse> getDevices() => _chatApi.device.getDevices();
|
||||
|
||||
@@ -29,13 +29,16 @@ class DeviceApi {
|
||||
/// Add a device for Push Notifications.
|
||||
Future<EmptyResponse> addDevice(
|
||||
String deviceId,
|
||||
PushProvider pushProvider,
|
||||
) async {
|
||||
PushProvider pushProvider, {
|
||||
String? pushProviderName,
|
||||
}) async {
|
||||
final response = await _client.post(
|
||||
'/devices',
|
||||
data: {
|
||||
'id': deviceId,
|
||||
'push_provider': pushProvider.name,
|
||||
if (pushProviderName != null && pushProviderName.isNotEmpty)
|
||||
'push_provider_name': pushProviderName,
|
||||
},
|
||||
);
|
||||
return EmptyResponse.fromJson(response.data);
|
||||
|
||||
@@ -5,7 +5,7 @@ export 'package:dio/src/dio_error.dart';
|
||||
export 'package:dio/src/multipart_file.dart';
|
||||
export 'package:dio/src/options.dart';
|
||||
export 'package:dio/src/options.dart' show ProgressCallback;
|
||||
export 'package:logging/logging.dart' show Logger, Level;
|
||||
export 'package:logging/logging.dart' show Logger, Level, LogRecord;
|
||||
export 'package:rate_limiter/rate_limiter.dart';
|
||||
export 'package:uuid/uuid.dart';
|
||||
|
||||
@@ -41,3 +41,31 @@ export './src/permission_type.dart';
|
||||
export './src/ws/connection_status.dart';
|
||||
export 'src/client/channel.dart';
|
||||
export 'src/client/client.dart';
|
||||
export 'src/core/api/attachment_file_uploader.dart' show AttachmentFileUploader;
|
||||
export 'src/core/api/requests.dart';
|
||||
export 'src/core/api/requests.dart';
|
||||
export 'src/core/api/responses.dart';
|
||||
export 'src/core/api/stream_chat_api.dart' show PushProvider;
|
||||
export 'src/core/error/error.dart';
|
||||
export 'src/core/models/action.dart';
|
||||
export 'src/core/models/attachment.dart';
|
||||
export 'src/core/models/attachment_file.dart';
|
||||
export 'src/core/models/channel_config.dart';
|
||||
export 'src/core/models/channel_model.dart';
|
||||
export 'src/core/models/channel_state.dart';
|
||||
export 'src/core/models/command.dart';
|
||||
export 'src/core/models/device.dart';
|
||||
export 'src/core/models/event.dart';
|
||||
export 'src/core/models/filter.dart' show Filter;
|
||||
export 'src/core/models/member.dart';
|
||||
export 'src/core/models/message.dart';
|
||||
export 'src/core/models/mute.dart';
|
||||
export 'src/core/models/own_user.dart';
|
||||
export 'src/core/models/reaction.dart';
|
||||
export 'src/core/models/read.dart';
|
||||
export 'src/core/models/user.dart';
|
||||
export 'src/core/util/extension.dart';
|
||||
export 'src/db/chat_persistence_client.dart';
|
||||
export 'src/event_type.dart';
|
||||
export 'src/location.dart';
|
||||
export 'src/ws/connection_status.dart';
|
||||
|
||||
@@ -1171,7 +1171,7 @@ void main() {
|
||||
verifyNoMoreInteractions(api.channel);
|
||||
});
|
||||
|
||||
test('`.addDevice`', () async {
|
||||
test('`.addDevice should work`', () async {
|
||||
const id = 'test-device-id';
|
||||
const provider = PushProvider.firebase;
|
||||
|
||||
@@ -1185,6 +1185,34 @@ void main() {
|
||||
verifyNoMoreInteractions(api.device);
|
||||
});
|
||||
|
||||
test('`.addDevice should work with pushProviderName`', () async {
|
||||
const id = 'test-device-id';
|
||||
const provider = PushProvider.firebase;
|
||||
const pushProviderName = 'my-custom-config';
|
||||
|
||||
when(
|
||||
() => api.device.addDevice(
|
||||
id,
|
||||
provider,
|
||||
pushProviderName: pushProviderName,
|
||||
),
|
||||
).thenAnswer((_) async => EmptyResponse());
|
||||
|
||||
final res = await client.addDevice(
|
||||
id,
|
||||
provider,
|
||||
pushProviderName: pushProviderName,
|
||||
);
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => api.device.addDevice(
|
||||
id,
|
||||
provider,
|
||||
pushProviderName: pushProviderName,
|
||||
)).called(1);
|
||||
verifyNoMoreInteractions(api.device);
|
||||
});
|
||||
|
||||
test('`.getDevices`', () async {
|
||||
final devices = List.generate(
|
||||
3,
|
||||
|
||||
@@ -20,7 +20,7 @@ void main() {
|
||||
deviceApi = DeviceApi(client);
|
||||
});
|
||||
|
||||
test('addDevice', () async {
|
||||
test('addDevice should work', () async {
|
||||
const deviceId = 'test-device-id';
|
||||
const pushProvider = PushProvider.firebase;
|
||||
|
||||
@@ -44,6 +44,36 @@ void main() {
|
||||
verifyNoMoreInteractions(client);
|
||||
});
|
||||
|
||||
test('addDevice should work with pushProviderName', () async {
|
||||
const deviceId = 'test-device-id';
|
||||
const pushProvider = PushProvider.firebase;
|
||||
const pushProviderName = 'my-custom-config';
|
||||
|
||||
const path = '/devices';
|
||||
|
||||
when(() => client.post(
|
||||
path,
|
||||
data: {
|
||||
'id': deviceId,
|
||||
'push_provider': pushProvider.name,
|
||||
'push_provider_name': pushProviderName,
|
||||
},
|
||||
))
|
||||
.thenAnswer(
|
||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||
|
||||
final res = await deviceApi.addDevice(
|
||||
deviceId,
|
||||
pushProvider,
|
||||
pushProviderName: pushProviderName,
|
||||
);
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.post(path, data: any(named: 'data'))).called(1);
|
||||
verifyNoMoreInteractions(client);
|
||||
});
|
||||
|
||||
test('getDevices', () async {
|
||||
const path = '/devices';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user