chore(service): Move createFallbackBodyForQuotedMessage into helpers

This commit is contained in:
PapaTutuWawa 2023-01-28 20:14:47 +01:00
parent c34c0ffd0f
commit 4523d87028
2 changed files with 43 additions and 41 deletions

View File

@ -3,6 +3,8 @@ import 'dart:ui';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:moxxmpp/moxxmpp.dart'; import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxyv2/i18n/strings.g.dart'; import 'package:moxxyv2/i18n/strings.g.dart';
import 'package:moxxyv2/shared/helpers.dart';
import 'package:moxxyv2/shared/models/message.dart';
import 'package:native_imaging/native_imaging.dart' as native; import 'package:native_imaging/native_imaging.dart' as native;
Future<String?> _generateBlurhashThumbnailImpl(String path) async { Future<String?> _generateBlurhashThumbnailImpl(String path) async {
@ -110,3 +112,44 @@ String getUnrecoverableErrorString(NonRecoverableErrorEvent event) {
return t.errors.connection.unrecoverable; return t.errors.connection.unrecoverable;
} }
/// Creates the fallback body for quoted messages.
/// If the quoted message contains text, it simply quotes the text.
/// If it contains a media file, the messageEmoji (usually an emoji
/// representing the mime type) is shown together with the file size
/// (from experience this information is sufficient, as most clients show
/// the file size, and including time information might be confusing and a
/// potential privacy issue).
/// This information is complemented either the srcUrl or if unavailable
/// by the body of the quoted message. For non-media messages, we always use
/// the body as fallback.
String? createFallbackBodyForQuotedMessage(Message? quotedMessage) {
if (quotedMessage == null) {
return null;
}
if (quotedMessage.isMedia) {
// Create formatted size string, if size is stored
String quoteMessageSize;
if (quotedMessage.mediaSize != null && quotedMessage.mediaSize! > 0) {
quoteMessageSize = '(${fileSizeToString(quotedMessage.mediaSize!)}) ';
} else {
quoteMessageSize = '';
}
// Create media url string, or use body if no srcUrl is stored
String quotedMediaUrl;
if (quotedMessage.srcUrl != null && quotedMessage.srcUrl!.isNotEmpty) {
quotedMediaUrl = '${quotedMessage.srcUrl!}';
} else if (quotedMessage.body.isNotEmpty){
quotedMediaUrl = '${quotedMessage.body}';
} else {
quotedMediaUrl = '';
}
// Concatenate emoji, size string, and media url and return
return '${quotedMessage.messageEmoji} $quoteMessageSize$quotedMediaUrl';
} else {
return quotedMessage.body;
}
}

View File

@ -1475,47 +1475,6 @@ class XmppService {
sendEvent(MessageUpdatedEvent(message: newMessage)); sendEvent(MessageUpdatedEvent(message: newMessage));
} }
/// Creates the fallback body for quoted messages.
/// If the quoted message contains text, it simply quotes the text.
/// If it contains a media file, the messageEmoji (usually an emoji
/// representing the mime type) is shown together with the file size
/// (from experience this information is sufficient, as most clients show
/// the file size, and including time information might be confusing and a
/// potential privacy issue).
/// This information is complemented either the srcUrl or if unavailable
/// by the body of the quoted message. For non-media messages, we always use
/// the body as fallback.
String? createFallbackBodyForQuotedMessage(Message? quotedMessage) {
if (quotedMessage == null) {
return null;
}
if (quotedMessage.isMedia) {
// Create formatted size string, if size is stored
String quoteMessageSize;
if (quotedMessage.mediaSize != null && quotedMessage.mediaSize! > 0) {
quoteMessageSize = '(${fileSizeToString(quotedMessage.mediaSize!)}) ';
} else {
quoteMessageSize = '';
}
// Create media url string, or use body if no srcUrl is stored
String quotedMediaUrl;
if (quotedMessage.srcUrl != null && quotedMessage.srcUrl!.isNotEmpty) {
quotedMediaUrl = '${quotedMessage.srcUrl!}';
} else if (quotedMessage.body.isNotEmpty){
quotedMediaUrl = '${quotedMessage.body}';
} else {
quotedMediaUrl = '';
}
// Concatenate emoji, size string, and media url and return
return '${quotedMessage.messageEmoji} $quoteMessageSize$quotedMediaUrl';
} else {
return quotedMessage.body;
}
}
Future<void> _onUnrecoverableError(NonRecoverableErrorEvent event, { dynamic extra }) async { Future<void> _onUnrecoverableError(NonRecoverableErrorEvent event, { dynamic extra }) async {
await GetIt.I.get<NotificationsService>().showWarningNotification( await GetIt.I.get<NotificationsService>().showWarningNotification(
t.notifications.titles.error, t.notifications.titles.error,