Skip to content

Commit

Permalink
v0.1.27: changed upload interface ; added upload queue ; increased up…
Browse files Browse the repository at this point in the history
…load speed on slow Internet
  • Loading branch information
vhunkalo committed Sep 23, 2024
1 parent 767392c commit add9333
Show file tree
Hide file tree
Showing 23 changed files with 1,158 additions and 255 deletions.
16 changes: 16 additions & 0 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 46 additions & 46 deletions lib/src/backbone/builder/request_dialog_message.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import 'package:webitel_portal_sdk/src/domain/entities/dialog_message_request.dart';
import 'package:webitel_portal_sdk/src/domain/entities/media_file_request.dart';

final class RequestDialogMessageBuilder {
late String _content;
late String _requestId;
late String _chatId;
late String _messageId;

late MediaFileRequest _file;

RequestDialogMessageBuilder setContent(String content) {
_content = content;
return this;
}

RequestDialogMessageBuilder setRequestId(String requestId) {
_requestId = requestId;
return this;
}

RequestDialogMessageBuilder setChatId(String chatId) {
_chatId = chatId;
return this;
}

RequestDialogMessageBuilder setMessageId(String messageId) {
_messageId = messageId;
return this;
}

RequestDialogMessageBuilder setFile(MediaFileRequest file) {
_file = file;
return this;
}

DialogMessageRequest build() {
return DialogMessageRequest(
chatId: _chatId,
content: _content,
requestId: _requestId,
messageId: _messageId,
file: _file,
);
}
}
// import 'package:webitel_portal_sdk/src/domain/entities/dialog_message_request.dart';
// import 'package:webitel_portal_sdk/src/domain/entities/media_file_request.dart';
//
// final class RequestDialogMessageBuilder {
// late String _content;
// late String _requestId;
// late String _chatId;
// late String _messageId;
//
// late MediaFileRequest _file;
//
// RequestDialogMessageBuilder setContent(String content) {
// _content = content;
// return this;
// }
//
// RequestDialogMessageBuilder setRequestId(String requestId) {
// _requestId = requestId;
// return this;
// }
//
// RequestDialogMessageBuilder setChatId(String chatId) {
// _chatId = chatId;
// return this;
// }
//
// RequestDialogMessageBuilder setMessageId(String messageId) {
// _messageId = messageId;
// return this;
// }
//
// RequestDialogMessageBuilder setFile(MediaFileRequest file) {
// _file = file;
// return this;
// }
//
// DialogMessageRequest build() {
// return DialogMessageRequest(
// chatId: _chatId,
// content: _content,
// requestId: _requestId,
// messageId: _messageId,
// file: _file,
// );
// }
// }
8 changes: 8 additions & 0 deletions lib/src/backbone/cert_helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dart:convert';

// Function to convert PEM string to List<int>
List<int> pemToBytes(String pem) {
final lines = pem.split('\n');
final base64 = lines.where((line) => !line.startsWith('-----')).join();
return base64Decode(base64);
}
73 changes: 73 additions & 0 deletions lib/src/backbone/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,76 @@ final class Constants {
/// The default timeout duration for requests.
static const Duration requestTimeout = Duration(seconds: 5);
}

