feat(lib, android, ios): permissions clean up, add id to files pack

This commit is contained in:
ksenia312
2024-02-07 13:30:34 +01:00
parent 2541aa57d2
commit f18065db49
20 changed files with 313 additions and 220 deletions
+12 -3
View File
@@ -7,12 +7,14 @@ import 'package:nearby_service/nearby_service.dart';
///
class ReceivedNearbyFilesPack implements NearbyReceivedInterface {
const ReceivedNearbyFilesPack({
required this.id,
required this.sender,
required this.files,
});
factory ReceivedNearbyFilesPack.fromJson(Map<String, dynamic>? json) {
return ReceivedNearbyFilesPack(
id: json?['id'],
sender: NearbyDeviceInfo.fromJson(json?['sender']),
files: [
...?(json?['files'] as List?)?.map(
@@ -30,8 +32,14 @@ class ReceivedNearbyFilesPack implements NearbyReceivedInterface {
///
final List<NearbyFileInfo> files;
///
/// ID of the files pack
///
final String id;
Map<String, dynamic> toJson() {
return {
'id': id,
'sender': sender.toJson(),
'files': [
...files.map((e) => e.toJson()),
@@ -45,13 +53,14 @@ class ReceivedNearbyFilesPack implements NearbyReceivedInterface {
other is ReceivedNearbyFilesPack &&
runtimeType == other.runtimeType &&
sender == other.sender &&
files == other.files;
files == other.files &&
id == other.id;
@override
int get hashCode => sender.hashCode ^ files.hashCode;
int get hashCode => sender.hashCode ^ files.hashCode ^ id.hashCode;
@override
String toString() {
return 'NearbyFilesPack{sender: $sender, files: $files}';
return 'ReceivedNearbyFilesPack{sender: $sender, files: $files, id: $id}';
}
}
+1 -1
View File
@@ -177,6 +177,6 @@ final class NearbyMessageFilesResponse extends NearbyMessageContent {
@override
String toString() {
return 'NearbyMessageFileResponse{response: $isAccepted, id: $id}';
return 'NearbyMessageFileResponse{isAccepted: $isAccepted, id: $id}';
}
}
+3
View File
@@ -63,13 +63,16 @@ class FilesSocket {
} else if (event == separateCommandOf(_currentFileIndex)) {
_futures.add(_createFile(_currentFileIndex));
_currentFileIndex = _currentFileIndex + 1;
_chunksCount = 0;
_bytesTable['$_currentFileIndex'] = [];
Logger.info('Completed receiving file №${_currentFileIndex - 1}');
} else if (event == finishCommand) {
await Future.wait(_futures);
Logger.info('Files pack ${filesRequest.id} was created');
listener?.onData.call(
ReceivedNearbyFilesPack(
id: filesRequest.id,
sender: sender,
files: _files,
),