Skip to content

Commit

Permalink
Merge pull request #777 from atsign-foundation/feat/profile_picture_fix
Browse files Browse the repository at this point in the history
fix: fixed profile picture fetch methods
  • Loading branch information
Sardar1208 authored Dec 22, 2023
2 parents a9f2e66 + 0122544 commit 180689c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
55 changes: 54 additions & 1 deletion packages/at_contacts_flutter/lib/services/contact_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -595,6 +599,55 @@ class ContactService {
return contactDetails;
}

Future<Map<String, dynamic>?> getProfilePicture(String atsign) async {
var contactDetails = <String, dynamic>{};

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<int> intList = result.value.cast<int>();
var image = Uint8List.fromList(intList);
contactDetails['image'] = image;
return contactDetails;
} catch (e) {
print('invalid iamge data: $e');
contactDetails['image'] = null;
return contactDetails;
}
}else {
return null;
}
}

Future<Metadata?> 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;
Expand Down

0 comments on commit 180689c

Please sign in to comment.