removed _repLocal function causing delays in initial translation, also made selection translation and repEvent fetching futures happen at the same time in message translation card

pull/1384/head
ggurdin 1 year ago
parent ea6d8f355c
commit db9320d2ac
No known key found for this signature in database
GPG Key ID: A01CB41737CBB478

@ -477,28 +477,10 @@ class PangeaMessageEvent {
return representationByLanguage(langCode)?.text ?? body;
}
bool get isNew =>
DateTime.now().difference(originServerTs.toLocal()).inSeconds < 8;
Future<RepresentationEvent?> _repLocal(String langCode) async {
int tries = 0;
RepresentationEvent? rep = representationByLanguage(langCode);
while ((isNew || eventId.contains("web")) && tries < 20) {
if (rep != null) return rep;
await Future.delayed(const Duration(milliseconds: 500));
rep = representationByLanguage(langCode);
tries += 1;
}
return rep;
}
Future<PangeaRepresentation?> representationByLanguageGlobal({
required String langCode,
}) async {
// try {
final RepresentationEvent? repLocal = await _repLocal(langCode);
final RepresentationEvent? repLocal = representationByLanguage(langCode);
if (repLocal != null ||
langCode == LanguageKeys.unknownLanguage ||
@ -519,11 +501,7 @@ class PangeaMessageEvent {
target: langCode,
room: _latestEdit.room,
);
if (pangeaRep == null ||
await _latestEdit.room.getEventById(_latestEdit.eventId) == null) {
return null;
}
if (pangeaRep == null) return null;
MatrixState.pangeaController.messageData
.sendRepresentationMatrixEvent(

@ -33,7 +33,7 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
String? oldSelectedText;
bool _fetchingRepresentation = false;
Future<void> fetchRepresentation(BuildContext context) async {
Future<void> fetchRepresentation() async {
if (l1Code == null) return;
repEvent = widget.messageEvent
@ -102,15 +102,13 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
@override
void initState() {
super.initState();
if (mounted) {
setState(() {});
}
loadTranslation(() async {
final List<Future> futures = [];
futures.add(fetchRepresentation());
if (widget.selection.selectedText != null) {
await translateSelection();
futures.add(translateSelection());
}
await fetchRepresentation(context);
await Future.wait(futures);
});
}

Loading…
Cancel
Save