kopia lustrzana https://github.com/nextcloud/social
Addind accountId and follows
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/2/head
rodzic
04972c6118
commit
aa7a43ecac
|
@ -83,6 +83,12 @@
|
||||||
<length>127</length>
|
<length>127</length>
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
|
<field>
|
||||||
|
<name>account_id</name>
|
||||||
|
<type>integer</type>
|
||||||
|
<length>7</length>
|
||||||
|
</field>
|
||||||
|
|
||||||
<field>
|
<field>
|
||||||
<name>status</name>
|
<name>status</name>
|
||||||
<type>integer</type>
|
<type>integer</type>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<name>Social</name>
|
<name>Social</name>
|
||||||
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
|
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
|
||||||
<description><![CDATA[test]]></description>
|
<description><![CDATA[test]]></description>
|
||||||
<version>0.0.9</version>
|
<version>0.0.10</version>
|
||||||
<licence>agpl</licence>
|
<licence>agpl</licence>
|
||||||
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
|
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
|
||||||
<author mail="jus@bitgrid.net">Julius Härtl</author>
|
<author mail="jus@bitgrid.net">Julius Härtl</author>
|
||||||
|
|
|
@ -23,11 +23,19 @@ return [
|
||||||
'name' => 'ActivityStreams#test', 'url' => '/user/account/{accountId}/test',
|
'name' => 'ActivityStreams#test', 'url' => '/user/account/{accountId}/test',
|
||||||
'verb' => 'GET'
|
'verb' => 'GET'
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'name' => 'ActivityStreams#posts', 'url' => '/user/account/{accountId}/posts',
|
||||||
|
'verb' => 'GET'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'ActivityStreams#follows', 'url' => '/user/account/{accountId}/follows',
|
||||||
|
'verb' => 'GET'
|
||||||
|
],
|
||||||
|
|
||||||
// [
|
// [
|
||||||
// 'name' => 'OAuth2#getAuthUrl', 'url' => '/client/oauth2/auth/{serviceId}/',
|
// 'name' => 'OAuth2#getAuthUrl', 'url' => '/client/oauth2/auth/{serviceId}/',
|
||||||
// 'verb' => 'GET'
|
// 'verb' => 'GET'
|
||||||
// ],
|
// ],
|
||||||
[
|
[
|
||||||
'name' => 'OAuth2#setCode', 'url' => '/client/oauth2/redirect/{serviceId}/',
|
'name' => 'OAuth2#setCode', 'url' => '/client/oauth2/redirect/{serviceId}/',
|
||||||
'verb' => 'GET'
|
'verb' => 'GET'
|
||||||
|
|
33
js/test.js
33
js/test.js
|
@ -41,8 +41,11 @@
|
||||||
elem.socialListAccounts.empty()
|
elem.socialListAccounts.empty()
|
||||||
for (var i = 0; i < data.result.accounts.length; i++) {
|
for (var i = 0; i < data.result.accounts.length; i++) {
|
||||||
var item = data.result.accounts[i]
|
var item = data.result.accounts[i]
|
||||||
elem.socialListAccounts.append($('<option>', {value: item.id}).text(item.account + '@' + item.service.address))
|
elem.socialListAccounts.append(
|
||||||
|
$('<option>', {value: item.id}).text(item.account + '@' + item.service.address))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test.refreshData()
|
||||||
},
|
},
|
||||||
|
|
||||||
testAccount: function (accountId) {
|
testAccount: function (accountId) {
|
||||||
|
@ -53,6 +56,28 @@
|
||||||
console.log(JSON.stringify(data))
|
console.log(JSON.stringify(data))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getAccountPosts: function (accountId) {
|
||||||
|
test.sendRequest('GET', {}, '/user/account/' + accountId + '/posts', test.getAccountPostsResult)
|
||||||
|
},
|
||||||
|
|
||||||
|
getAccountPostsResult: function (data) {
|
||||||
|
console.log('Your posts: ' + JSON.stringify(data))
|
||||||
|
},
|
||||||
|
|
||||||
|
getAccountFollows: function (accountId) {
|
||||||
|
test.sendRequest('GET', {}, '/user/account/' + accountId + '/follows',
|
||||||
|
test.getAccountFollowsResult)
|
||||||
|
},
|
||||||
|
|
||||||
|
getAccountFollowsResult: function (data) {
|
||||||
|
console.log('Your Follows: ' + JSON.stringify(data))
|
||||||
|
},
|
||||||
|
|
||||||
|
refreshData: function () {
|
||||||
|
var accountId = elem.socialListAccounts.val()
|
||||||
|
test.getAccountFollows(accountId)
|
||||||
|
},
|
||||||
|
|
||||||
sendRequest: function (method, data, url, callback) {
|
sendRequest: function (method, data, url, callback) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: method,
|
method: method,
|
||||||
|
@ -94,7 +119,13 @@
|
||||||
test.testAccount(elem.socialListAccounts.val())
|
test.testAccount(elem.socialListAccounts.val())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
elem.socialListAccounts.on('change', function () {
|
||||||
|
test.refreshData()
|
||||||
|
})
|
||||||
|
|
||||||
test.getAccounts()
|
test.getAccounts()
|
||||||
|
|
||||||
|
// test.getAccountPosts()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OCA.Social === undefined) {
|
if (OCA.Social === undefined) {
|
||||||
|
|
|
@ -108,5 +108,46 @@ class ActivityStreamsController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param int $accountId
|
||||||
|
*
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function posts(int $accountId): DataResponse {
|
||||||
|
try {
|
||||||
|
$account = $this->serviceAccountsService->getAccount($this->userId, $accountId);
|
||||||
|
|
||||||
|
$result = $this->activityStreamsService->posts($account);
|
||||||
|
|
||||||
|
return $this->success($result);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $this->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param int $accountId
|
||||||
|
*
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function follows(int $accountId): DataResponse {
|
||||||
|
try {
|
||||||
|
$account = $this->serviceAccountsService->getAccount($this->userId, $accountId);
|
||||||
|
$result = $this->activityStreamsService->follows($account);
|
||||||
|
|
||||||
|
return $this->success($result);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $this->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,6 @@ class ServiceAccountsController extends Controller {
|
||||||
'protocol' => 'OAuth2',
|
'protocol' => 'OAuth2',
|
||||||
'authorizationUrl' => $authUrl
|
'authorizationUrl' => $authUrl
|
||||||
];
|
];
|
||||||
$this->miscService->log('___' . json_encode($data));
|
|
||||||
|
|
||||||
return $this->success($data);
|
return $this->success($data);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
|
@ -75,6 +75,7 @@ class ServiceAccountsRequest extends ServiceAccountsRequestBuilder {
|
||||||
$qb->setValue('service_id', $qb->createNamedParameter($service->getId()))
|
$qb->setValue('service_id', $qb->createNamedParameter($service->getId()))
|
||||||
->setValue('user_id', $qb->createNamedParameter($account->getUserId()))
|
->setValue('user_id', $qb->createNamedParameter($account->getUserId()))
|
||||||
->setValue('account', $qb->createNamedParameter($account->getAccount()))
|
->setValue('account', $qb->createNamedParameter($account->getAccount()))
|
||||||
|
->setValue('account_id', $qb->createNamedParameter($account->getAccountId()))
|
||||||
->setValue('status', $qb->createNamedParameter($account->getStatus()))
|
->setValue('status', $qb->createNamedParameter($account->getStatus()))
|
||||||
->setValue('auth', $qb->createNamedParameter(json_encode($account->getAuthAll())));
|
->setValue('auth', $qb->createNamedParameter(json_encode($account->getAuthAll())));
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ class ServiceAccountsRequestBuilder extends CoreRequestBuilder {
|
||||||
|
|
||||||
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
/** @noinspection PhpMethodParametersCountMismatchInspection */
|
||||||
$qb->select(
|
$qb->select(
|
||||||
'a.id', 'a.service_id', 'a.user_id', 'a.account', 'a.status', 'a.auth', 'a.config',
|
'a.id', 'a.service_id', 'a.user_id', 'a.account', 'a.account_id', 'a.status', 'a.auth',
|
||||||
'a.creation'
|
'a.config', 'a.creation'
|
||||||
)
|
)
|
||||||
->from(self::TABLE_ACCOUNTS, 'a');
|
->from(self::TABLE_ACCOUNTS, 'a');
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ class ServiceAccountsRequestBuilder extends CoreRequestBuilder {
|
||||||
$account->setService($service)
|
$account->setService($service)
|
||||||
->setUserId($data['user_id'])
|
->setUserId($data['user_id'])
|
||||||
->setAccount($this->get('account', $data, ''))
|
->setAccount($this->get('account', $data, ''))
|
||||||
|
->setAccountId($this->getInt('account_id', $data, 0))
|
||||||
->setStatus($this->getInt('status', $data, 0))
|
->setStatus($this->getInt('status', $data, 0))
|
||||||
->setAuthAll(json_decode($this->get('auth', $data, '[]'), true))
|
->setAuthAll(json_decode($this->get('auth', $data, '[]'), true))
|
||||||
->setConfigAll(json_decode($this->get('config', $data, '[]'), true))
|
->setConfigAll(json_decode($this->get('config', $data, '[]'), true))
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\Social\Exceptions;
|
||||||
|
|
||||||
|
class APIRequestException extends \Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ class ServiceAccount implements \JsonSerializable {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $account = '';
|
private $account = '';
|
||||||
|
|
||||||
|
/** @var int */
|
||||||
|
private $accountId = 0;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $status = 0;
|
private $status = 0;
|
||||||
|
|
||||||
|
@ -125,6 +128,25 @@ class ServiceAccount implements \JsonSerializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getAccountId(): int {
|
||||||
|
return $this->accountId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $accountId
|
||||||
|
*
|
||||||
|
* @return ServiceAccount
|
||||||
|
*/
|
||||||
|
public function setAccountId(int $accountId): ServiceAccount {
|
||||||
|
$this->accountId = $accountId;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
@ -143,6 +165,7 @@ class ServiceAccount implements \JsonSerializable {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
@ -310,12 +333,13 @@ class ServiceAccount implements \JsonSerializable {
|
||||||
*/
|
*/
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
return [
|
return [
|
||||||
'id' => $this->getId(),
|
'id' => $this->getId(),
|
||||||
'service' => $this->getService(),
|
'service' => $this->getService(),
|
||||||
'userId' => $this->getUserId(),
|
'userId' => $this->getUserId(),
|
||||||
'account' => $this->getAccount(),
|
'account' => $this->getAccount(),
|
||||||
'auth' => $this->getAuthAll(),
|
'account_id' => $this->getAccountId(),
|
||||||
'creation' => $this->getCreation()
|
'auth' => $this->getAuthAll(),
|
||||||
|
'creation' => $this->getCreation()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,9 @@ class ActivityStreamsService {
|
||||||
const URL_CREATE_APP = '/api/v1/apps';
|
const URL_CREATE_APP = '/api/v1/apps';
|
||||||
const URL_VERIFY_ACCOUNT = '/api/v1/accounts/verify_credentials';
|
const URL_VERIFY_ACCOUNT = '/api/v1/accounts/verify_credentials';
|
||||||
const URL_TEST = '/api/v1/accounts/verify_credentials';
|
const URL_TEST = '/api/v1/accounts/verify_credentials';
|
||||||
|
const URL_ACCOUNT_POSTS = '/api/v1/accounts/verify_credentials';
|
||||||
|
const URL_ACCOUNT_FOLLOWS = '/api/v1/accounts/:id/following';
|
||||||
|
const URL_ACCOUNT_FOLLOWERS = '/api/v1/accounts/:id/followers';
|
||||||
|
|
||||||
|
|
||||||
use TOAuth2;
|
use TOAuth2;
|
||||||
|
@ -93,6 +96,33 @@ class ActivityStreamsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ServiceAccount $account
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function posts(ServiceAccount $account) {
|
||||||
|
$request = new Request(self::URL_ACCOUNT_POSTS, Request::TYPE_GET);
|
||||||
|
|
||||||
|
return $this->request($account, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ServiceAccount $account
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function follows(ServiceAccount $account) {
|
||||||
|
$request = new Request(self::URL_ACCOUNT_FOLLOWS, Request::TYPE_GET);
|
||||||
|
$request->addDataInt('id', $account->getAccountId());
|
||||||
|
|
||||||
|
return $this->request($account, $request);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ServiceAccount $account
|
* @param ServiceAccount $account
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace OCA\Social\Service;
|
||||||
|
|
||||||
|
|
||||||
use daita\Model\Request;
|
use daita\Model\Request;
|
||||||
|
use OCA\Social\Exceptions\APIRequestException;
|
||||||
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
use OCA\Social\Exceptions\InvalidAccessTokenException;
|
||||||
use OCA\Social\Exceptions\MovedPermanentlyException;
|
use OCA\Social\Exceptions\MovedPermanentlyException;
|
||||||
use OCA\Social\Model\ServiceAccount;
|
use OCA\Social\Model\ServiceAccount;
|
||||||
|
@ -60,6 +61,7 @@ class CurlService {
|
||||||
* @return array
|
* @return array
|
||||||
* @throws InvalidAccessTokenException
|
* @throws InvalidAccessTokenException
|
||||||
* @throws MovedPermanentlyException
|
* @throws MovedPermanentlyException
|
||||||
|
* @throws APIRequestException
|
||||||
*/
|
*/
|
||||||
public function request(ServiceAccount $account, Request $request, bool $authed = true) {
|
public function request(ServiceAccount $account, Request $request, bool $authed = true) {
|
||||||
|
|
||||||
|
@ -70,9 +72,9 @@ class CurlService {
|
||||||
|
|
||||||
$result = curl_exec($curl);
|
$result = curl_exec($curl);
|
||||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
|
|
||||||
$this->parseRequestResultCode301($code);
|
$this->parseRequestResultCode301($code);
|
||||||
$this->parseRequestResultCode401($code);
|
$this->parseRequestResultCode401($code);
|
||||||
|
$this->parseRequestResultCode404($code);
|
||||||
// $this->parseRequestResultCode503($code);
|
// $this->parseRequestResultCode503($code);
|
||||||
// $this->parseRequestResultCode500($code);
|
// $this->parseRequestResultCode500($code);
|
||||||
// $this->parseRequestResult($result);
|
// $this->parseRequestResult($result);
|
||||||
|
@ -115,10 +117,8 @@ class CurlService {
|
||||||
* @return resource
|
* @return resource
|
||||||
*/
|
*/
|
||||||
private function generateCurlRequest(ServiceAccount $account, Request $request) {
|
private function generateCurlRequest(ServiceAccount $account, Request $request) {
|
||||||
|
|
||||||
$service = $account->getService();
|
$service = $account->getService();
|
||||||
// $service->setAddress('mastodon.social');
|
$url = 'https://' . $service->getAddress() . $request->getParsedUrl();
|
||||||
$url = 'https://' . $service->getAddress() . $request->getUrl();
|
|
||||||
|
|
||||||
if ($request->getType() !== Request::TYPE_GET) {
|
if ($request->getType() !== Request::TYPE_GET) {
|
||||||
$curl = curl_init($url);
|
$curl = curl_init($url);
|
||||||
|
@ -194,5 +194,16 @@ class CurlService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $code
|
||||||
|
*
|
||||||
|
* @throws APIRequestException
|
||||||
|
*/
|
||||||
|
private function parseRequestResultCode404($code) {
|
||||||
|
if ($code === 404) {
|
||||||
|
throw new APIRequestException('404 Not Found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ class ServiceAccountsService {
|
||||||
$this->checkAccountUniqueness($serviceId, $userId, $accountName);
|
$this->checkAccountUniqueness($serviceId, $userId, $accountName);
|
||||||
|
|
||||||
$account->setAccount($accountName);
|
$account->setAccount($accountName);
|
||||||
|
$account->setAccountId($this->getInt('id', $info, 0));
|
||||||
$this->serviceAccountsRequest->create($account);
|
$this->serviceAccountsRequest->create($account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,8 +141,6 @@ class ServicesService {
|
||||||
$account = new ServiceAccount();
|
$account = new ServiceAccount();
|
||||||
$account->setService($service);
|
$account->setService($service);
|
||||||
|
|
||||||
$this->miscService->log('___' . $this->configService->getCloudAddress());
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client_name' => 'Social@' . $this->configService->getCloudAddress(),
|
'client_name' => 'Social@' . $this->configService->getCloudAddress(),
|
||||||
'redirect_uris' => $this->generateRedirectUrl($service->getId()),
|
'redirect_uris' => $this->generateRedirectUrl($service->getId()),
|
||||||
|
|
|
@ -81,6 +81,19 @@ class Request implements \JsonSerializable {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getParsedUrl(): string {
|
||||||
|
$url = $this->getUrl();
|
||||||
|
$ak = array_keys($this->getData());
|
||||||
|
foreach ($ak as $k) {
|
||||||
|
$url = str_replace(':' . $k, $this->data[$k], $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
|
|
Ładowanie…
Reference in New Issue