From de5dae07513fbc9323b0d2a45394fbae628e5436 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 00:46:01 +0100 Subject: [PATCH 1/3] Basic support for account/update_profile API (fixes #4094) --- doc/api.md | 18 +++++++++++++++++- include/api.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/doc/api.md b/doc/api.md index c565d8699..3306c7d4d 100644 --- a/doc/api.md +++ b/doc/api.md @@ -692,6 +692,23 @@ On error: --- +### account/update_profile (POST; AUTH) + +#### Parameters + +* name (optional): full name of the user +* description (optional): a description of the user + +#### Unsupported parameters + +* url +* location +* profile_link_color +* include_entities +* skip_status + +--- + ### friendships/incoming (*; AUTH) #### Unsupported parameters @@ -1205,7 +1222,6 @@ The following API calls from the Twitter API are not implemented in either Frien * friendships/lookup * account/settings * account/update_delivery_device -* account/update_profile * blocks/ids * users/show * users/search diff --git a/include/api.php b/include/api.php index 0b401f6df..46b7cd3de 100644 --- a/include/api.php +++ b/include/api.php @@ -4472,6 +4472,39 @@ api_register_func('api/friendica/photo/delete', 'api_fr_photo_delete', true, API api_register_func('api/friendica/photo', 'api_fr_photo_detail', true); api_register_func('api/account/update_profile_image', 'api_account_update_profile_image', true, API_METHOD_POST); +/** + * Update user profile + * + * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' + * + * @return array|string + */ +function api_account_update_profile($type) +{ + $local_user = local_user(); + $api_user = api_get_user(get_app()); + + if (x($_POST['name'])) { + dba::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]); + dba::update('user', ['username' => $_POST['name']], ['uid' => $local_user]); + dba::update('contact', ['name' => $_POST['name']], ['uid' => $local_user, 'self' => 1]); + dba::update('contact', ['name' => $_POST['name']], ['id' => $api_user['id']]); + } + + if (x($_POST['description'])) { + dba::update('profile', ['about' => $_POST['description']], ['uid' => $local_user]); + dba::update('contact', ['about' => $_POST['description']], ['uid' => $local_user, 'self' => 1]); + dba::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]); + } + + Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user()); + + return api_account_verify_credentials($type); +} + +/// @TODO move to top of file or somewhere better +api_register_func('api/account/update_profile', 'api_account_update_profile', true, API_METHOD_POST); + /** * * @param string $acl_string From 94244024aca2840913ba43992350505a3115c232 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 26 Dec 2017 01:05:00 +0100 Subject: [PATCH 2/3] Improve conditions in api_account_update_profile --- include/api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/api.php b/include/api.php index 46b7cd3de..59317fcd3 100644 --- a/include/api.php +++ b/include/api.php @@ -4481,17 +4481,17 @@ api_register_func('api/account/update_profile_image', 'api_account_update_profil */ function api_account_update_profile($type) { - $local_user = local_user(); + $local_user = api_user(); $api_user = api_get_user(get_app()); - if (x($_POST['name'])) { + if (!empty($_POST['name'])) { dba::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]); dba::update('user', ['username' => $_POST['name']], ['uid' => $local_user]); dba::update('contact', ['name' => $_POST['name']], ['uid' => $local_user, 'self' => 1]); dba::update('contact', ['name' => $_POST['name']], ['id' => $api_user['id']]); } - if (x($_POST['description'])) { + if (isset($_POST['description'])) { dba::update('profile', ['about' => $_POST['description']], ['uid' => $local_user]); dba::update('contact', ['about' => $_POST['description']], ['uid' => $local_user, 'self' => 1]); dba::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]); From c490a718acbbb8eb34d1c7f8e49806148a33380e Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 26 Dec 2017 01:08:51 +0100 Subject: [PATCH 3/3] Update profile in directory when calling api_account_update_profile --- include/api.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/api.php b/include/api.php index 59317fcd3..e2d35d59d 100644 --- a/include/api.php +++ b/include/api.php @@ -4498,6 +4498,11 @@ function api_account_update_profile($type) } Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user()); + // Update global directory in background + $url = $_SESSION['my_url']; + if ($url && strlen(Config::get('system', 'directory'))) { + Worker::add(PRIORITY_LOW, "Directory", $url); + } return api_account_verify_credentials($type); }