-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor!(ui, llc): Attachments refactor. #1667
Changes from 8 commits
f246de5
e8de288
b2171b5
db6febc
572207c
93b4158
72e0c7b
ff3ad6b
795c494
eeb957f
115dced
9f4c31c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ class AttachmentFile { | |
String? get extension => name?.split('.').last; | ||
|
||
/// The mime type of this file. | ||
MediaType? get mimeType => name?.mimeType; | ||
MediaType? get mediaType => name?.mediaType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a breaking change? |
||
|
||
/// Serialize to json | ||
Map<String, dynamic> toJson() => _$AttachmentFileToJson(this); | ||
|
@@ -75,13 +75,13 @@ class AttachmentFile { | |
multiPartFile = MultipartFile.fromBytes( | ||
bytes!, | ||
filename: name, | ||
contentType: mimeType, | ||
contentType: mediaType, | ||
); | ||
} else { | ||
multiPartFile = await MultipartFile.fromFile( | ||
path!, | ||
filename: name, | ||
contentType: mimeType, | ||
contentType: mediaType, | ||
); | ||
} | ||
return multiPartFile; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'package:stream_chat/src/core/models/attachment.dart'; | ||
|
||
/// {@template giphy_info_type} | ||
/// The different types of quality for a Giphy attachment. | ||
/// {@endtemplate} | ||
enum GiphyInfoType { | ||
/// Original quality giphy, the largest size to load. | ||
original('original'), | ||
|
||
/// Lower quality with a fixed height, adjusts width according to the | ||
/// Giphy aspect ratio. Lower size than [original]. | ||
fixedHeight('fixed_height'), | ||
|
||
/// Still image of the [fixedHeight] giphy. | ||
fixedHeightStill('fixed_height_still'), | ||
|
||
/// Lower quality with a fixed height with width adjusted according to the | ||
/// aspect ratio and played at a lower frame rate. Significantly lower size, | ||
/// but visually less appealing. | ||
fixedHeightDownsampled('fixed_height_downsampled'); | ||
|
||
/// {@macro giphy_info_type} | ||
const GiphyInfoType(this.value); | ||
|
||
/// The value of the [GiphyInfoType]. | ||
final String value; | ||
} | ||
|
||
/// {@template giphy_info} | ||
/// A class that contains extra information about a Giphy attachment. | ||
/// {@endtemplate} | ||
class GiphyInfo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious if need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed. Used just to store some values. |
||
/// {@macro giphy_info} | ||
const GiphyInfo({ | ||
required this.url, | ||
required this.width, | ||
required this.height, | ||
}); | ||
|
||
/// The url for the Giphy image. | ||
final String url; | ||
|
||
/// The width of the Giphy image. | ||
final double width; | ||
|
||
/// The height of the Giphy image. | ||
final double height; | ||
|
||
@override | ||
String toString() => 'GiphyInfo{url: $url, width: $width, height: $height}'; | ||
} | ||
|
||
/// GiphyInfo extension on [Attachment] class. | ||
extension GiphyInfoX on Attachment { | ||
/// Returns the [GiphyInfo] for the given [type]. | ||
GiphyInfo? giphyInfo(GiphyInfoType type) { | ||
final giphy = extraData['giphy'] as Map<String, Object?>?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we extract |
||
if (giphy == null) return null; | ||
|
||
final info = giphy[type.value] as Map<String, Object?>?; | ||
if (info == null) return null; | ||
|
||
return GiphyInfo( | ||
url: info['url']! as String, | ||
width: double.parse(info['width']! as String), | ||
height: double.parse(info['height']! as String), | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment just duplicates the code below.
Could we put the reason why we're doing this instead (why we consider it as
urlPreview
)? 🙂