Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed profile picture fetch methods #777

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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