mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-04-18 14:42:54 +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(
|
await twonlyDB.contactsDao.updateContact(
|
||||||
fromUserId,
|
fromUserId,
|
||||||
ContactsCompanion(
|
ContactsCompanion(
|
||||||
avatarSvgCompressed:
|
avatarSvgCompressed: Value(
|
||||||
Value(Uint8List.fromList(contactUpdate.avatarSvgCompressed)),
|
Uint8List.fromList(contactUpdate.avatarSvgCompressed),
|
||||||
|
),
|
||||||
displayName: Value(contactUpdate.displayName),
|
displayName: Value(contactUpdate.displayName),
|
||||||
username: Value(contactUpdate.username),
|
username: Value(contactUpdate.username),
|
||||||
senderProfileCounter: Value(senderProfileCounter),
|
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/globals.dart';
|
||||||
import 'package:twonly/src/utils/misc.dart';
|
import 'package:twonly/src/utils/misc.dart';
|
||||||
|
|
||||||
Future<void> createPushAvatars() async {
|
Future<void> createPushAvatars({int? forceForUserId}) async {
|
||||||
final contacts = await twonlyDB.contactsDao.getAllContacts();
|
final contacts = await twonlyDB.contactsDao.getAllContacts();
|
||||||
|
|
||||||
for (final contact in contacts) {
|
for (final contact in contacts) {
|
||||||
if (contact.avatarSvgCompressed == null) continue;
|
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 avatarSvg = getAvatarSvg(contact.avatarSvgCompressed!);
|
||||||
|
|
||||||
final pictureInfo = await vg.loadPicture(SvgStringLoader(avatarSvg), null);
|
final pictureInfo = await vg.loadPicture(SvgStringLoader(avatarSvg), null);
|
||||||
|
|
@ -27,8 +36,9 @@ Future<void> createPushAvatars() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
File avatarPNGFile(int contactId) {
|
File avatarPNGFile(int contactId) {
|
||||||
final avatarsDirectory =
|
final avatarsDirectory = Directory(
|
||||||
Directory('$globalApplicationCacheDirectory/avatars');
|
'$globalApplicationCacheDirectory/avatars',
|
||||||
|
);
|
||||||
|
|
||||||
if (!avatarsDirectory.existsSync()) {
|
if (!avatarsDirectory.existsSync()) {
|
||||||
avatarsDirectory.createSync(recursive: true);
|
avatarsDirectory.createSync(recursive: true);
|
||||||
|
|
@ -42,8 +52,10 @@ Future<Uint8List> getUserAvatar() async {
|
||||||
return data.buffer.asUint8List();
|
return data.buffer.asUint8List();
|
||||||
}
|
}
|
||||||
|
|
||||||
final pictureInfo =
|
final pictureInfo = await vg.loadPicture(
|
||||||
await vg.loadPicture(SvgStringLoader(gUser.avatarSvg!), null);
|
SvgStringLoader(gUser.avatarSvg!),
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
final image = await pictureInfo.picture.toImage(270, 300);
|
final image = await pictureInfo.picture.toImage(270, 300);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue