migrate chatty
This commit is contained in:
@@ -11,7 +11,7 @@ class StreamApiImpl extends StreamApiRepository {
|
||||
final StreamChatClient _client;
|
||||
|
||||
@override
|
||||
Future<ChatUser> connectUser(ChatUser user, String token) async {
|
||||
Future<ChatUser> connectUser(ChatUser user, String? token) async {
|
||||
Map<String, dynamic> extraData = {};
|
||||
if (user.image != null) {
|
||||
extraData['image'] = user.image;
|
||||
@@ -21,7 +21,7 @@ class StreamApiImpl extends StreamApiRepository {
|
||||
}
|
||||
await _client.disconnect();
|
||||
await _client.connectUser(
|
||||
User(id: user.id, extraData: extraData),
|
||||
User(id: user.id!, extraData: extraData as Map<String, Object>),
|
||||
token,
|
||||
);
|
||||
return user;
|
||||
@@ -31,12 +31,12 @@ class StreamApiImpl extends StreamApiRepository {
|
||||
Future<List<ChatUser>> getChatUsers() async {
|
||||
final result = await _client.queryUsers();
|
||||
final chatUsers = result.users
|
||||
.where((element) => element.id != _client.state.user.id)
|
||||
.where((element) => element.id != _client.state.user!.id)
|
||||
.map(
|
||||
(e) => ChatUser(
|
||||
id: e.id,
|
||||
name: e.name,
|
||||
image: e.extraData['image'],
|
||||
image: e.extraData['image'] as String?,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
@@ -44,10 +44,10 @@ class StreamApiImpl extends StreamApiRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> getToken(String userId) async {
|
||||
Future<String?> getToken(String userId) async {
|
||||
//TODO: use your own implementation in Production
|
||||
final response = await http.post(
|
||||
'your_backend_url',
|
||||
Uri.parse('your_backend_url'),
|
||||
body: jsonEncode(<String, String>{'id': userId}),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
@@ -62,25 +62,25 @@ class StreamApiImpl extends StreamApiRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Channel> createGroupChat(String id, String name, List<String> members,
|
||||
{String image}) async {
|
||||
Future<Channel> createGroupChat(String id, String? name, List<String?>? members,
|
||||
{String? image}) async {
|
||||
final channel = _client.channel('messaging', id: id, extraData: {
|
||||
'name': name,
|
||||
'image': image,
|
||||
'members': [_client.state.user.id, ...members],
|
||||
'name': name!,
|
||||
'image': image!,
|
||||
'members': [_client.state.user!.id, ...members!],
|
||||
});
|
||||
await channel.watch();
|
||||
return channel;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Channel> createSimpleChat(String friendId) async {
|
||||
Future<Channel> createSimpleChat(String? friendId) async {
|
||||
final channel = _client.channel('messaging',
|
||||
id: '${_client.state.user.id.hashCode}${friendId.hashCode}',
|
||||
id: '${_client.state.user!.id.hashCode}${friendId.hashCode}',
|
||||
extraData: {
|
||||
'members': [
|
||||
friendId,
|
||||
_client.state.user.id,
|
||||
_client.state.user!.id,
|
||||
],
|
||||
});
|
||||
await channel.watch();
|
||||
@@ -99,6 +99,6 @@ class StreamApiImpl extends StreamApiRepository {
|
||||
User(id: userId),
|
||||
token,
|
||||
);
|
||||
return _client.state.user.name != null && _client.state.user.name != userId;
|
||||
return _client.state.user!.name != null && _client.state.user!.name != userId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user