Merge pull request #255 from GetStream/deprecate-setUser
Deprecate `setUser` with `connectUser`
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
## 1.0.2-beta
|
||||
|
||||
- Deprecated `setUser`, `setGuestUser`, `setUserWithProvider` in favor of `connectUser`, `connectGuestUser`, `connectUserWithProvider`
|
||||
- Optimised reaction updates - i.e., Update first call Api later.
|
||||
|
||||
## 1.0.1-beta
|
||||
|
||||
- Fixed pub analysis issues
|
||||
|
||||
@@ -10,7 +10,7 @@ Future<void> main() async {
|
||||
/// a backend to generate a user token using our server SDK.
|
||||
/// Please see the following for more information:
|
||||
/// https://getstream.io/chat/docs/ios_user_setup_and_tokens/
|
||||
await client.setUser(
|
||||
await client.connectUser(
|
||||
User(
|
||||
id: 'cool-shadow-7',
|
||||
extraData: {
|
||||
|
||||
@@ -141,9 +141,9 @@ class SendReactionResponse extends _BaseResponse {
|
||||
_$SendReactionResponseFromJson(json);
|
||||
}
|
||||
|
||||
/// Model response for [StreamChatClient.setGuestUser] api call
|
||||
/// Model response for [StreamChatClient.connectGuestUser] api call
|
||||
@JsonSerializable(createToJson: false)
|
||||
class SetGuestUserResponse extends _BaseResponse {
|
||||
class ConnectGuestUserResponse extends _BaseResponse {
|
||||
/// Guest user access token
|
||||
String accessToken;
|
||||
|
||||
@@ -151,8 +151,8 @@ class SetGuestUserResponse extends _BaseResponse {
|
||||
User user;
|
||||
|
||||
/// Create a new instance from a json
|
||||
static SetGuestUserResponse fromJson(Map<String, dynamic> json) =>
|
||||
_$SetGuestUserResponseFromJson(json);
|
||||
static ConnectGuestUserResponse fromJson(Map<String, dynamic> json) =>
|
||||
_$ConnectGuestUserResponseFromJson(json);
|
||||
}
|
||||
|
||||
/// Model response for [StreamChatClient.updateUser] api call
|
||||
|
||||
@@ -123,8 +123,8 @@ SendReactionResponse _$SendReactionResponseFromJson(Map json) {
|
||||
));
|
||||
}
|
||||
|
||||
SetGuestUserResponse _$SetGuestUserResponseFromJson(Map json) {
|
||||
return SetGuestUserResponse()
|
||||
ConnectGuestUserResponse _$ConnectGuestUserResponseFromJson(Map json) {
|
||||
return ConnectGuestUserResponse()
|
||||
..duration = json['duration'] as String
|
||||
..accessToken = json['access_token'] as String
|
||||
..user = json['user'] == null
|
||||
|
||||
@@ -146,7 +146,7 @@ class StreamChatClient {
|
||||
|
||||
/// A function in which you send a request to your own backend to get a Stream Chat API token.
|
||||
/// The token will be the return value of the function.
|
||||
/// It's used by the client to refresh the token once expired or to set the user without a predefined token using [setUserWithProvider].
|
||||
/// It's used by the client to refresh the token once expired or to connect the user without a predefined token using [connectUserWithProvider].
|
||||
final TokenProvider tokenProvider;
|
||||
|
||||
/// [Dio] httpClient
|
||||
@@ -271,7 +271,7 @@ class StreamChatClient {
|
||||
|
||||
httpClient.unlock();
|
||||
|
||||
await setUser(User(id: userId), newToken);
|
||||
await connectUser(User(id: userId), newToken);
|
||||
|
||||
try {
|
||||
return await httpClient.request(
|
||||
@@ -344,7 +344,12 @@ class StreamChatClient {
|
||||
|
||||
/// Set the current user, this triggers a connection to the API.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<Event> setUser(User user, String token) async {
|
||||
@Deprecated('Use `connectUser` instead. Will be removed in Future releases')
|
||||
Future<Event> setUser(User user, String token) => connectUser(user, token);
|
||||
|
||||
/// Connects the current user, this triggers a connection to the API.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<Event> connectUser(User user, String token) async {
|
||||
if (_connectCompleter != null && !_connectCompleter.isCompleted) {
|
||||
logger.warning('Already connecting');
|
||||
throw Exception('Already connecting');
|
||||
@@ -352,7 +357,7 @@ class StreamChatClient {
|
||||
|
||||
_connectCompleter = Completer();
|
||||
|
||||
logger.info('set user');
|
||||
logger.info('connect user');
|
||||
state.user = OwnUser.fromJson(user.toJson());
|
||||
this.token = token;
|
||||
_anonymous = false;
|
||||
@@ -368,15 +373,21 @@ class StreamChatClient {
|
||||
|
||||
/// Set the current user using the [tokenProvider] to fetch the token.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<void> setUserWithProvider(User user) async {
|
||||
@Deprecated(
|
||||
'Use `connectUserWithProvider` instead. Will be removed in Future releases')
|
||||
Future<Event> setUserWithProvider(User user) => connectUserWithProvider(user);
|
||||
|
||||
/// Connects the current user using the [tokenProvider] to fetch the token.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<Event> connectUserWithProvider(User user) async {
|
||||
if (tokenProvider == null) {
|
||||
throw Exception('''
|
||||
TokenProvider must be provided in the constructor in order to use `setUserWithProvider` method.
|
||||
Use `setUser` providing a token.
|
||||
TokenProvider must be provided in the constructor in order to use `connectUserWithProvider` method.
|
||||
Use `connectUser` providing a token.
|
||||
''');
|
||||
}
|
||||
final token = await tokenProvider(user.id);
|
||||
return setUser(user, token);
|
||||
return connectUser(user, token);
|
||||
}
|
||||
|
||||
/// Stream of [Event] coming from websocket connection
|
||||
@@ -573,7 +584,7 @@ class StreamChatClient {
|
||||
}
|
||||
if (wsConnectionStatus != ConnectionStatus.connected) {
|
||||
final errorMessage =
|
||||
'You cannot use queryChannels without an active connection. Please call setUser to connect the client.';
|
||||
'You cannot use queryChannels without an active connection. Please call `connectUser` to connect the client.';
|
||||
if (persistenceEnabled) {
|
||||
logger.warning(
|
||||
'$errorMessage\nTrying to retrieve channels from the offline storage.');
|
||||
@@ -869,7 +880,13 @@ class StreamChatClient {
|
||||
|
||||
/// Set the current user with an anonymous id, this triggers a connection to the API.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<Event> setAnonymousUser() async {
|
||||
@Deprecated(
|
||||
'Use `connectAnonymousUser` instead. Will be removed in Future releases')
|
||||
Future<Event> setAnonymousUser() => connectAnonymousUser();
|
||||
|
||||
/// Connects the current user with an anonymous id, this triggers a connection to the API.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<Event> connectAnonymousUser() async {
|
||||
if (_connectCompleter != null && !_connectCompleter.isCompleted) {
|
||||
logger.warning('Already connecting');
|
||||
throw Exception('Already connecting');
|
||||
@@ -892,13 +909,19 @@ class StreamChatClient {
|
||||
|
||||
/// Set the current user as guest, this triggers a connection to the API.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<void> setGuestUser(User user) async {
|
||||
@Deprecated(
|
||||
'Use `connectGuestUser` instead. Will be removed in Future releases')
|
||||
Future<Event> setGuestUser(User user) => connectGuestUser(user);
|
||||
|
||||
/// Connects the current user as guest, this triggers a connection to the API.
|
||||
/// It returns a [Future] that resolves when the connection is setup.
|
||||
Future<Event> connectGuestUser(User user) async {
|
||||
_anonymous = true;
|
||||
final response = await post('/guest', data: {'user': user.toJson()})
|
||||
.then((res) => decode<SetGuestUserResponse>(
|
||||
res.data, SetGuestUserResponse.fromJson))
|
||||
.then((res) => decode<ConnectGuestUserResponse>(
|
||||
res.data, ConnectGuestUserResponse.fromJson))
|
||||
.whenComplete(() => _anonymous = false);
|
||||
return setUser(
|
||||
return connectUser(
|
||||
response.user,
|
||||
response.accessToken,
|
||||
);
|
||||
|
||||
@@ -2,4 +2,4 @@ import 'package:stream_chat/src/client.dart';
|
||||
|
||||
/// Current package version
|
||||
/// Used in [StreamChatClient] to build the `x-stream-client` header
|
||||
const PACKAGE_VERSION = '1.0.1-beta';
|
||||
const PACKAGE_VERSION = '1.0.2-beta';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: stream_chat
|
||||
homepage: https://getstream.io/
|
||||
description: The official Dart client for Stream Chat, a service for building chat applications.
|
||||
version: 1.0.1-beta
|
||||
version: 1.0.2-beta
|
||||
repository: https://github.com/GetStream/stream-chat-flutter
|
||||
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues
|
||||
|
||||
|
||||
@@ -3496,10 +3496,11 @@ void main() {
|
||||
expect(response.users, isA<Map<String, User>>());
|
||||
});
|
||||
|
||||
test('SetGuestUserResponse', () {
|
||||
test('ConnectGuestUserResponse', () {
|
||||
const jsonExample =
|
||||
r'{"user":{"id":"guest-ac612aee-25fe-49fb-b1af-969e41f452a0-wild-breeze-7","role":"guest","created_at":"2020-02-03T10:19:01.538434Z","updated_at":"2020-02-03T10:19:01.539543Z","banned":false,"online":false},"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiZ3Vlc3QtYWM2MTJhZWUtMjVmZS00OWZiLWIxYWYtOTY5ZTQxZjQ1MmEwLXdpbGQtYnJlZXplLTcifQ.mmoFGu7oJjpFsp7nFN78UbIpO7gowbuIbyoppsuvbXA","duration":"4.66ms"}';
|
||||
final response = SetGuestUserResponse.fromJson(json.decode(jsonExample));
|
||||
final response =
|
||||
ConnectGuestUserResponse.fromJson(json.decode(jsonExample));
|
||||
expect(response.user, isA<User>());
|
||||
expect(response.accessToken, isA<String>());
|
||||
});
|
||||
|
||||
@@ -390,7 +390,7 @@ void main() {
|
||||
});
|
||||
|
||||
group('user', () {
|
||||
test('setUser should throw exception', () async {
|
||||
test('connectUser should throw exception', () async {
|
||||
final mockDio = MockDio();
|
||||
|
||||
when(mockDio.options).thenReturn(BaseOptions());
|
||||
@@ -422,7 +422,7 @@ void main() {
|
||||
httpClient: mockDio,
|
||||
);
|
||||
|
||||
expect(() => client.setUserWithProvider(User(id: 'test-id')),
|
||||
expect(() => client.connectUserWithProvider(User(id: 'test-id')),
|
||||
throwsA(isA<Exception>()));
|
||||
});
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
cupertino_icons: ^1.0.0
|
||||
stream_chat:
|
||||
path: ../../stream_chat
|
||||
stream_chat: ^1.0.0-beta
|
||||
stream_chat_persistence:
|
||||
path: ../
|
||||
|
||||
|
||||
Reference in New Issue
Block a user