Merge pull request #1744 from famedly/td/pduFakeSync

chore: check message size before fake sync
This commit is contained in:
td 2024-03-25 19:37:49 +05:30 committed by GitHub
commit 90ab339277
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 29 deletions

View File

@ -923,24 +923,11 @@ class Room {
Future<String?> _sendContent(
String type,
Map<String, dynamic> content, {
Map<String, dynamic> sendMessageContent, {
String? txid,
}) async {
txid ??= client.generateUniqueTransactionId();
final mustEncrypt = encrypted && client.encryptionEnabled;
final sendMessageContent = mustEncrypt
? await client.encryption!
.encryptGroupMessagePayload(id, content, type: type)
: content;
final utf8EncodedJsonLength =
utf8.encode(jsonEncode(sendMessageContent)).length;
if (utf8EncodedJsonLength > maxPDUSize) {
throw EventTooLarge(utf8EncodedJsonLength);
}
return await client.sendMessage(
id,
sendMessageContent.containsKey('ciphertext')
@ -1053,6 +1040,21 @@ class Room {
}
}
final sentDate = DateTime.now();
final mustEncrypt = encrypted && client.encryptionEnabled;
final sendMessageContent = mustEncrypt
? await client.encryption!
.encryptGroupMessagePayload(id, content, type: type)
: content;
final utf8EncodedJsonLength =
utf8.encode(jsonEncode(sendMessageContent)).length;
if (utf8EncodedJsonLength > maxPDUSize) {
throw EventTooLarge(utf8EncodedJsonLength);
}
final syncUpdate = SyncUpdate(
nextBatch: '',
rooms: RoomsUpdate(
@ -1092,13 +1094,11 @@ class Room {
try {
res = await _sendContent(
type,
content,
sendMessageContent,
txid: messageID,
);
} catch (e, s) {
if (e is EventTooLarge) {
rethrow;
} else if (e is MatrixException &&
if (e is MatrixException &&
e.retryAfterMs != null &&
!DateTime.now()
.add(Duration(milliseconds: e.retryAfterMs!))

View File

@ -1718,7 +1718,7 @@ class CallSession {
if (capabilities != null) 'capabilities': capabilities.toJson(),
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallInvite,
content,
@ -1746,7 +1746,7 @@ class CallSession {
'selected_party_id': selected_party_id,
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallSelectAnswer,
content,
@ -1769,7 +1769,7 @@ class CallSession {
'version': version,
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallReject,
content,
@ -1799,7 +1799,7 @@ class CallSession {
if (capabilities != null) 'capabilities': capabilities.toJson(),
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallNegotiate,
content,
@ -1842,7 +1842,7 @@ class CallSession {
'version': version,
'candidates': candidates,
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallCandidates,
content,
@ -1872,7 +1872,7 @@ class CallSession {
if (capabilities != null) 'capabilities': capabilities.toJson(),
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallAnswer,
content,
@ -1894,7 +1894,7 @@ class CallSession {
'version': version,
if (hangupCause != null) 'reason': hangupCause,
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallHangup,
content,
@ -1926,7 +1926,7 @@ class CallSession {
'version': version,
sdpStreamMetadataKey: metadata.toJson(),
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallSDPStreamMetadataChangedPrefix,
content,
@ -1950,7 +1950,7 @@ class CallSession {
'version': version,
...callReplaces.toJson(),
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallReplaces,
content,
@ -1974,7 +1974,7 @@ class CallSession {
'version': version,
'asserted_identity': assertedIdentity.toJson(),
};
return await _sendContent(
return await _sendCallContent(
room,
EventTypes.CallAssertedIdentity,
content,
@ -1982,7 +1982,7 @@ class CallSession {
);
}
Future<String?> _sendContent(
Future<String?> _sendCallContent(
Room room,
String type,
Map<String, dynamic> content, {