fix(service): Optionally send the roster item's contact title

This commit is contained in:
PapaTutuWawa 2023-08-17 17:42:51 +02:00
parent 1de6bab86e
commit 0dc44572b1
2 changed files with 23 additions and 2 deletions

View File

@ -1643,8 +1643,7 @@ Future<void> performFetchRecipientInformation(
items.add(
SendFilesRecipient(
rosterItem.jid,
// TODO: Check if we can use the contact title
rosterItem.title,
await rosterItem.titleWithOptionalContactService,
rosterItem.avatarPath.isEmpty ? null : rosterItem.avatarPath,
rosterItem.avatarHash.isEmpty ? null : rosterItem.avatarHash,
rosterItem.contactId != null,

View File

@ -1,5 +1,7 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:get_it/get_it.dart';
import 'package:moxxyv2/service/database/helpers.dart';
import 'package:moxxyv2/service/preferences.dart';
part 'roster.freezed.dart';
part 'roster.g.dart';
@ -90,4 +92,24 @@ class RosterItem with _$RosterItem {
return true;
}
/// The title of the roster item. This returns, if [contactIntegration] is true, first the contact's display
/// name, then the XMPP roster title. If [contactIntegration] is false, just returns the XMPP roster
/// title.
String getTitleWithOptionalContact(bool contactIntegration) {
if (contactIntegration) {
return contactDisplayName ?? title;
}
return title;
}
/// This getter is a short-hand for [getTitleWithOptionalContact] with the
/// contact integration enablement status extracted from the [PreferencesService].
/// NOTE: This method only works in the background isolate.
Future<String> get titleWithOptionalContactService async =>
getTitleWithOptionalContact(
(await GetIt.I.get<PreferencesService>().getPreferences())
.enableContactIntegration,
);
}