From 3d6bcd3bf97741c729b23ba79a3e737aec483fa2 Mon Sep 17 00:00:00 2001 From: leith abdulla Date: Sat, 7 Nov 2020 15:56:32 +0000 Subject: vcard should only have 1 photo field when adding/removing photos when adding photo fields through the social api service, an extra photo field is created for vcard version 3.0 due to setting a field as empty instead of unsetting it all together when removing photo fields, this empty photo field is left untouched thus, syncing photos to address book clients can be buggy as most address book clients do not properly iterate through all photo fields to display the contact photo Signed-off-by: leith abdulla --- lib/Service/SocialApiService.php | 2 +- .../ContactDetails/ContactDetailsAvatar.vue | 2 +- tests/unit/Service/SocialApiServiceTest.php | 71 +++++++++++++++++++++- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/Service/SocialApiService.php b/lib/Service/SocialApiService.php index 446a9ef6..b1657734 100644 --- a/lib/Service/SocialApiService.php +++ b/lib/Service/SocialApiService.php @@ -118,7 +118,7 @@ class SocialApiService { $contact['PHOTO;ENCODING=b;TYPE=' . $imageType . ';VALUE=BINARY'] = $photo; // remove previous photo (necessary as new attribute is not equal to 'PHOTO') - $contact['PHOTO'] = ''; + unset($contact['PHOTO']); } } diff --git a/src/components/ContactDetails/ContactDetailsAvatar.vue b/src/components/ContactDetails/ContactDetailsAvatar.vue index 8f631eb5..5a43ac08 100644 --- a/src/components/ContactDetails/ContactDetailsAvatar.vue +++ b/src/components/ContactDetails/ContactDetailsAvatar.vue @@ -368,7 +368,7 @@ export default { */ removePhoto() { this.maximizeAvatar = false - this.contact.vCard.removeProperty('photo') + this.contact.vCard.removeAllProperties('photo') this.$store.dispatch('updateContact', this.contact) }, diff --git a/tests/unit/Service/SocialApiServiceTest.php b/tests/unit/Service/SocialApiServiceTest.php index e7f4c8e3..eba6d9a3 100644 --- a/tests/unit/Service/SocialApiServiceTest.php +++ b/tests/unit/Service/SocialApiServiceTest.php @@ -183,7 +183,76 @@ class SocialApiServiceTest extends TestCase { $this->assertEquals($status, $result->getStatus()); } - public function testUpdateContactWithNetwork() { + public function testUpdateContactWithNetworkVersion3() { + $network = "mastodon"; + $body = "the body"; + $imageType = "jpg"; + $addressBookId = "contacts"; + $contactId = "3225c0d5-1bd2-43e5-a08c-4e65eaa406b0"; + $contact = [ + 'URI' => $contactId, + 'VERSION' => '3.0' + ]; + $provider = $this->createMock(ISocialProvider::class); + $provider->method('supportsContact')->willReturn(true); + $provider->method('getImageUrls')->willReturn(["url1"]); + + $addressbook = $this->createMock(IAddressBook::class); + $addressbook + ->method('getUri') + ->willReturn('contacts'); + $addressbook + ->method('search') + ->willReturn([$contact]); + + $this->manager + ->method('getUserAddressBooks') + ->willReturn([$addressbook]); + + $this->socialProvider + ->method('getSocialConnectors') + ->willReturn([$provider]); + + $this->socialProvider + ->method('getSocialConnector') + ->willReturn($provider); + + $response = $this->createMock(IResponse::class); + $response + ->method('getBody') + ->willReturn($body); + $response + ->method('getHeader') + ->willReturn($imageType); + $client = $this->createMock(IClient::class); + $client + ->method('get') + ->willReturn($response); + $this->clientService + ->method('NewClient') + ->willReturn($client); + + $changes = [ + 'URI' => $contact['URI'], + 'VERSION' => $contact['VERSION'], + 'PHOTO;ENCODING=b;TYPE=' . $imageType . ';VALUE=BINARY' => base64_encode($body) + ]; + + $this->socialProvider + ->expects($this->once())->method("getSocialConnector")->with($network); + $provider->expects($this->once())->method("supportsContact")->with($contact); + $addressbook->expects($this->once())->method("createOrUpdate")->with($changes, $addressBookId); + + $result = $this->service + ->updateContact( + $addressBookId, + $contactId, + $network); + + $this->assertEquals(Http::STATUS_OK, $result->getStatus()); + } + + public function testUpdateContactWithNetworkVersion4() { $network = "mastodon"; $body = "the body"; $imageType = "jpg"; -- cgit v1.2.3