Skip to content

Commit

Permalink
fix address location filtering for sharing profile
Browse files Browse the repository at this point in the history
  • Loading branch information
LGro committed Sep 22, 2024
1 parent 99dece2 commit ef661ce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/data/repositories/contacts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,24 @@ ContactDetails filterDetails(ContactDetails details,
details.events, settings.events, activeCircles),
);

// TODO: Implement me; but maybe switch for address locations to a similar indexing scheme like with the other details for circles?
Map<int, ContactAddressLocation> filterAddressLocations(
Map<int, ContactAddressLocation> locations,
ProfileSharingSettings settings,
List<String> activeCircles) =>
locations;
{
// TODO: If we were also using "index|label" style keys for "locations", this could be simplified
for (final location in locations.entries)
if (({
for (final addressSetting in settings.addresses.entries)
int.parse(addressSetting.key.split('|').first):
addressSetting.value
}[location.key]
?.toSet() ??
{})
.intersection(activeCircles.toSet())
.isNotEmpty)
location.key: location.value
};

/// Remove locations that ended longer than a day ago, or aren't shared with the given circles
List<ContactTemporaryLocation> filterTemporaryLocations(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: coagulate
description: Staying in contact, with privacy friendly contact synchronization powered by Veilid.
publish_to: 'none'
version: "0.0.1+12"
version: "0.0.1+13"

environment:
sdk: '>=3.0.5 <4.0.0'
Expand Down
21 changes: 21 additions & 0 deletions test/data/repositories/contacts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,25 @@ void main() {
final contactWithoutPhoto = Contact.fromJson(contactJson);
expect(systemContactsEqual(contact, contactWithoutPhoto), true);
});

test('filter addresses', () {
const locations = {
0: ContactAddressLocation(
coagContactId: '1', longitude: 10, latitude: 12, name: 'loc0'),
2: ContactAddressLocation(
coagContactId: '1', longitude: 10, latitude: 12, name: 'loc2'),
3: ContactAddressLocation(
coagContactId: '1', longitude: 10, latitude: 12, name: 'loc3'),
};
const settings = ProfileSharingSettings(addresses: {
'0|home': ['circle1'],
'3|work': ['circle2', 'circle3'],
});
const activeCircles = ['circle1'];
final filteredLocations =
filterAddressLocations(locations, settings, activeCircles);
expect(filteredLocations.length, 1);
expect(filteredLocations.keys.first, 0);
expect(filteredLocations.values.first.name, 'loc0');
});
}

0 comments on commit ef661ce

Please sign in to comment.