-
Notifications
You must be signed in to change notification settings - Fork 195
get contact pictures from social networks #1580
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
Closed
Closed
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
2fc64dd
first steps with vue, editing the menues
18ed4e5
added setup instructions
7d23da2
hide menu when no facebook id present
057c6ce
higher resolution pictures
acad8ff
moved all profile pic stuff into ContactDetailsAvatar
93ce55c
moved profile loader to page controller
23672ef
add demo image
9fcf232
handle profile ids also if uri
4e10add
improved readability
f86aba8
preparation for avatar settings page to update complete addressbook
f82fff0
creation of empty settings page
56e7a97
separated avatar logic
95f1eb6
considering recommendation from Codacy/PR Quality Review
call-me-matt 09df2f4
moved code from frontend to backend
b536fea
Merge remote-tracking branch 'upstream/master'
call-me-matt 21927f9
renaming the route into API
call-me-matt 12db28b
implemented contact access in SocialApiController
call-me-matt 19a59bd
ported code to php, fixed responses
call-me-matt 62a98e3
axios token to prevent CSRF exception
call-me-matt 00fccc4
retrieve updated contact
call-me-matt 9cb71e7
Merge remote-tracking branch 'upstream/master'
call-me-matt 8a6a00c
testing only - refresh view after backend updates
call-me-matt 28177a0
fixup! testing only - refresh view after backend updates
skjnldsv a345eb5
removed test dummy
call-me-matt c6361ec
first steps towards unit testing
call-me-matt c260ec2
first steps with unit tests
call-me-matt c5e5b9c
improving code as reviewed by skjnldsv
call-me-matt f74139c
accept only supported social networks
call-me-matt a184e98
retrieve list of supported networks from socialAPI
call-me-matt 51771f1
added support for avatar.io/twitter
call-me-matt 4d2a96a
notify if avatar unchanged
call-me-matt d990d64
using initial-state to load supported networks
call-me-matt 3eba54f
constants for network connectors, added support for tumblr, removed a…
call-me-matt 55ccf25
added vcard support for v3 and higher
call-me-matt ff69634
removing number check for fb to allow for company avatars
call-me-matt e58ddb4
Merge remote-tracking branch 'upstream/master'
call-me-matt 25d6af7
creating stubs for testing
call-me-matt 037444b
allow regex cleanups, data provider for unittests
call-me-matt eccae0c
icon change from globe to sync
call-me-matt 9a34d07
improved code style after review
call-me-matt 2cc83bf
added lock file for npm lint
call-me-matt 164b585
allowing for selection of social network
call-me-matt 8d7de9b
adapted error return codes
call-me-matt d8e2937
code cleanup, removed type for less complexity
call-me-matt b6e1731
removed doubled test case
call-me-matt 87f5f75
improved as recommended by codacy
call-me-matt 63de675
separated vcard image tag creation into own function
call-me-matt 3b3dfdd
reducing complexity
call-me-matt db096f0
Merge remote-tracking branch 'upstream/master'
call-me-matt 6a813cf
force re-fetch of contacts after update
call-me-matt cb30db5
prevent error logs for contacts without social profiles/avatars
call-me-matt 63f05e2
renaming & compatibility with nextcloud v19
call-me-matt ba3c38b
using dependency injection
call-me-matt 2bc3d03
added instagram
call-me-matt 07426a5
split controller into service
call-me-matt 4d9e45d
added admin setting to (de)activate social media integration
call-me-matt f1aac0b
enable social sync by default
call-me-matt 81e55f2
changing for vuejs (trying)
call-me-matt 2f0979e
admin settings & not case sensitive network names
133e9b9
reorder menu items according to priority
51ee1da
moved all logic from controller to service
call-me-matt e5efde0
individual icons per social network (dummies)
call-me-matt 637fb80
split service into providers
call-me-matt 0d69e4f
allowing for nextcloud v20
call-me-matt 2f4becf
code improvements according to codacy
call-me-matt c10dc11
added twitter
call-me-matt 7eb403e
added Mastodon
call-me-matt 7857b91
Merge remote-tracking branch 'upstream/master'
call-me-matt 638495a
delete previous photos during update for vCard version 3.0
call-me-matt 04e4a24
cleanup (variables)
call-me-matt b67c85d
changed icon names to lower case
call-me-matt ae14dbe
fixed identation
call-me-matt c131de8
formatting and styling issues
call-me-matt 30eb73f
never trust your inputs
call-me-matt 6ae6abd
using app name from config
call-me-matt f6eff74
changed method for avatar change to PUT
call-me-matt 381e7b8
use Nextcloud's HTTP service
call-me-matt 09ef3ee
add social icons
call-me-matt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # social network icons: | ||
| * “facebook (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/facebook?style=brands) | ||
| * “instagram (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/instagram?style=brands) | ||
| * “mastodon (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/mastodon?style=brands) | ||
| * “tumblr (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/tumblr?style=brands) | ||
| * “twitter (fab)” by fontawesome.com is licensed under CC BY 4.0. (https://fontawesome.com/icons/twitter?style=brands) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
| /** | ||
| * @copyright Copyright (c) 2020 Matthias Heinisch <nextcloud@matthiasheinisch.de> | ||
| * | ||
| * @author Matthias Heinisch <nextcloud@matthiasheinisch.de> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Contacts\Controller; | ||
|
|
||
| use OCP\IConfig; | ||
| use OCP\AppFramework\ApiController; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\JSONResponse; | ||
| use OCP\IRequest; | ||
|
|
||
| use OCA\Contacts\Service\SocialApiService; | ||
| use OCA\Contacts\AppInfo\Application; | ||
|
|
||
|
|
||
| class SocialApiController extends ApiController { | ||
|
|
||
| /** @var IConfig */ | ||
| private $config; | ||
| /** @var SocialApiService */ | ||
| private $socialApiService; | ||
|
|
||
| public function __construct( | ||
| IRequest $request, | ||
| IConfig $config, | ||
| SocialApiService $socialApiService) { | ||
| parent::__construct(Application::APP_ID, $request); | ||
|
|
||
| $this->config = $config; | ||
| $this->socialApiService = $socialApiService; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * update appconfig (admin setting) | ||
| * | ||
| * @param {String} key the identifier to change | ||
| * @param {String} allow the value to set | ||
| * | ||
| * @returns {JSONResponse} an empty JSONResponse with respective http status code | ||
| */ | ||
| public function setAppConfig($key, $allow) { | ||
| $permittedKeys = ['allowSocialSync']; | ||
| if (!in_array($key, $permittedKeys)) { | ||
| return new JSONResponse([], Http::STATUS_FORBIDDEN); | ||
| } | ||
| $this->config->setAppValue(Application::APP_ID, $key, $allow); | ||
| return new JSONResponse([], Http::STATUS_OK); | ||
| } | ||
|
|
||
| /** | ||
| * @NoAdminRequired | ||
| * | ||
| * returns an array of supported social networks | ||
| * | ||
| * @returns {array} array of the supported social networks | ||
| */ | ||
| public function getSupportedNetworks() : array { | ||
| return $this->socialApiService->getSupportedNetworks(); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * @NoAdminRequired | ||
| * | ||
| * Retrieves social profile data for a contact and updates the entry | ||
| * | ||
| * @param {String} addressbookId the addressbook identifier | ||
| * @param {String} contactId the contact identifier | ||
| * @param {String} network the social network to use (if unkown: take first match) | ||
| * | ||
| * @returns {JSONResponse} an empty JSONResponse with respective http status code | ||
| */ | ||
| public function updateContact(string $addressbookId, string $contactId, string $network) : JSONResponse { | ||
| return $this->socialApiService->updateContact($addressbookId, $contactId, $network); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <?php | ||
| /** | ||
| * @copyright 2020 Matthias Heinisch <nextcloud@matthiasheinisch.de> | ||
| * | ||
| * @author Matthias Heinisch <nextcloud@matthiasheinisch.de> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Contacts\Service\Social; | ||
|
|
||
| /** | ||
| * Composition of all social providers for easier usage | ||
| */ | ||
| class CompositeSocialProvider { | ||
|
|
||
| /** @var ISocialProvider[] */ | ||
| private $providers; | ||
|
|
||
| public function __construct(InstagramProvider $instagramProvider, | ||
| MastodonProvider $mastodonProvider, | ||
| FacebookProvider $facebookProvider, | ||
| TwitterProvider $twitterProvider, | ||
| TumblrProvider $tumblrProvider) { | ||
|
|
||
| // This determines the priority of known providers | ||
| $this->providers = [ | ||
| 'instagram' => $instagramProvider, | ||
| 'mastodon' => $mastodonProvider, | ||
| 'twitter' => $twitterProvider, | ||
| 'facebook' => $facebookProvider, | ||
| 'tumblr' => $tumblrProvider, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * returns an array of supported social providers | ||
| * | ||
| * @returns String[] array of the supported social networks | ||
| */ | ||
| public function getSupportedNetworks() : array { | ||
| return array_keys($this->providers); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * generate download url for a social entry | ||
| * | ||
| * @param array socialEntries all social data from the contact | ||
| * @param String network the choice which network to use (fallback: take first available) | ||
| * | ||
| * @returns String the url to the requested information or null in case of errors | ||
| */ | ||
| public function getSocialConnector(array $socialEntries, string $network) : ?string { | ||
|
|
||
| $connector = null; | ||
| $selection = $this->providers; | ||
| // check if dedicated network selected | ||
| if (isset($this->providers[$network])) { | ||
| $selection = [$network => $this->providers[$network]]; | ||
| } | ||
|
|
||
| // check selected providers in order | ||
| foreach($selection as $type => $socialProvider) { | ||
|
|
||
| // search for this network in user's profile | ||
| foreach ($socialEntries as $socialEntry) { | ||
|
|
||
| if (strtolower($type) === strtolower($socialEntry['type'])) { | ||
| $profileId = $socialProvider->cleanupId($socialEntry['value']); | ||
| if (!is_null($profileId)) { | ||
| $connector = $socialProvider->getImageUrl($profileId); | ||
call-me-matt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| break; | ||
| } | ||
| } | ||
| if ($connector) { | ||
| break; | ||
| } | ||
| } | ||
| return ($connector); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.