Skip to content

Commit d2ac7e7

Browse files
authored
feat(ui, localization): add support for async audio (#2097)
Co-authored-by: xsahil03x <[email protected]>
1 parent e1ec460 commit d2ac7e7

File tree

130 files changed

+7145
-896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+7145
-896
lines changed

analysis_options.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ linter:
8282
- prefer_const_constructors_in_immutables
8383
- prefer_const_declarations
8484
- prefer_const_literals_to_create_immutables
85-
- prefer_constructors_over_static_methods
8685
- prefer_contains
8786
- prefer_equal_for_default_values
8887
- prefer_final_fields

melos.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ command:
5353
photo_manager: ^3.2.0
5454
photo_view: ^0.15.0
5555
rate_limiter: ^1.0.0
56+
record: ^5.2.0
5657
responsive_builder: ^0.7.0
5758
rxdart: ^0.28.0
5859
share_plus: ^10.0.2
@@ -82,6 +83,8 @@ command:
8283
json_serializable: ^6.7.1
8384
mocktail: ^1.0.0
8485
path: ^1.8.3
86+
path_provider_platform_interface: ^2.0.0
87+
plugin_platform_interface: ^2.0.0
8588
test: ^1.24.6
8689

8790
scripts:

packages/stream_chat/lib/src/core/models/attachment_file.dart

+18-20
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AttachmentFile {
2828
'File by path is not supported in web, Please provide bytes',
2929
),
3030
assert(
31-
name?.contains('.') ?? true,
31+
name == null || name.isEmpty || name.contains('.'),
3232
'Invalid file name, should also contain file extension',
3333
),
3434
_name = name;
@@ -47,8 +47,10 @@ class AttachmentFile {
4747
final String? _name;
4848

4949
/// File name including its extension.
50-
String? get name =>
51-
_name ?? path?.split(CurrentPlatform.isWindows ? r'\' : '/').last;
50+
String? get name {
51+
if (_name case final name? when name.isNotEmpty) return name;
52+
return path?.split(CurrentPlatform.isWindows ? r'\' : '/').last;
53+
}
5254

5355
/// Byte data for this file. Particularly useful if you want to manipulate
5456
/// its data or easily upload to somewhere else.
@@ -69,22 +71,18 @@ class AttachmentFile {
6971

7072
/// Converts this into a [MultipartFile]
7173
Future<MultipartFile> toMultipartFile() async {
72-
MultipartFile multiPartFile;
73-
74-
if (CurrentPlatform.isWeb) {
75-
multiPartFile = MultipartFile.fromBytes(
76-
bytes!,
77-
filename: name,
78-
contentType: mediaType,
79-
);
80-
} else {
81-
multiPartFile = await MultipartFile.fromFile(
82-
path!,
83-
filename: name,
84-
contentType: mediaType,
85-
);
86-
}
87-
return multiPartFile;
74+
return switch (CurrentPlatform.type) {
75+
PlatformType.web => MultipartFile.fromBytes(
76+
bytes!,
77+
filename: name,
78+
contentType: mediaType,
79+
),
80+
_ => await MultipartFile.fromFile(
81+
path!,
82+
filename: name,
83+
contentType: mediaType,
84+
),
85+
};
8886
}
8987

9088
/// Creates a copy of this [AttachmentFile] but with the given fields
@@ -106,7 +104,7 @@ class AttachmentFile {
106104

107105
/// Union class to hold various [UploadState] of a attachment.
108106
@freezed
109-
class UploadState with _$UploadState {
107+
sealed class UploadState with _$UploadState {
110108
// Dummy private constructor in order to use getters
111109
const UploadState._();
112110

packages/stream_chat/lib/src/core/models/message_state.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extension MessageStateX on MessageState {
134134

135135
/// Represents the various states a message can be in.
136136
@freezed
137-
class MessageState with _$MessageState {
137+
sealed class MessageState with _$MessageState {
138138
/// Initial state when the message is created.
139139
const factory MessageState.initial() = MessageInitial;
140140

@@ -243,7 +243,7 @@ class MessageState with _$MessageState {
243243

244244
/// Represents the state of an outgoing message.
245245
@freezed
246-
class OutgoingState with _$OutgoingState {
246+
sealed class OutgoingState with _$OutgoingState {
247247
/// Sending state when the message is being sent.
248248
const factory OutgoingState.sending() = Sending;
249249

@@ -262,7 +262,7 @@ class OutgoingState with _$OutgoingState {
262262

263263
/// Represents the completed state of a message.
264264
@freezed
265-
class CompletedState with _$CompletedState {
265+
sealed class CompletedState with _$CompletedState {
266266
/// Sent state when the message has been successfully sent.
267267
const factory CompletedState.sent() = Sent;
268268

@@ -281,7 +281,7 @@ class CompletedState with _$CompletedState {
281281

282282
/// Represents the failed state of a message.
283283
@freezed
284-
class FailedState with _$FailedState {
284+
sealed class FailedState with _$FailedState {
285285
/// Sending failed state when the message fails to be sent.
286286
const factory FailedState.sendingFailed() = SendingFailed;
287287

packages/stream_chat/lib/src/core/util/extension.dart

+3-7
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ extension MapX<K, V> on Map<K?, V?> {
2222
extension StringX on String {
2323
/// returns the media type from the passed file name.
2424
MediaType? get mediaType {
25-
if (toLowerCase().endsWith('heic')) {
26-
return MediaType.parse('image/heic');
27-
} else {
28-
final mimeType = lookupMimeType(this);
29-
if (mimeType == null) return null;
30-
return MediaType.parse(mimeType);
31-
}
25+
final mimeType = lookupMimeType(this);
26+
if (mimeType == null) return null;
27+
return MediaType.parse(mimeType);
3228
}
3329
}

packages/stream_chat_flutter/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Upcoming
2+
3+
✅ Added
4+
5+
- Added support for `voiceRecording` type attachments.
6+
17
## 9.2.0+1
28

39
- Remove untracked files from the package.

0 commit comments

Comments
 (0)