mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-04-18 12:52:53 +00:00
only force create avatars in case they where changed or did not yet exists
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
Some checks are pending
Flutter analyze & test / flutter_analyze_and_test (push) Waiting to run
This commit is contained in:
parent
9b848138df
commit
68cf1b6b89
2 changed files with 21 additions and 8 deletions
|
|
@ -124,14 +124,15 @@ Future<void> handleContactUpdate(
|
|||
await twonlyDB.contactsDao.updateContact(
|
||||
fromUserId,
|
||||
ContactsCompanion(
|
||||
avatarSvgCompressed:
|
||||
Value(Uint8List.fromList(contactUpdate.avatarSvgCompressed)),
|
||||
avatarSvgCompressed: Value(
|
||||
Uint8List.fromList(contactUpdate.avatarSvgCompressed),
|
||||
),
|
||||
displayName: Value(contactUpdate.displayName),
|
||||
username: Value(contactUpdate.username),
|
||||
senderProfileCounter: Value(senderProfileCounter),
|
||||
),
|
||||
);
|
||||
unawaited(createPushAvatars());
|
||||
unawaited(createPushAvatars(forceForUserId: fromUserId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,21 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:twonly/globals.dart';
|
||||
import 'package:twonly/src/utils/misc.dart';
|
||||
|
||||
Future<void> createPushAvatars() async {
|
||||
Future<void> createPushAvatars({int? forceForUserId}) async {
|
||||
final contacts = await twonlyDB.contactsDao.getAllContacts();
|
||||
|
||||
for (final contact in contacts) {
|
||||
if (contact.avatarSvgCompressed == null) continue;
|
||||
|
||||
if (forceForUserId == null) {
|
||||
if (avatarPNGFile(contact.userId).existsSync()) {
|
||||
continue; // only create the avatar in case no avatar exists yet fot this user
|
||||
}
|
||||
} else if (contact.userId != forceForUserId) {
|
||||
// only update the avatar for this specified contact
|
||||
continue;
|
||||
}
|
||||
|
||||
final avatarSvg = getAvatarSvg(contact.avatarSvgCompressed!);
|
||||
|
||||
final pictureInfo = await vg.loadPicture(SvgStringLoader(avatarSvg), null);
|
||||
|
|
@ -27,8 +36,9 @@ Future<void> createPushAvatars() async {
|
|||
}
|
||||
|
||||
File avatarPNGFile(int contactId) {
|
||||
final avatarsDirectory =
|
||||
Directory('$globalApplicationCacheDirectory/avatars');
|
||||
final avatarsDirectory = Directory(
|
||||
'$globalApplicationCacheDirectory/avatars',
|
||||
);
|
||||
|
||||
if (!avatarsDirectory.existsSync()) {
|
||||
avatarsDirectory.createSync(recursive: true);
|
||||
|
|
@ -42,8 +52,10 @@ Future<Uint8List> getUserAvatar() async {
|
|||
return data.buffer.asUint8List();
|
||||
}
|
||||
|
||||
final pictureInfo =
|
||||
await vg.loadPicture(SvgStringLoader(gUser.avatarSvg!), null);
|
||||
final pictureInfo = await vg.loadPicture(
|
||||
SvgStringLoader(gUser.avatarSvg!),
|
||||
null,
|
||||
);
|
||||
|
||||
final image = await pictureInfo.picture.toImage(270, 300);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue