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