chore: check message size before fake sync
This commit is contained in:
parent
17ed3b255c
commit
981c3ea94d
|
|
@ -923,24 +923,11 @@ class Room {
|
||||||
|
|
||||||
Future<String?> _sendContent(
|
Future<String?> _sendContent(
|
||||||
String type,
|
String type,
|
||||||
Map<String, dynamic> content, {
|
Map<String, dynamic> sendMessageContent, {
|
||||||
String? txid,
|
String? txid,
|
||||||
}) async {
|
}) async {
|
||||||
txid ??= client.generateUniqueTransactionId();
|
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(
|
return await client.sendMessage(
|
||||||
id,
|
id,
|
||||||
sendMessageContent.containsKey('ciphertext')
|
sendMessageContent.containsKey('ciphertext')
|
||||||
|
|
@ -1053,6 +1040,21 @@ class Room {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final sentDate = DateTime.now();
|
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(
|
final syncUpdate = SyncUpdate(
|
||||||
nextBatch: '',
|
nextBatch: '',
|
||||||
rooms: RoomsUpdate(
|
rooms: RoomsUpdate(
|
||||||
|
|
@ -1092,13 +1094,11 @@ class Room {
|
||||||
try {
|
try {
|
||||||
res = await _sendContent(
|
res = await _sendContent(
|
||||||
type,
|
type,
|
||||||
content,
|
sendMessageContent,
|
||||||
txid: messageID,
|
txid: messageID,
|
||||||
);
|
);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
if (e is EventTooLarge) {
|
if (e is MatrixException &&
|
||||||
rethrow;
|
|
||||||
} else if (e is MatrixException &&
|
|
||||||
e.retryAfterMs != null &&
|
e.retryAfterMs != null &&
|
||||||
!DateTime.now()
|
!DateTime.now()
|
||||||
.add(Duration(milliseconds: e.retryAfterMs!))
|
.add(Duration(milliseconds: e.retryAfterMs!))
|
||||||
|
|
|
||||||
|
|
@ -1718,7 +1718,7 @@ class CallSession {
|
||||||
if (capabilities != null) 'capabilities': capabilities.toJson(),
|
if (capabilities != null) 'capabilities': capabilities.toJson(),
|
||||||
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
|
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallInvite,
|
EventTypes.CallInvite,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1746,7 +1746,7 @@ class CallSession {
|
||||||
'selected_party_id': selected_party_id,
|
'selected_party_id': selected_party_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallSelectAnswer,
|
EventTypes.CallSelectAnswer,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1769,7 +1769,7 @@ class CallSession {
|
||||||
'version': version,
|
'version': version,
|
||||||
};
|
};
|
||||||
|
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallReject,
|
EventTypes.CallReject,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1799,7 +1799,7 @@ class CallSession {
|
||||||
if (capabilities != null) 'capabilities': capabilities.toJson(),
|
if (capabilities != null) 'capabilities': capabilities.toJson(),
|
||||||
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
|
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallNegotiate,
|
EventTypes.CallNegotiate,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1842,7 +1842,7 @@ class CallSession {
|
||||||
'version': version,
|
'version': version,
|
||||||
'candidates': candidates,
|
'candidates': candidates,
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallCandidates,
|
EventTypes.CallCandidates,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1872,7 +1872,7 @@ class CallSession {
|
||||||
if (capabilities != null) 'capabilities': capabilities.toJson(),
|
if (capabilities != null) 'capabilities': capabilities.toJson(),
|
||||||
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
|
if (metadata != null) sdpStreamMetadataKey: metadata.toJson(),
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallAnswer,
|
EventTypes.CallAnswer,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1894,7 +1894,7 @@ class CallSession {
|
||||||
'version': version,
|
'version': version,
|
||||||
if (hangupCause != null) 'reason': hangupCause,
|
if (hangupCause != null) 'reason': hangupCause,
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallHangup,
|
EventTypes.CallHangup,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1926,7 +1926,7 @@ class CallSession {
|
||||||
'version': version,
|
'version': version,
|
||||||
sdpStreamMetadataKey: metadata.toJson(),
|
sdpStreamMetadataKey: metadata.toJson(),
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallSDPStreamMetadataChangedPrefix,
|
EventTypes.CallSDPStreamMetadataChangedPrefix,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1950,7 +1950,7 @@ class CallSession {
|
||||||
'version': version,
|
'version': version,
|
||||||
...callReplaces.toJson(),
|
...callReplaces.toJson(),
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallReplaces,
|
EventTypes.CallReplaces,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1974,7 +1974,7 @@ class CallSession {
|
||||||
'version': version,
|
'version': version,
|
||||||
'asserted_identity': assertedIdentity.toJson(),
|
'asserted_identity': assertedIdentity.toJson(),
|
||||||
};
|
};
|
||||||
return await _sendContent(
|
return await _sendCallContent(
|
||||||
room,
|
room,
|
||||||
EventTypes.CallAssertedIdentity,
|
EventTypes.CallAssertedIdentity,
|
||||||
content,
|
content,
|
||||||
|
|
@ -1982,7 +1982,7 @@ class CallSession {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> _sendContent(
|
Future<String?> _sendCallContent(
|
||||||
Room room,
|
Room room,
|
||||||
String type,
|
String type,
|
||||||
Map<String, dynamic> content, {
|
Map<String, dynamic> content, {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue