Merge branch 'develop' of github.com:GetStream/stream-chat-flutter into fix/message-search-pagination
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
## Upcoming
|
||||
## 2.2.1
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
- Fixed unread indicator not updating correctly
|
||||
- Fix `channel.show` not working because of null body
|
||||
|
||||
## 2.2.0
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
@@ -8,7 +15,9 @@
|
||||
|
||||
- `User` and `OwnUser` classes now have an `image` property. Setting an image will also set the 'image' key on `extraData`, so `user.image` and `user.extraData['image']` is the same.
|
||||
- `User` and `OwnUser` classes now have a `name` property. Setting a name will also set the 'name' key on `extraData`, so `user.name` and `user.extraData['name']` is the same.
|
||||
|
||||
- `Channel` class now has extra `image` getter and setter. As well as an `updateImage` to do a partial update after a channel has been initialized.
|
||||
- `Channel` class now has extra `name` getter and setter. As well as an `updateName` to do a partial update after a channel has been initialized.
|
||||
- Added slow mode which allows a cooldown period after a user sends a message.
|
||||
## 2.1.1
|
||||
|
||||
🐞 Fixed
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -767,7 +767,9 @@ class StreamChatClient {
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
/// Replaces the [channelId] of type [ChannelType] data with [data]
|
||||
/// Replaces the [channelId] of type [ChannelType] data with [data].
|
||||
///
|
||||
/// Use [updateChannelPartial] for a partial update.
|
||||
Future<UpdateChannelResponse> updateChannel(
|
||||
String channelId,
|
||||
String channelType,
|
||||
@@ -781,7 +783,10 @@ class StreamChatClient {
|
||||
message: message,
|
||||
);
|
||||
|
||||
/// Updates the [channelId] of type [ChannelType] data with [data]
|
||||
/// Partial update for the [channelId] of type [ChannelType]. Sets the
|
||||
/// data provided in [set], and removes the attributes given in [unset].
|
||||
///
|
||||
/// Use [updateChannel] for a full update.
|
||||
Future<PartialUpdateChannelResponse> updateChannelPartial(
|
||||
String channelId,
|
||||
String channelType, {
|
||||
@@ -1247,6 +1252,28 @@ class StreamChatClient {
|
||||
language,
|
||||
);
|
||||
|
||||
/// Enables slow mode
|
||||
Future<PartialUpdateChannelResponse> enableSlowdown(
|
||||
String channelId,
|
||||
String channelType,
|
||||
int cooldown,
|
||||
) async =>
|
||||
_chatApi.channel.enableSlowdown(
|
||||
channelId,
|
||||
channelType,
|
||||
cooldown,
|
||||
);
|
||||
|
||||
/// Disables slow mode
|
||||
Future<PartialUpdateChannelResponse> disableSlowdown(
|
||||
String channelId,
|
||||
String channelType,
|
||||
) async =>
|
||||
_chatApi.channel.disableSlowdown(
|
||||
channelId,
|
||||
channelType,
|
||||
);
|
||||
|
||||
/// Pins provided message
|
||||
/// [timeoutOrExpirationDate] can either be a [DateTime] or a value in seconds
|
||||
/// to be added to [DateTime.now]
|
||||
|
||||
@@ -123,6 +123,35 @@ class ChannelApi {
|
||||
return PartialUpdateChannelResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
/// Enable slowdown
|
||||
Future<PartialUpdateChannelResponse> enableSlowdown(
|
||||
String channelId,
|
||||
String channelType,
|
||||
int cooldown,
|
||||
) async {
|
||||
final response = await updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {
|
||||
'cooldown': cooldown,
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// Disable slowdown
|
||||
Future<PartialUpdateChannelResponse> disableSlowdown(
|
||||
String channelId,
|
||||
String channelType,
|
||||
) async {
|
||||
final response = await updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
unset: ['cooldown'],
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
/// Accept invitation to the channel
|
||||
Future<AcceptInviteResponse> acceptChannelInvite(
|
||||
String channelId,
|
||||
@@ -263,6 +292,7 @@ class ChannelApi {
|
||||
) async {
|
||||
final response = await _client.post(
|
||||
'${_getChannelUrl(channelId, channelType)}/show',
|
||||
data: {},
|
||||
);
|
||||
return EmptyResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ class ChannelModel {
|
||||
this.memberCount = 0,
|
||||
this.extraData = const {},
|
||||
this.team,
|
||||
this.cooldown = 0,
|
||||
}) : assert(
|
||||
(cid != null && cid.contains(':')) || (id != null && type != null),
|
||||
'provide either a cid or an id and type',
|
||||
@@ -81,6 +82,10 @@ class ChannelModel {
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly, defaultValue: 0)
|
||||
final int memberCount;
|
||||
|
||||
/// The number of seconds in a cooldown
|
||||
@JsonKey(includeIfNull: false, defaultValue: 0)
|
||||
final int cooldown;
|
||||
|
||||
/// Map of custom channel extraData
|
||||
@JsonKey(
|
||||
includeIfNull: false,
|
||||
@@ -107,6 +112,7 @@ class ChannelModel {
|
||||
'deleted_at',
|
||||
'member_count',
|
||||
'team',
|
||||
'cooldown',
|
||||
];
|
||||
|
||||
/// Shortcut for channel name
|
||||
@@ -133,6 +139,7 @@ class ChannelModel {
|
||||
int? memberCount,
|
||||
Map<String, Object?>? extraData,
|
||||
String? team,
|
||||
int? cooldown,
|
||||
}) =>
|
||||
ChannelModel(
|
||||
id: id ?? this.id,
|
||||
@@ -148,6 +155,7 @@ class ChannelModel {
|
||||
memberCount: memberCount ?? this.memberCount,
|
||||
extraData: extraData ?? this.extraData,
|
||||
team: team ?? this.team,
|
||||
cooldown: cooldown ?? this.cooldown,
|
||||
);
|
||||
|
||||
/// Returns a new [ChannelModel] that is a combination of this channelModel
|
||||
@@ -168,6 +176,7 @@ class ChannelModel {
|
||||
memberCount: other.memberCount,
|
||||
extraData: other.extraData,
|
||||
team: other.team,
|
||||
cooldown: other.cooldown,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) {
|
||||
memberCount: json['member_count'] as int? ?? 0,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>? ?? {},
|
||||
team: json['team'] as String?,
|
||||
cooldown: json['cooldown'] as int? ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,6 +58,7 @@ Map<String, dynamic> _$ChannelModelToJson(ChannelModel instance) {
|
||||
writeNotNull('updated_at', readonly(instance.updatedAt));
|
||||
writeNotNull('deleted_at', readonly(instance.deletedAt));
|
||||
writeNotNull('member_count', readonly(instance.memberCount));
|
||||
val['cooldown'] = instance.cooldown;
|
||||
val['extra_data'] = instance.extraData;
|
||||
writeNotNull('team', readonly(instance.team));
|
||||
return val;
|
||||
|
||||
@@ -184,6 +184,8 @@ class EventChannel extends ChannelModel {
|
||||
DateTime? deletedAt,
|
||||
required int memberCount,
|
||||
Map<String, Object?>? extraData,
|
||||
required int cooldown,
|
||||
String? team,
|
||||
}) : super(
|
||||
id: id,
|
||||
type: type,
|
||||
@@ -197,6 +199,8 @@ class EventChannel extends ChannelModel {
|
||||
deletedAt: deletedAt,
|
||||
memberCount: memberCount,
|
||||
extraData: extraData ?? {},
|
||||
cooldown: cooldown,
|
||||
team: team,
|
||||
);
|
||||
|
||||
/// Create a new instance from a json
|
||||
|
||||
@@ -87,5 +87,7 @@ EventChannel _$EventChannelFromJson(Map<String, dynamic> json) {
|
||||
: DateTime.parse(json['deleted_at'] as String),
|
||||
memberCount: json['member_count'] as int? ?? 0,
|
||||
extraData: json['extra_data'] as Map<String, dynamic>? ?? {},
|
||||
cooldown: json['cooldown'] as int? ?? 0,
|
||||
team: json['team'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@ import 'package:stream_chat/src/client/client.dart';
|
||||
/// Current package version
|
||||
/// Used in [StreamChatClient] to build the `x-stream-client` header
|
||||
// ignore: constant_identifier_names
|
||||
const PACKAGE_VERSION = '2.1.1';
|
||||
const PACKAGE_VERSION = '2.2.1';
|
||||
|
||||
@@ -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: 2.1.1
|
||||
version: 2.2.1
|
||||
repository: https://github.com/GetStream/stream-chat-flutter
|
||||
issue_tracker: https://github.com/GetStream/stream-chat-flutter/issues
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"id": "dev",
|
||||
"type": "team",
|
||||
"frozen": true,
|
||||
"cooldown": 0,
|
||||
"name": "#dev",
|
||||
"image": "https://cdn.chrisshort.net/testing-certificate-chains-in-go/GOPHER_MIC_DROP.png",
|
||||
"example": 1
|
||||
|
||||
+150
@@ -72,6 +72,40 @@ void main() {
|
||||
expect(channel.extraData.containsKey('name'), isTrue);
|
||||
expect(channel.extraData['name'], 'test-channel-name');
|
||||
});
|
||||
|
||||
test('should be able to get and set `image`', () {
|
||||
expect(channel.extraData.isEmpty, isTrue);
|
||||
|
||||
const imageUrl = 'https://getstream.io/some-image';
|
||||
channel.image = imageUrl;
|
||||
|
||||
expect(channel.image, imageUrl);
|
||||
expect(channel.extraData['image'], imageUrl);
|
||||
|
||||
const newImage = 'https://getstream.io/new-image';
|
||||
final newChannelInstance =
|
||||
Channel(client, channelType, channelId, image: newImage);
|
||||
|
||||
expect(newChannelInstance.image, newImage);
|
||||
expect(newChannelInstance.extraData['image'], newImage);
|
||||
});
|
||||
|
||||
test('should be able to get and set `name`', () {
|
||||
expect(channel.extraData.isEmpty, isTrue);
|
||||
|
||||
const name = 'Channel name';
|
||||
channel.name = name;
|
||||
|
||||
expect(channel.name, name);
|
||||
expect(channel.extraData['name'], name);
|
||||
|
||||
const newName = 'New channel name';
|
||||
final newChannelInstance =
|
||||
Channel(client, channelType, channelId, name: newName);
|
||||
|
||||
expect(newChannelInstance.name, newName);
|
||||
expect(newChannelInstance.extraData['name'], newName);
|
||||
});
|
||||
});
|
||||
|
||||
// TODO : test all persistence related logic in this group
|
||||
@@ -192,6 +226,22 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('should throw if trying to set `image`', () {
|
||||
try {
|
||||
channel.image = 'https://stream.io/some-image';
|
||||
} catch (e) {
|
||||
expect(e, isA<StateError>());
|
||||
}
|
||||
});
|
||||
|
||||
test('should throw if trying to set `name`', () {
|
||||
try {
|
||||
channel.name = 'New name';
|
||||
} catch (e) {
|
||||
expect(e, isA<StateError>());
|
||||
}
|
||||
});
|
||||
|
||||
group('`.sendMessage`', () {
|
||||
test('should work fine', () async {
|
||||
final message = Message(id: 'test-message-id');
|
||||
@@ -1192,6 +1242,62 @@ void main() {
|
||||
message: any(named: 'message'))).called(1);
|
||||
});
|
||||
|
||||
test('`.updateImage`', () async {
|
||||
const image = 'https://getstream.io/new-image';
|
||||
|
||||
final channelModel = ChannelModel(
|
||||
cid: channelCid,
|
||||
extraData: {'image': image},
|
||||
);
|
||||
|
||||
when(() => client.updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {'image': image},
|
||||
)).thenAnswer(
|
||||
(_) async => PartialUpdateChannelResponse()..channel = channelModel,
|
||||
);
|
||||
|
||||
final res = await channel.updateImage(image);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.channel.extraData['image'], image);
|
||||
|
||||
verify(() => client.updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {'image': image},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('`.updateName`', () async {
|
||||
const name = 'Name';
|
||||
|
||||
final channelModel = ChannelModel(
|
||||
cid: channelCid,
|
||||
extraData: {'name': name},
|
||||
);
|
||||
|
||||
when(() => client.updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {'name': name},
|
||||
)).thenAnswer(
|
||||
(_) async => PartialUpdateChannelResponse()..channel = channelModel,
|
||||
);
|
||||
|
||||
final res = await channel.updateName(name);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.channel.extraData['name'], name);
|
||||
|
||||
verify(() => client.updateChannelPartial(
|
||||
channelId,
|
||||
channelType,
|
||||
set: {'name': name},
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('`.updatePartial`', () async {
|
||||
const set = {
|
||||
'name': 'Stream Team',
|
||||
@@ -1753,6 +1859,50 @@ void main() {
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('`.enableSlowMode`', () async {
|
||||
const cooldown = 10;
|
||||
|
||||
final channelModel = ChannelModel(
|
||||
cid: channelCid,
|
||||
cooldown: cooldown,
|
||||
);
|
||||
|
||||
when(() => client.enableSlowdown(
|
||||
channelId,
|
||||
channelType,
|
||||
cooldown,
|
||||
)).thenAnswer((_) async => PartialUpdateChannelResponse()
|
||||
..channel = channelModel);
|
||||
|
||||
final res = await channel.enableSlowMode(cooldownInterval: 10);
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.enableSlowdown(
|
||||
channelId,
|
||||
channelType,
|
||||
cooldown,
|
||||
)).called(1);
|
||||
});
|
||||
|
||||
test('`.disableSlowMode`', () async {
|
||||
final channelModel = ChannelModel(
|
||||
cid: channelCid,
|
||||
);
|
||||
|
||||
when(() => client.disableSlowdown(
|
||||
channelId,
|
||||
channelType,
|
||||
)).thenAnswer((_) async => PartialUpdateChannelResponse()
|
||||
..channel = channelModel);
|
||||
|
||||
final res = await channel.disableSlowMode();
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.disableSlowdown(channelId, channelType)).called(1);
|
||||
});
|
||||
|
||||
test('`.banUser`', () async {
|
||||
const userId = 'test-user-id';
|
||||
const options = {'key': 'value'};
|
||||
@@ -550,14 +550,21 @@ void main() {
|
||||
|
||||
final path = '${_getChannelUrl(channelId, channelType)}/show';
|
||||
|
||||
when(() => client.post(path)).thenAnswer(
|
||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||
when(() => client.post(
|
||||
path,
|
||||
data: {},
|
||||
))
|
||||
.thenAnswer(
|
||||
(_) async => successResponse(path, data: <String, dynamic>{}));
|
||||
|
||||
final res = await channelApi.showChannel(channelId, channelType);
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.post(path)).called(1);
|
||||
verify(() => client.post(
|
||||
path,
|
||||
data: {},
|
||||
)).called(1);
|
||||
verifyNoMoreInteractions(client);
|
||||
});
|
||||
|
||||
@@ -605,4 +612,65 @@ void main() {
|
||||
verify(() => client.post(path, data: {})).called(1);
|
||||
verifyNoMoreInteractions(client);
|
||||
});
|
||||
|
||||
test('enableSlowdown', () async {
|
||||
const channelId = 'test-channel-id';
|
||||
const channelType = 'test-channel-type';
|
||||
const cooldown = 10;
|
||||
const set = {
|
||||
'cooldown': 10,
|
||||
};
|
||||
|
||||
final path = _getChannelUrl(channelId, channelType);
|
||||
|
||||
final channelModel = ChannelModel(
|
||||
id: channelId,
|
||||
type: channelType,
|
||||
extraData: set,
|
||||
);
|
||||
|
||||
when(() => client.patch(path, data: {
|
||||
'set': set,
|
||||
})).thenAnswer((_) async => successResponse(path, data: {
|
||||
'channel': channelModel.toJson(),
|
||||
}));
|
||||
|
||||
final res =
|
||||
await channelApi.enableSlowdown(channelId, channelType, cooldown);
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.patch(path, data: {
|
||||
'set': set,
|
||||
})).called(1);
|
||||
verifyNoMoreInteractions(client);
|
||||
});
|
||||
|
||||
test('disableSlowdown', () async {
|
||||
const channelId = 'test-channel-id';
|
||||
const channelType = 'test-channel-type';
|
||||
const unset = ['cooldown'];
|
||||
|
||||
final path = _getChannelUrl(channelId, channelType);
|
||||
|
||||
final channelModel = ChannelModel(
|
||||
id: channelId,
|
||||
type: channelType,
|
||||
);
|
||||
|
||||
when(() => client.patch(path, data: {
|
||||
'unset': unset,
|
||||
})).thenAnswer((_) async => successResponse(path, data: {
|
||||
'channel': channelModel.toJson(),
|
||||
}));
|
||||
|
||||
final res = await channelApi.disableSlowdown(channelId, channelType);
|
||||
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => client.patch(path, data: {
|
||||
'unset': unset,
|
||||
})).called(1);
|
||||
verifyNoMoreInteractions(client);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ void main() {
|
||||
expect(channel.cid, equals('livestream:test'));
|
||||
expect(channel.extraData['cats'], equals(true));
|
||||
expect(channel.extraData['fruit'], equals(['bananas', 'apples']));
|
||||
expect(channel.cooldown, equals(0));
|
||||
});
|
||||
|
||||
test('should serialize to json correctly', () {
|
||||
@@ -24,7 +25,13 @@ void main() {
|
||||
|
||||
expect(
|
||||
channel.toJson(),
|
||||
{'id': 'id', 'type': 'type', 'frozen': false, 'name': 'cool'},
|
||||
{
|
||||
'id': 'id',
|
||||
'type': 'type',
|
||||
'frozen': false,
|
||||
'cooldown': 0,
|
||||
'name': 'cool',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -38,7 +45,13 @@ void main() {
|
||||
|
||||
expect(
|
||||
channel.toJson(),
|
||||
{'id': 'id', 'type': 'type', 'name': 'cool', 'frozen': false},
|
||||
{
|
||||
'id': 'id',
|
||||
'type': 'type',
|
||||
'frozen': false,
|
||||
'cooldown': 0,
|
||||
'name': 'cool',
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,10 +13,11 @@ void main() {
|
||||
expect(reaction.type, 'wow');
|
||||
expect(
|
||||
reaction.user?.toJson(),
|
||||
User(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: const {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan'
|
||||
}).toJson(),
|
||||
User(
|
||||
id: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
image: 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
name: 'Daisy Morgan',
|
||||
).toJson(),
|
||||
);
|
||||
expect(reaction.score, 1);
|
||||
expect(reaction.userId, '2de0297c-f3f2-489d-b930-ef77342edccf');
|
||||
@@ -28,11 +29,11 @@ void main() {
|
||||
messageId: '76cd8c82-b557-4e48-9d12-87995d3a0e04',
|
||||
createdAt: DateTime.parse('2020-01-28T22:17:31.108742Z'),
|
||||
type: 'wow',
|
||||
user:
|
||||
User(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: const {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan'
|
||||
}),
|
||||
user: User(
|
||||
id: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
image: 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
name: 'Daisy Morgan',
|
||||
),
|
||||
userId: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
extraData: {'bananas': 'yes'},
|
||||
score: 1,
|
||||
@@ -58,10 +59,11 @@ void main() {
|
||||
expect(newReaction.type, 'wow');
|
||||
expect(
|
||||
newReaction.user?.toJson(),
|
||||
User(id: '2de0297c-f3f2-489d-b930-ef77342edccf', extraData: const {
|
||||
'image': 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
'name': 'Daisy Morgan',
|
||||
}).toJson(),
|
||||
User(
|
||||
id: '2de0297c-f3f2-489d-b930-ef77342edccf',
|
||||
image: 'https://randomuser.me/api/portraits/women/45.jpg',
|
||||
name: 'Daisy Morgan',
|
||||
).toJson(),
|
||||
);
|
||||
expect(newReaction.score, 1);
|
||||
expect(newReaction.userId, '2de0297c-f3f2-489d-b930-ef77342edccf');
|
||||
|
||||
Reference in New Issue
Block a user