@@ -38,10 +38,6 @@ import 'package:stream_chat/src/core/models/member.dart';
|
||||
/// [LogRecord] as the only parameter.
|
||||
typedef LogHandlerFunction = void Function(LogRecord record);
|
||||
|
||||
/// A function which can be used to request a Stream Chat API token from your
|
||||
/// own backend server. Function requires a single [userId].
|
||||
typedef TokenProvider = Future<String> Function(String userId);
|
||||
|
||||
final _levelEmojiMapper = {
|
||||
Level.INFO: 'ℹ️',
|
||||
Level.WARNING: '⚠️',
|
||||
@@ -583,7 +579,6 @@ class StreamChatClient {
|
||||
}
|
||||
|
||||
logger.info('Query channel start');
|
||||
print('Query Channel Started : ${DateTime.now()}');
|
||||
final res = await _chatApi.channel.queryChannels(
|
||||
filter: filter,
|
||||
sort: sort,
|
||||
@@ -594,7 +589,6 @@ class StreamChatClient {
|
||||
messageLimit: messageLimit,
|
||||
paginationParams: paginationParams,
|
||||
);
|
||||
print('Query Channel Completed : ${DateTime.now()}');
|
||||
|
||||
if (res.channels.isEmpty && paginationParams.offset == 0) {
|
||||
logger.warning('''
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:stream_chat/src/core/api/responses.dart';
|
||||
import 'package:stream_chat/src/core/http/stream_http_client.dart';
|
||||
import 'package:stream_chat/src/core/util/extension.dart';
|
||||
import 'package:stream_chat/src/core/models/attachment_file.dart';
|
||||
|
||||
/// Class responsible for uploading images and files to a given channel
|
||||
@@ -70,29 +69,10 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader {
|
||||
ProgressCallback? onSendProgress,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
final filename = file.path?.split('/').last ?? file.name;
|
||||
final mimeType = filename?.mimeType;
|
||||
|
||||
MultipartFile? multiPartFile;
|
||||
if (file.path != null) {
|
||||
multiPartFile = await MultipartFile.fromFile(
|
||||
file.path!,
|
||||
filename: filename,
|
||||
contentType: mimeType,
|
||||
);
|
||||
} else if (file.bytes != null) {
|
||||
multiPartFile = MultipartFile.fromBytes(
|
||||
file.bytes!,
|
||||
filename: filename,
|
||||
contentType: mimeType,
|
||||
);
|
||||
}
|
||||
|
||||
final response = await _client.post(
|
||||
final multiPartFile = await file.toMultipartFile();
|
||||
final response = await _client.postFile(
|
||||
'/channels/$channelType/$channelId/image',
|
||||
data: FormData.fromMap({
|
||||
'file': multiPartFile,
|
||||
}),
|
||||
multiPartFile,
|
||||
onSendProgress: onSendProgress,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
@@ -107,29 +87,10 @@ class StreamAttachmentFileUploader implements AttachmentFileUploader {
|
||||
ProgressCallback? onSendProgress,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
final filename = file.path?.split('/').last ?? file.name;
|
||||
final mimeType = filename?.mimeType;
|
||||
|
||||
MultipartFile? multiPartFile;
|
||||
if (file.path != null) {
|
||||
multiPartFile = await MultipartFile.fromFile(
|
||||
file.path!,
|
||||
filename: filename,
|
||||
contentType: mimeType,
|
||||
);
|
||||
} else if (file.bytes != null) {
|
||||
multiPartFile = MultipartFile.fromBytes(
|
||||
file.bytes!,
|
||||
filename: filename,
|
||||
contentType: mimeType,
|
||||
);
|
||||
}
|
||||
|
||||
final response = await _client.post(
|
||||
final multiPartFile = await file.toMultipartFile();
|
||||
final response = await _client.postFile(
|
||||
'/channels/$channelType/$channelId/file',
|
||||
data: FormData.fromMap({
|
||||
'file': multiPartFile,
|
||||
}),
|
||||
multiPartFile,
|
||||
onSendProgress: onSendProgress,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
@@ -59,7 +59,6 @@ class ChannelApi {
|
||||
bool presence = false,
|
||||
PaginationParams paginationParams = const PaginationParams(),
|
||||
}) async {
|
||||
print('Query Channel Started 2 : ${DateTime.now()}');
|
||||
final response = await _client.get(
|
||||
'/channels',
|
||||
queryParameters: {
|
||||
@@ -80,7 +79,6 @@ class ChannelApi {
|
||||
})
|
||||
},
|
||||
);
|
||||
print('Query Channel Completed 2 : ${DateTime.now()}');
|
||||
return QueryChannelsResponse.fromJson(response.data);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ enum PushProvider {
|
||||
apn
|
||||
}
|
||||
|
||||
extension on PushProvider {
|
||||
/// Helper extension for [PushProvider]
|
||||
extension PushProviderX on PushProvider {
|
||||
/// Returns the string notion for [PushProvider].
|
||||
String get name => {
|
||||
PushProvider.apn: 'apn',
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dio/dio.dart' show MultipartFile;
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:stream_chat/src/core/platform_detector/platform_detector.dart';
|
||||
import 'package:stream_chat/src/core/util/extension.dart';
|
||||
|
||||
part 'attachment_file.freezed.dart';
|
||||
|
||||
part 'attachment_file.g.dart';
|
||||
|
||||
/// Union class to hold various [UploadState] of a attachment.
|
||||
@@ -58,14 +62,18 @@ String? _toString(Uint8List? bytes) {
|
||||
@JsonSerializable()
|
||||
class AttachmentFile {
|
||||
/// Creates a new [AttachmentFile] instance.
|
||||
const AttachmentFile({
|
||||
AttachmentFile({
|
||||
required this.size,
|
||||
this.path,
|
||||
this.name,
|
||||
this.bytes,
|
||||
}) : assert(
|
||||
}) : assert(
|
||||
path != null || bytes != null,
|
||||
'Either path or bytes should be != null',
|
||||
),
|
||||
assert(
|
||||
!CurrentPlatform.isWeb || bytes != null,
|
||||
'File by path is not supported in web, Please provide bytes',
|
||||
);
|
||||
|
||||
/// Create a new instance from a json
|
||||
@@ -95,4 +103,27 @@ class AttachmentFile {
|
||||
|
||||
/// Serialize to json
|
||||
Map<String, dynamic> toJson() => _$AttachmentFileToJson(this);
|
||||
|
||||
/// Converts this into a [MultipartFile]
|
||||
Future<MultipartFile> toMultipartFile() async {
|
||||
final filename = path?.split('/').last ?? name;
|
||||
final mimeType = filename?.mimeType;
|
||||
|
||||
late MultipartFile multiPartFile;
|
||||
|
||||
if (CurrentPlatform.isWeb) {
|
||||
multiPartFile = MultipartFile.fromBytes(
|
||||
bytes!,
|
||||
filename: filename,
|
||||
contentType: mimeType,
|
||||
);
|
||||
} else {
|
||||
multiPartFile = await MultipartFile.fromFile(
|
||||
path!,
|
||||
filename: filename,
|
||||
contentType: mimeType,
|
||||
);
|
||||
}
|
||||
return multiPartFile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user