Merge branch 'develop' into message-input-controller

This commit is contained in:
Salvatore Giordano
2021-12-13 12:28:32 +01:00
7 changed files with 139 additions and 17 deletions
@@ -1316,6 +1316,10 @@ class StreamChatClient {
},
);
/// Get OpenGraph data of the given [url].
Future<OGAttachmentResponse> enrichUrl(String url) =>
_chatApi.general.enrichUrl(url);
/// Closes the [_ws] connection and resets the [state]
/// If [flushChatPersistence] is true the client deletes all offline
/// user's data.
@@ -96,4 +96,16 @@ class GeneralApi {
return QueryMembersResponse.fromJson(response.data);
}
/// Get OpenGraph data of the given [url].
Future<OGAttachmentResponse> enrichUrl(String url) async {
final response = await _client.get(
'/og',
queryParameters: {
'url': url,
},
);
return OGAttachmentResponse.fromJson(response.data);
}
}
@@ -442,3 +442,43 @@ class ChannelStateResponse extends _BaseResponse {
static ChannelStateResponse fromJson(Map<String, dynamic> json) =>
_$ChannelStateResponseFromJson(json);
}
/// Model response for [Client.enrichUrl] api call.
@JsonSerializable(createToJson: false)
class OGAttachmentResponse extends _BaseResponse {
/// The URL of the page that was scraped.
late String ogScrapeUrl;
/// The URL of the asset.
String? assetUrl;
/// The URL of the author.
String? authorLink;
/// The name of the author.
String? authorName;
/// The URL of the image.
String? imageUrl;
/// The text of the attachment.
String? text;
/// The URL of the thumbnail.
String? thumbUrl;
/// The title of the attachment.
String? title;
/// The URL of the title.
String? titleLink;
/// The type of the attachment.
///
/// 'video' | 'audio' | 'image'
String? type;
/// Create a new instance from a [json].
static OGAttachmentResponse fromJson(Map<String, dynamic> json) =>
_$OGAttachmentResponseFromJson(json);
}
@@ -273,3 +273,18 @@ ChannelStateResponse _$ChannelStateResponseFromJson(
?.map((e) => Read.fromJson(e as Map<String, dynamic>))
.toList() ??
[];
OGAttachmentResponse _$OGAttachmentResponseFromJson(
Map<String, dynamic> json) =>
OGAttachmentResponse()
..duration = json['duration'] as String?
..ogScrapeUrl = json['og_scrape_url'] as String
..assetUrl = json['asset_url'] as String?
..authorLink = json['author_link'] as String?
..authorName = json['author_name'] as String?
..imageUrl = json['image_url'] as String?
..text = json['text'] as String?
..thumbUrl = json['thumb_url'] as String?
..title = json['title'] as String?
..titleLink = json['title_link'] as String?
..type = json['type'] as String?;