From 972855cc64fabb78757638b26dc657c4593d51a6 Mon Sep 17 00:00:00 2001 From: Sardar1208 Date: Thu, 21 Dec 2023 14:45:45 +0530 Subject: [PATCH 1/2] fix: fixed profile picture fetch methods --- .../Flutter/GeneratedPluginRegistrant.swift | 2 +- .../lib/services/contact_service.dart | 53 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/at_contacts_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift b/packages/at_contacts_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift index 508252dd..591d027b 100644 --- a/packages/at_contacts_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/packages/at_contacts_flutter/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -20,7 +20,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { BiometricStorageMacOSPlugin.register(with: registry.registrar(forPlugin: "BiometricStorageMacOSPlugin")) DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) - FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) + FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) diff --git a/packages/at_contacts_flutter/lib/services/contact_service.dart b/packages/at_contacts_flutter/lib/services/contact_service.dart index 106fa834..d5fe7fe3 100644 --- a/packages/at_contacts_flutter/lib/services/contact_service.dart +++ b/packages/at_contacts_flutter/lib/services/contact_service.dart @@ -574,7 +574,11 @@ class ContactService { key.metadata?.isBinary = true; key.key = contactFields[2]; Uint8List? image; - var result = await atClientManager.atClient.get(key); + + GetRequestOptions options = GetRequestOptions(); + options.bypassCache = true; + var result = + await atClientManager.atClient.get(key, getRequestOptions: options); if (result.value != null) { try { @@ -595,6 +599,53 @@ class ContactService { return contactDetails; } + getProfilePicture(String atsign) async { + var contactDetails = {}; + + var metadata = Metadata(); + metadata.isPublic = true; + metadata.namespaceAware = false; + var key = AtKey(); + key.sharedBy = atsign; + key.metadata = metadata; + // making isPublic true (as get method changes it to false) + key.metadata?.isBinary = true; + key.key = "image.wavi"; + + GetRequestOptions options = GetRequestOptions(); + options.bypassCache = true; + var result = + await atClientManager.atClient.get(key, getRequestOptions: options); + + if (result.value != null) { + try { + List intList = result.value.cast(); + var image = Uint8List.fromList(intList); + contactDetails['image'] = image; + return contactDetails; + } catch (e) { + print('invalid iamge data: $e'); + contactDetails['image'] = null; + return contactDetails; + } + } + } + + fetchProfilePictureMetaData(String atsign) async { + var metadata = Metadata(); + metadata.isPublic = true; + metadata.namespaceAware = false; + var key = AtKey(); + key.sharedBy = atsign; + key.metadata = metadata; + // making isPublic true (as get method changes it to false) + key.metadata?.isBinary = true; + key.key = "image.wavi"; + + var result = await atClientManager.atClient.getMeta(key); + return result; + } + /// updates status of contacts for [baseContactList] and [baseBlockedList] void updateState(STATE_UPDATE stateToUpdate, AtContact contact, bool state) { int indexToUpdate; From 0122544bb900a40d1e48e783eb038e532265e152 Mon Sep 17 00:00:00 2001 From: Sardar1208 Date: Fri, 22 Dec 2023 12:28:32 +0530 Subject: [PATCH 2/2] chore: added return type to functions --- .../at_contacts_flutter/lib/services/contact_service.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/at_contacts_flutter/lib/services/contact_service.dart b/packages/at_contacts_flutter/lib/services/contact_service.dart index d5fe7fe3..b22e4ada 100644 --- a/packages/at_contacts_flutter/lib/services/contact_service.dart +++ b/packages/at_contacts_flutter/lib/services/contact_service.dart @@ -599,7 +599,7 @@ class ContactService { return contactDetails; } - getProfilePicture(String atsign) async { + Future?> getProfilePicture(String atsign) async { var contactDetails = {}; var metadata = Metadata(); @@ -628,10 +628,12 @@ class ContactService { contactDetails['image'] = null; return contactDetails; } + }else { + return null; } } - fetchProfilePictureMetaData(String atsign) async { + Future fetchProfilePictureMetaData(String atsign) async { var metadata = Metadata(); metadata.isPublic = true; metadata.namespaceAware = false;