mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 19:58:41 +00:00
buf fix #8
This commit is contained in:
parent
de9bd43e4b
commit
504b528770
3 changed files with 19 additions and 13 deletions
|
|
@ -46,8 +46,13 @@ Future tryTransmitMessages() async {
|
||||||
if (encryptedMedia != null) {
|
if (encryptedMedia != null) {
|
||||||
final content = retransmit[i].messageContent;
|
final content = retransmit[i].messageContent;
|
||||||
if (content is MediaMessageContent) {
|
if (content is MediaMessageContent) {
|
||||||
uploadMediaFile(msgId, Int64(retransmit[i].otherUserId), encryptedMedia,
|
await uploadMediaFile(
|
||||||
content.isRealTwonly, content.maxShowTime, retransmit[i].sendAt);
|
msgId,
|
||||||
|
Int64(retransmit[i].otherUserId),
|
||||||
|
encryptedMedia,
|
||||||
|
content.isRealTwonly,
|
||||||
|
content.maxShowTime,
|
||||||
|
retransmit[i].sendAt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +115,7 @@ Future uploadMediaFile(
|
||||||
) async {
|
) async {
|
||||||
Box box = await getMediaStorage();
|
Box box = await getMediaStorage();
|
||||||
|
|
||||||
List<int>? uploadToken = await box.get("retransmit-$messageId-uploadtoken");
|
List<int>? uploadToken = box.get("retransmit-$messageId-uploadtoken");
|
||||||
if (uploadToken == null) {
|
if (uploadToken == null) {
|
||||||
Result res = await apiProvider.getUploadToken();
|
Result res = await apiProvider.getUploadToken();
|
||||||
|
|
||||||
|
|
@ -120,34 +125,35 @@ Future uploadMediaFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadToken = res.value.uploadtoken;
|
uploadToken = res.value.uploadtoken;
|
||||||
|
|
||||||
await box.put("retransmit-$messageId-uploadtoken", uploadToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uploadToken == null) return;
|
if (uploadToken == null) return;
|
||||||
|
|
||||||
int offset = await box.get("retransmit-$messageId-offset") ?? 0;
|
int offset = box.get("retransmit-$messageId-offset") ?? 0;
|
||||||
|
|
||||||
int fragmentedTransportSize = 100000;
|
int fragmentedTransportSize = 100000;
|
||||||
|
|
||||||
while (offset < encryptedMedia.length) {
|
while (offset < encryptedMedia.length) {
|
||||||
|
debugPrint("offset: $offset");
|
||||||
int end = encryptedMedia.length;
|
int end = encryptedMedia.length;
|
||||||
if (offset + fragmentedTransportSize < encryptedMedia.length) {
|
if (offset + fragmentedTransportSize < encryptedMedia.length) {
|
||||||
end = offset + fragmentedTransportSize;
|
end = offset + fragmentedTransportSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wasSend = await apiProvider.uploadData(
|
Result wasSend = await apiProvider.uploadData(
|
||||||
uploadToken,
|
uploadToken,
|
||||||
encryptedMedia.sublist(offset, end),
|
encryptedMedia.sublist(offset, end),
|
||||||
offset,
|
offset,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!wasSend) {
|
if (wasSend.isError) {
|
||||||
|
await box.put("retransmit-$messageId-offset", 0);
|
||||||
|
await box.delete("retransmit-$messageId-uploadtoken");
|
||||||
Logger("api.dart").shout("error while uploading media");
|
Logger("api.dart").shout("error while uploading media");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await box.put("retransmit-$messageId-offset", offset);
|
box.put("retransmit-$messageId-offset", offset);
|
||||||
|
|
||||||
offset = end;
|
offset = end;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ class ApiProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onError(dynamic e) {
|
void _onError(dynamic e) {
|
||||||
|
log.shout("WebSocket Error: $e");
|
||||||
globalCallbackConnectionState(false);
|
globalCallbackConnectionState(false);
|
||||||
_channel = null;
|
_channel = null;
|
||||||
isAuthenticated = false;
|
isAuthenticated = false;
|
||||||
|
|
@ -309,7 +310,7 @@ class ApiProvider {
|
||||||
return await _sendRequestV0(req);
|
return await _sendRequestV0(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> uploadData(
|
Future<Result> uploadData(
|
||||||
List<int> uploadToken, Uint8List data, int offset) async {
|
List<int> uploadToken, Uint8List data, int offset) async {
|
||||||
var get = ApplicationData_UploadData()
|
var get = ApplicationData_UploadData()
|
||||||
..uploadToken = uploadToken
|
..uploadToken = uploadToken
|
||||||
|
|
@ -318,7 +319,7 @@ class ApiProvider {
|
||||||
var appData = ApplicationData()..uploaddata = get;
|
var appData = ApplicationData()..uploaddata = get;
|
||||||
var req = createClientToServerFromApplicationData(appData);
|
var req = createClientToServerFromApplicationData(appData);
|
||||||
final result = await _sendRequestV0(req);
|
final result = await _sendRequestV0(req);
|
||||||
return result.isSuccess;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result> getUserData(String username) async {
|
Future<Result> getUserData(String username) async {
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,9 @@ class _ChatListViewState extends State<ChatListView> {
|
||||||
|
|
||||||
allUsers.sort((b, a) {
|
allUsers.sort((b, a) {
|
||||||
DbMessage? msgA = lastMessages[a.userId.toInt()];
|
DbMessage? msgA = lastMessages[a.userId.toInt()];
|
||||||
DbMessage? msgB = lastMessages[a.userId.toInt()];
|
DbMessage? msgB = lastMessages[b.userId.toInt()];
|
||||||
if (msgA == null) return 1;
|
if (msgA == null) return 1;
|
||||||
if (msgB == null) return -1;
|
if (msgB == null) return -1;
|
||||||
|
|
||||||
return msgA.sendAt.compareTo(msgB.sendAt);
|
return msgA.sendAt.compareTo(msgB.sendAt);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue