Skip to content

Commit

Permalink
Merge 137e24b into 7720468
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Jul 15, 2021
2 parents 7720468 + 137e24b commit 4e4c80a
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/Cron/SocialUpdate.php
Expand Up @@ -46,7 +46,7 @@ protected function run($arguments) {
$offsetContact = $arguments['offsetContact'] ?? null;

// update contacts with first available social media profile
$result = $this->social->updateAddressbooks('any', $userId, $offsetBook, $offsetContact);
$result = $this->social->updateAddressbooks($userId, $offsetBook, $offsetContact);

if ($result->getStatus() === Http::STATUS_PARTIAL_CONTENT) {
// not finished; schedule a follow-up
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/DiasporaProvider.php
Expand Up @@ -49,6 +49,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/FacebookProvider.php
Expand Up @@ -45,6 +45,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfiles($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/GravatarProvider.php
Expand Up @@ -38,6 +38,9 @@ public function __construct() {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("EMAIL",$contact)) {
return false;
}
$emails = $contact['EMAIL'];
return isset($emails) && count($emails);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/InstagramProvider.php
Expand Up @@ -55,6 +55,9 @@ public function __construct(IClientService $httpClient,
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfiles($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/MastodonProvider.php
Expand Up @@ -45,6 +45,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$profiles = $this->getProfileIds($contact);
return isset($profiles) && count($profiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/TumblrProvider.php
Expand Up @@ -38,6 +38,9 @@ public function __construct() {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/TwitterProvider.php
Expand Up @@ -54,6 +54,9 @@ public function __construct(IClientService $httpClient,
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/Social/XingProvider.php
Expand Up @@ -45,6 +45,9 @@ public function __construct(IClientService $httpClient) {
* @return bool
*/
public function supportsContact(array $contact):bool {
if (!array_key_exists("X-SOCIALPROFILE",$contact)) {
return false;
}
$socialprofiles = $this->getProfileIds($contact);
return isset($socialprofiles) && count($socialprofiles) > 0;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/SocialApiService.php
Expand Up @@ -342,12 +342,12 @@ protected function sortContacts(array $a, array $b) {
/**
* Updates social profile data for all contacts of an addressbook
*
* @param {String} network the social network to use (fallback: take first match)
* @param {String|null} network the social network to use (take first match if unset)
* @param {String} userId the address book owner
*
* @returns {JSONResponse} JSONResponse with the list of changed and failed contacts
*/
public function updateAddressbooks(string $network, string $userId, string $offsetBook = null, string $offsetContact = null) : JSONResponse {
public function updateAddressbooks(string $userId, string $offsetBook = null, string $offsetContact = null, string $network = null) : JSONResponse {

// double check!
$syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes');
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/Service/SocialApiServiceTest.php
Expand Up @@ -237,7 +237,7 @@ public function testUpdateContactWithNetworkVersion3() {
'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);
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testUpdateContactWithNetworkVersion4() {
'VERSION' => $contact['VERSION'],
'PHOTO' => "data:".$imageType.";base64," . base64_encode($body)
];

$this->socialProvider
->expects($this->once())->method("getSocialConnector")->with($network);
$provider->expects($this->once())->method("supportsContact")->with($contact);
Expand Down Expand Up @@ -442,7 +442,17 @@ public function testUpdateAddressbooks($syncAllowedByAdmin, $bgSyncEnabledByUser

$this->setupAddressbooks();

$result = $this->service->updateAddressbooks('any', 'mrstest');
if ($syncAllowedByAdmin === 'yes' && $bgSyncEnabledByUser === 'yes') {
$this->socialProvider
->expects($this->atLeastOnce())
->method('getSocialConnectors');
}

$this->socialProvider
->expects($this->never())
->method('getSocialConnector');

$result = $this->service->updateAddressbooks('mrstest');

$this->assertEquals($expected, $result->getStatus());

Expand Down Expand Up @@ -474,7 +484,7 @@ public function testUpdateAddressbooksTimeout() {

$this->setupAddressbooks();

$result = $this->service->updateAddressbooks('any', 'msstest');
$result = $this->service->updateAddressbooks('msstest');

$this->assertEquals(Http::STATUS_PARTIAL_CONTENT, $result->getStatus());

Expand Down Expand Up @@ -502,7 +512,7 @@ public function testUpdateAddressbooksContinued($syncAllowedByAdmin, $bgSyncEnab

$this->setupAddressbooks();

$result = $this->service->updateAddressbooks('any', 'mrstest', 'contacts2', '22222222-2222-2222-2222-222222222222');
$result = $this->service->updateAddressbooks('mrstest', 'contacts2', '22222222-2222-2222-2222-222222222222');

$this->assertEquals($expected, $result->getStatus());

Expand Down

0 comments on commit 4e4c80a

Please sign in to comment.