//Solva cert
const String pemCertificate = '''
-----BEGIN CERTIFICATE-----
MIIGEzCCA/ugAwIBAgIQfVtRJrR2uhHbdBYLvFMNpzANBgkqhkiG9w0BAQwFADCB
iDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCk5ldyBKZXJzZXkxFDASBgNVBAcTC0pl
cnNleSBDaXR5MR4wHAYDVQQKExVUaGUgVVNFUlRSVVNUIE5ldHdvcmsxLjAsBgNV
BAMTJVVTRVJUcnVzdCBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTgx
MTAyMDAwMDAwWhcNMzAxMjMxMjM1OTU5WjCBjzELMAkGA1UEBhMCR0IxGzAZBgNV
BAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEYMBYGA1UE
ChMPU2VjdGlnbyBMaW1pdGVkMTcwNQYDVQQDEy5TZWN0aWdvIFJTQSBEb21haW4g
VmFsaWRhdGlvbiBTZWN1cmUgU2VydmVyIENBMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEA1nMz1tc8INAA0hdFuNY+B6I/x0HuMjDJsGz99J/LEpgPLT+N
TQEMgg8Xf2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81XHfqnHd4blsjDwSXWXavVcStkNr/+XeTWYRUc+ZruwXtuhxkYze
Sf7dNXGiFSeUHM9h4ya7b6NnJSFd5t0dCy5oGzuCr+yDZ4XUmFF0sbmZgIn/f3gZ
XHlKYC6SQK5MNyosycdiyA5d9zZbyuAlJQG03RoHnHcAP9Dc1ew91Pq7P8yF1m9/
qS3fuQL39ZeatTXaw2ewh0qpKJ4jjv9cJ2vhsE/zB+4ALtRZh8tSQZXq9EfX7mRB
VXyNWQKV3WKdwrnuWih0hKWbt5DHDAff9Yk2dDLWKMGwsAvgnEzDHNb842m1R0aB
L6KCq9NjRHDEjf8tM7qtj3u1cIiuPhnPQCjY/MiQu12ZIvVS5ljFH4gxQ+6IHdfG
jjxDah2nGN59PRbxYvnKkKj9
-----END CERTIFICATE-----
''';
2 changes: 1 addition & 1 deletion lib/src/backbone/helper/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class MessageHelper {
/// [dialogMessageRequestEntity] The dialog message request to be checked.
static MessageType determineMessageTypeRequest(
DialogMessageRequest dialogMessageRequestEntity) {
if (dialogMessageRequestEntity.file.name.isNotEmpty) {
if (dialogMessageRequestEntity.uploadFile.id != '') {
return MessageType.media;
} else {
return MessageType.text;
Expand Down
79 changes: 31 additions & 48 deletions lib/src/data/dialog_impl.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'dart:async';
import 'dart:io';

import 'package:injectable/injectable.dart';
import 'package:webitel_portal_sdk/src/domain/entities/call_error.dart';
import 'package:webitel_portal_sdk/src/domain/entities/dialog.dart';
import 'package:webitel_portal_sdk/src/domain/entities/dialog_message_request.dart';
import 'package:webitel_portal_sdk/src/domain/entities/dialog_message_response.dart';
import 'package:webitel_portal_sdk/src/domain/entities/download.dart';
import 'package:webitel_portal_sdk/src/domain/entities/media_file_request.dart';
import 'package:webitel_portal_sdk/src/domain/entities/media_file_response.dart';
import 'package:webitel_portal_sdk/src/domain/entities/portal_chat_member.dart';
import 'package:webitel_portal_sdk/src/domain/entities/postback.dart';
import 'package:webitel_portal_sdk/src/domain/entities/upload.dart';
import 'package:webitel_portal_sdk/src/domain/entities/upload_file.dart';
import 'package:webitel_portal_sdk/src/domain/services/chat_service.dart';
import 'package:webitel_portal_sdk/src/injection/injection.dart';

Expand All @@ -20,13 +21,13 @@ final class DialogImpl implements Dialog {
@override
final String id;

/// The top message in the dialog.
/// The current status of the dialog whether it's closed.
@override
final String topMessage;
final bool isClosed;

/// Flag indicating whether the chat is closed or not.
/// The top message in the dialog.
@override
final bool isClosed;
final String topMessage;

/// The error associated with the dialog, if any.
@override
Expand All @@ -36,23 +37,18 @@ final class DialogImpl implements Dialog {
@override
final Stream<DialogMessageResponse> onNewMessage;

/// Stream [PortalChatMember] for new member added to the chat..
/// Stream [PortalChatMember] for new member added to the chat.
@override
final Stream<PortalChatMember> onMemberAdded;

/// Stream [PortalChatMember] for member left the chat..
/// Stream [PortalChatMember] for member left the chat.
@override
final Stream<PortalChatMember> onMemberLeft;

// Dependency on the ChatService to handle chat-related operations.
late final ChatService _chatService;

/// Constructor for initializing a [DialogImpl] instance.
///
/// [id] The unique identifier for the dialog.
/// [topMessage] The top message in the dialog.
/// [onNewMessage] The stream for new messages in the dialog.
/// [error] The error associated with the dialog, if any.
DialogImpl({
required this.id,
required this.topMessage,
Expand All @@ -76,19 +72,9 @@ final class DialogImpl implements Dialog {
onMemberAdded = Stream.empty();

/// Sends a message in the dialog.
///
/// [mediaType] The type of the media (optional).
/// [mediaName] The name of the media (optional).
/// [mediaData] The stream of media data (optional).
/// [content] The content of the message.
/// [requestId] The unique identifier for the request.
///
/// Returns a [Future] that completes with a [DialogMessageResponse].
@override
Future<DialogMessageResponse> sendMessage({
String? mediaType,
String? mediaName,
Stream<List<int>>? mediaData,
UploadFile? uploadFile,
required String content,
required String requestId,
}) async {
Expand All @@ -97,22 +83,16 @@ final class DialogImpl implements Dialog {
message: DialogMessageRequest(
content: content,
requestId: requestId,
file: MediaFileRequest(
data: mediaData ?? Stream<List<int>>.empty(),
name: mediaName ?? '',
type: mediaType ?? '',
requestId: requestId,
uploadFile: UploadFile(
name: uploadFile?.name ?? '',
type: uploadFile?.type ?? '',
id: uploadFile?.id ?? '',
),
),
);
}

/// Sends a postback in the dialog.
///
/// [postback] The postback object,
/// [requestId] The unique identifier for the request.
///
/// Returns a [Future] that completes with a [DialogMessageResponse].
@override
Future<DialogMessageResponse> sendPostback({
required Postback postback,
Expand All @@ -126,11 +106,6 @@ final class DialogImpl implements Dialog {
}

/// Fetches messages in the dialog.
///
/// [limit] The maximum number of messages to fetch (optional).
/// [offset] The offset from which to start fetching messages (optional).
///
/// Returns a [Future] that completes with a list of [DialogMessageResponse].
@override
Future<List<DialogMessageResponse>> fetchMessages({
int? limit,
Expand All @@ -144,11 +119,6 @@ final class DialogImpl implements Dialog {
}

/// Fetches updates in the dialog.
///
/// [limit] The maximum number of updates to fetch (optional).
/// [offset] The offset from which to start fetching updates (optional).
///
/// Returns a [Future] that completes with a list of [DialogMessageResponse].
@override
Future<List<DialogMessageResponse>> fetchUpdates({
int? limit,
Expand All @@ -162,14 +132,27 @@ final class DialogImpl implements Dialog {
}

/// Downloads a media file associated with a dialog.
///
/// [fileId] The ID of the file to be downloaded.
///
/// Returns a stream of [MediaFileResponse] representing the downloaded file.
@override
Download downloadFile({required String fileId, int? offset}) =>
_chatService.downloadFile(
fileId: fileId,
offset: offset,
);

/// Uploads a media file associated with a dialog.
@override
Upload uploadFile({
required String mediaType,
required String mediaName,
required File file,
String? pid,
int? offset,
}) =>
_chatService.uploadFile(
mediaType: mediaType,
mediaName: mediaName,
file: file,
pid: pid,
offset: offset,
);
}
Loading

0 comments on commit add9333

Please sign in to comment.