some bug fixes

This commit is contained in:
otsmr 2025-02-17 15:35:12 +01:00
parent 6856eb3809
commit 00ad654660
6 changed files with 23 additions and 15 deletions

View file

@ -130,7 +130,7 @@ Future uploadMediaFile(
int offset = box.get("retransmit-$messageId-offset") ?? 0;
int fragmentedTransportSize = 50000;
int fragmentedTransportSize = 1_000_000; // per upload transfer
while (offset < encryptedMedia.length) {
Logger("api.dart").info("Uploading image $messageId with offset: $offset");
@ -272,6 +272,7 @@ Future sendImage(
Future tryDownloadMedia(int messageId, int fromUserId, List<int> mediaToken,
{bool force = false}) async {
if (globalIsAppInBackground) return;
if (!force) {
// TODO: create option to enable download via mobile data
final List<ConnectivityResult> connectivityResult =
@ -281,9 +282,15 @@ Future tryDownloadMedia(int messageId, int fromUserId, List<int> mediaToken,
return;
}
}
final box = await getMediaStorage();
if (box.containsKey("${mediaToken}_downloaded")) {
Logger("tryDownloadMedia").shout("mediaToken already downloaded");
return;
}
Logger("tryDownloadMedia").info("Downloading: $mediaToken");
int offset = 0;
final box = await getMediaStorage();
Uint8List? media = box.get("$mediaToken");
if (media != null && media.isNotEmpty) {
offset = media.length;

View file

@ -1,7 +1,6 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:fixnum/fixnum.dart';
import 'package:flutter/foundation.dart';
import 'package:libsignal_protocol_dart/libsignal_protocol_dart.dart';
import 'package:logging/logging.dart';
import 'package:twonly/globals.dart';

View file

@ -25,11 +25,11 @@ import 'package:web_socket_channel/web_socket_channel.dart';
/// It handles errors and does automatically tries to reconnect on
/// errors or network changes.
class ApiProvider {
final String apiUrl = (kDebugMode && false)
final String apiUrl = (kDebugMode)
? "ws://10.99.0.6:3030/api/client"
: "wss://api.twonly.eu/api/client";
// ws://api.twonly.eu/api/client
final String? backupApiUrl = (kDebugMode && false)
final String? backupApiUrl = (kDebugMode)
? "ws://10.99.0.6:3030/api/client"
: "wss://api2.twonly.eu/api/client";
bool isAuthenticated = false;

View file

@ -34,6 +34,8 @@ class MessagesChangeProvider with ChangeNotifier, DiagnosticableTreeMixin {
int index = _allMessagesFromUser[targetUserId]!
.indexWhere((x) => x.messageId == messageId);
if (index == -1) {
print("should be indexed by time!!");
_allMessagesFromUser[targetUserId]!.insert(0, msg);
// reload all messages but async
loadMessagesForUser(targetUserId, force: true);

View file

@ -49,22 +49,20 @@ Future<bool> addNewContact(Response_UserData userData) async {
1);
tempPreKeyId = userData.prekeys.first.id.toInt();
}
// Signed pre key calculation
int tempSignedPreKeyId = userData.signedPrekeyId.toInt();
// Map? tempSignedPreKey = remoteBundle["signedPreKey"];
ECPublicKey? tempSignedPreKeyPublic;
Uint8List? tempSignedPreKeySignature;
// if (tempSignedPreKey != null) {
tempSignedPreKeyPublic = Curve.decodePoint(
ECPublicKey? tempSignedPreKeyPublic = Curve.decodePoint(
DjbECPublicKey(Uint8List.fromList(userData.signedPrekey)).serialize(), 1);
tempSignedPreKeySignature =
Uint8List? tempSignedPreKeySignature =
Uint8List.fromList(userData.signedPrekeySignature);
// }
// Identity key calculation
IdentityKey tempIdentityKey = IdentityKey(Curve.decodePoint(
DjbECPublicKey(Uint8List.fromList(userData.publicIdentityKey))
.serialize(),
1));
PreKeyBundle preKeyBundle = PreKeyBundle(
userData.userId.toInt(),
1,
@ -230,6 +228,7 @@ Future<Uint8List?> decryptBytes(Uint8List bytes, Int64 target) async {
int type = bytesToInt(msgs[1]);
Uint8List plaintext;
Logger("utils/signal").info("got signal type: $type!");
if (type == CiphertextMessage.prekeyType) {
PreKeySignalMessage pre = PreKeySignalMessage(body);
plaintext = await session.decrypt(pre);
@ -237,6 +236,7 @@ Future<Uint8List?> decryptBytes(Uint8List bytes, Int64 target) async {
SignalMessage signalMsg = SignalMessage.fromSerialized(body);
plaintext = await session.decryptFromSignal(signalMsg);
} else {
Logger("utils/signal").shout("signal type is not known: $type!");
return null;
}
List<int>? plainBytes = gzip.decode(Uint8List.fromList(plaintext));

View file

@ -7,7 +7,7 @@ publish_to: 'none'
version: 0.0.4+4
environment:
sdk: ^3.5.4
sdk: ^3.6.0
dependencies:
camerawesome: ^2.1.0