Skip to content

Commit

Permalink
feat(ui, localization): add support for async audio (#2097)
Browse files Browse the repository at this point in the history
Co-authored-by: xsahil03x <[email protected]>
  • Loading branch information
xsahil03x and xsahil03x authored Feb 11, 2025
1 parent e1ec460 commit d2ac7e7
Show file tree
Hide file tree
Showing 130 changed files with 7,145 additions and 896 deletions.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ linter:
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
- prefer_constructors_over_static_methods
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
Expand Down
3 changes: 3 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ command:
photo_manager: ^3.2.0
photo_view: ^0.15.0
rate_limiter: ^1.0.0
record: ^5.2.0
responsive_builder: ^0.7.0
rxdart: ^0.28.0
share_plus: ^10.0.2
Expand Down Expand Up @@ -82,6 +83,8 @@ command:
json_serializable: ^6.7.1
mocktail: ^1.0.0
path: ^1.8.3
path_provider_platform_interface: ^2.0.0
plugin_platform_interface: ^2.0.0
test: ^1.24.6

scripts:
Expand Down
38 changes: 18 additions & 20 deletions packages/stream_chat/lib/src/core/models/attachment_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AttachmentFile {
'File by path is not supported in web, Please provide bytes',
),
assert(
name?.contains('.') ?? true,
name == null || name.isEmpty || name.contains('.'),
'Invalid file name, should also contain file extension',
),
_name = name;
Expand All @@ -47,8 +47,10 @@ class AttachmentFile {
final String? _name;

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

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

/// Converts this into a [MultipartFile]
Future<MultipartFile> toMultipartFile() async {
MultipartFile multiPartFile;

if (CurrentPlatform.isWeb) {
multiPartFile = MultipartFile.fromBytes(
bytes!,
filename: name,
contentType: mediaType,
);
} else {
multiPartFile = await MultipartFile.fromFile(
path!,
filename: name,
contentType: mediaType,
);
}
return multiPartFile;
return switch (CurrentPlatform.type) {
PlatformType.web => MultipartFile.fromBytes(
bytes!,
filename: name,
contentType: mediaType,
),
_ => await MultipartFile.fromFile(
path!,
filename: name,
contentType: mediaType,
),
};
}

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

/// Union class to hold various [UploadState] of a attachment.
@freezed
class UploadState with _$UploadState {
sealed class UploadState with _$UploadState {
// Dummy private constructor in order to use getters
const UploadState._();

Expand Down
8 changes: 4 additions & 4 deletions packages/stream_chat/lib/src/core/models/message_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension MessageStateX on MessageState {

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

Expand Down Expand Up @@ -243,7 +243,7 @@ class MessageState with _$MessageState {

/// Represents the state of an outgoing message.
@freezed
class OutgoingState with _$OutgoingState {
sealed class OutgoingState with _$OutgoingState {
/// Sending state when the message is being sent.
const factory OutgoingState.sending() = Sending;

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

/// Represents the completed state of a message.
@freezed
class CompletedState with _$CompletedState {
sealed class CompletedState with _$CompletedState {
/// Sent state when the message has been successfully sent.
const factory CompletedState.sent() = Sent;

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

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

Expand Down
10 changes: 3 additions & 7 deletions packages/stream_chat/lib/src/core/util/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ extension MapX<K, V> on Map<K?, V?> {
extension StringX on String {
/// returns the media type from the passed file name.
MediaType? get mediaType {
if (toLowerCase().endsWith('heic')) {
return MediaType.parse('image/heic');
} else {
final mimeType = lookupMimeType(this);
if (mimeType == null) return null;
return MediaType.parse(mimeType);
}
final mimeType = lookupMimeType(this);
if (mimeType == null) return null;
return MediaType.parse(mimeType);
}
}
6 changes: 6 additions & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Upcoming

✅ Added

- Added support for `voiceRecording` type attachments.

## 9.2.0+1

- Remove untracked files from the package.
Expand Down
Loading

0 comments on commit d2ac7e7

Please sign in to comment.