fix: interceptor handlers

This commit is contained in:
Felix Angelov
2021-03-24 00:09:00 -05:00
parent 67f62d0692
commit 537bcf1abb
5 changed files with 49 additions and 48 deletions
@@ -2,6 +2,6 @@
<Workspace
version = "1.0">
<FileRef
location = "group:Runner.xcodeproj">
location = "self:">
</FileRef>
</Workspace>
+15 -16
View File
@@ -2,12 +2,9 @@ import 'package:flutter/material.dart';
import 'package:stream_chat/stream_chat.dart';
Future<void> main() async {
/// Create a new instance of [StreamChatClient] passing the apikey obtained from your
/// project dashboard.
final client = StreamChatClient(
'b67pax5b2wdq',
logLevel: Level.INFO,
);
/// Create a new instance of [StreamChatClient]
/// by passing the apikey obtained from your project dashboard.
final client = StreamChatClient('b67pax5b2wdq', logLevel: Level.INFO);
/// Set the current user. In a production scenario, this should be done using
/// a backend to generate a user token using our server SDK.
@@ -21,7 +18,7 @@ Future<void> main() async {
'https://getstream.io/random_png/?id=cool-shadow-7&amp;name=Cool+shadow',
},
),
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo',
'''eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiY29vbC1zaGFkb3ctNyJ9.gkOlCRb1qgy4joHPaxFwPOdXcGvSPvp6QY0S4mpRkVo''',
);
/// Creates a channel using the type `messaging` and `godevs`.
@@ -44,15 +41,16 @@ Future<void> main() async {
/// Example using Stream's Low Level Dart client.
class StreamExample extends StatelessWidget {
/// To initialize this example, an instance of [client] and [channel] is required.
/// To initialize this example, an instance of
/// [client] and [channel] is required.
const StreamExample({
Key key,
@required this.client,
@required this.channel,
}) : super(key: key);
/// Instance of [StreamChatClient] we created earlier. This contains information about
/// our application and connection state.
/// Instance of [StreamChatClient] we created earlier.
/// This contains information about our application and connection state.
final StreamChatClient client;
/// The channel we'd like to observe and participate.
@@ -104,8 +102,8 @@ class HomeScreen extends StatelessWidget {
}
return const Center(
child: SizedBox(
width: 100.0,
height: 100.0,
width: 100,
height: 100,
child: CircularProgressIndicator(),
),
);
@@ -180,7 +178,7 @@ class _MessageViewState extends State<MessageView> {
return Align(
alignment: Alignment.centerRight,
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: Text(item.text),
),
);
@@ -188,7 +186,7 @@ class _MessageViewState extends State<MessageView> {
return Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: Text(item.text),
),
);
@@ -197,7 +195,7 @@ class _MessageViewState extends State<MessageView> {
),
),
Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: Row(
children: [
Expanded(
@@ -245,7 +243,8 @@ class _MessageViewState extends State<MessageView> {
}
}
/// Helper extension for quickly retrieving the current user id from a [StreamChatClient].
/// Helper extension for quickly retrieving
/// the current user id from a [StreamChatClient].
extension on StreamChatClient {
String get uid => state.user.id;
}
+5 -4
View File
@@ -1,21 +1,22 @@
name: example
description: A new Flutter project.
publish_to: 'none'
publish_to: "none"
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
cupertino_icons: ^1.0.0
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
stream_chat:
stream_chat:
path: ../
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
uses-material-design: true
+27 -26
View File
@@ -280,8 +280,7 @@ class StreamChatClient {
data: $stringData
''');
return options;
handler.next(options);
},
onError: _tokenExpiredInterceptor,
),
@@ -315,33 +314,35 @@ class StreamChatClient {
await connectUser(User(id: userId), newToken);
try {
return await httpClient.request(
err.requestOptions.path,
cancelToken: err.requestOptions.cancelToken,
data: err.requestOptions.data,
onReceiveProgress: err.requestOptions.onReceiveProgress,
onSendProgress: err.requestOptions.onSendProgress,
queryParameters: err.requestOptions.queryParameters,
options: Options(
method: err.requestOptions.method,
sendTimeout: err.requestOptions.sendTimeout,
receiveTimeout: err.requestOptions.receiveTimeout,
extra: err.requestOptions.extra,
headers: err.requestOptions.headers,
responseType: err.requestOptions.responseType,
contentType: err.requestOptions.contentType,
validateStatus: err.requestOptions.validateStatus,
receiveDataWhenStatusError:
err.requestOptions.receiveDataWhenStatusError,
followRedirects: err.requestOptions.followRedirects,
maxRedirects: err.requestOptions.maxRedirects,
requestEncoder: err.requestOptions.requestEncoder,
responseDecoder: err.requestOptions.responseDecoder,
listFormat: err.requestOptions.listFormat,
handler.resolve(
await httpClient.request(
err.requestOptions.path,
cancelToken: err.requestOptions.cancelToken,
data: err.requestOptions.data,
onReceiveProgress: err.requestOptions.onReceiveProgress,
onSendProgress: err.requestOptions.onSendProgress,
queryParameters: err.requestOptions.queryParameters,
options: Options(
method: err.requestOptions.method,
sendTimeout: err.requestOptions.sendTimeout,
receiveTimeout: err.requestOptions.receiveTimeout,
extra: err.requestOptions.extra,
headers: err.requestOptions.headers,
responseType: err.requestOptions.responseType,
contentType: err.requestOptions.contentType,
validateStatus: err.requestOptions.validateStatus,
receiveDataWhenStatusError:
err.requestOptions.receiveDataWhenStatusError,
followRedirects: err.requestOptions.followRedirects,
maxRedirects: err.requestOptions.maxRedirects,
requestEncoder: err.requestOptions.requestEncoder,
responseDecoder: err.requestOptions.responseDecoder,
listFormat: err.requestOptions.listFormat,
),
),
);
} catch (err) {
return err;
handler.reject(err);
}
}
}
@@ -871,7 +871,7 @@ void main() {
expect(channelState.messages[0], isNotNull);
expect(
channelState.messages[0].createdAt,
DateTime.parse('2,020-01-29T03:23:02.843948Z'),
DateTime.parse('2020-01-29T03:23:02.843948Z'),
);
expect(channelState.messages[0].user, isA<User>());
expect(channelState.watcherCount, 5);