kopia lustrzana https://github.com/nextcloud/social
Implement frontend for ostatus popup
Signed-off-by: Julius Härtl <jus@bitgrid.net>pull/314/head
rodzic
910583e122
commit
5f0fa2cbc1
|
@ -42,7 +42,10 @@ use OCA\Social\Service\CurlService;
|
|||
use OCA\Social\Service\MiscService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
||||
|
||||
class OStatusController extends Controller {
|
||||
|
@ -64,6 +67,9 @@ class OStatusController extends Controller {
|
|||
/** @var MiscService */
|
||||
private $miscService;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userSession;
|
||||
|
||||
|
||||
/**
|
||||
* OStatusController constructor.
|
||||
|
@ -76,7 +82,7 @@ class OStatusController extends Controller {
|
|||
*/
|
||||
public function __construct(
|
||||
IRequest $request, CacheActorService $cacheActorService, AccountService $accountService,
|
||||
CurlService $curlService, MiscService $miscService
|
||||
CurlService $curlService, MiscService $miscService, IUserSession $userSession
|
||||
) {
|
||||
parent::__construct(Application::APP_NAME, $request);
|
||||
|
||||
|
@ -84,6 +90,7 @@ class OStatusController extends Controller {
|
|||
$this->accountService = $accountService;
|
||||
$this->curlService = $curlService;
|
||||
$this->miscService = $miscService;
|
||||
$this->userSession = $userSession;
|
||||
}
|
||||
|
||||
|
||||
|
@ -131,10 +138,24 @@ class OStatusController extends Controller {
|
|||
throw new RetrieveAccountFormatException();
|
||||
}
|
||||
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user === null) {
|
||||
return $this->fail('Failed to retrieve current user');
|
||||
}
|
||||
|
||||
$template = $this->get('template', $link, '');
|
||||
$url = str_replace('{uri}', $following->getAccount(), $template);
|
||||
|
||||
return $this->success(['url' => $url]);
|
||||
return new TemplateResponse('social', 'ostatus', [
|
||||
'serverData' => [
|
||||
'url' => $url,
|
||||
'account' => $account,
|
||||
'currentUser' => [
|
||||
'uid' => $user->getUID(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
]
|
||||
]
|
||||
], 'guest');
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import store from './store'
|
||||
import OStatus from './views/OStatus'
|
||||
|
||||
// eslint-disable-next-line
|
||||
__webpack_nonce__ = btoa(OC.requestToken)
|
||||
// eslint-disable-next-line
|
||||
__webpack_public_path__ = OC.linkTo('social', 'js/')
|
||||
|
||||
Vue.prototype.t = t
|
||||
Vue.prototype.n = n
|
||||
Vue.prototype.OC = OC
|
||||
Vue.prototype.OCA = OCA
|
||||
|
||||
/* eslint-disable-next-line no-new */
|
||||
new Vue({
|
||||
render: h => h(OStatus),
|
||||
store: store
|
||||
}).$mount('#vue-content')
|
|
@ -0,0 +1,78 @@
|
|||
<template>
|
||||
<div>
|
||||
<h2>{{ t('social', 'Follow on Nextcloud Social') }}</h2>
|
||||
<div v-if="accountInfo">
|
||||
<p>{{ t('social', 'Hello') }} <avatar :user="currentUser.uid" :size="16" />{{ currentUser.displayName }}</p>
|
||||
<p>{{ t('social', 'Please confirm that you want to follow this account:') }}</p>
|
||||
|
||||
<avatar :url="avatarUrl" :disable-tooltip="true" :size="128" />
|
||||
<h2>{{ displayName }}</h2>
|
||||
<form @submit.prevent="follow">
|
||||
<input type="text" :value="serverData.account">
|
||||
<input type="submit" class="primary" value="Follow">
|
||||
</form>
|
||||
</div>
|
||||
<div :class="{ 'icon-loading-dark': !accountInfo }" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
h2, p {
|
||||
color: var(--color-primary-text);
|
||||
}
|
||||
.avatardiv {
|
||||
vertical-align: -4px;
|
||||
margin-right: 3px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
import { Avatar } from 'nextcloud-vue'
|
||||
import currentuserMixin from './../mixins/currentUserMixin'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
Avatar
|
||||
},
|
||||
mixins: [currentuserMixin],
|
||||
computed: {
|
||||
account() {
|
||||
return this.serverData.account
|
||||
},
|
||||
avatarUrl() {
|
||||
return OC.generateUrl('/apps/social/api/v1/global/actor/avatar?id=' + this.accountInfo.id)
|
||||
},
|
||||
accountInfo: function() {
|
||||
return this.$store.getters.getAccount(this.serverData.account)
|
||||
},
|
||||
currentUser() {
|
||||
return window.oc_current_user
|
||||
},
|
||||
displayName() {
|
||||
if (typeof this.accountInfo.name !== 'undefined' && this.accountInfo.name !== '') {
|
||||
return this.accountInfo.name
|
||||
}
|
||||
return this.account
|
||||
}
|
||||
},
|
||||
beforeMount: function() {
|
||||
// importing server data into the store
|
||||
const serverDataElmt = document.getElementById('serverData')
|
||||
if (serverDataElmt !== null) {
|
||||
const serverData = JSON.parse(document.getElementById('serverData').dataset.server)
|
||||
window.oc_current_user = JSON.parse(JSON.stringify(serverData.currentUser))
|
||||
this.$store.commit('setServerData', serverData)
|
||||
this.$store.dispatch('fetchAccountInfo', this.serverData.account)
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
follow() {
|
||||
this.$store.dispatch('followAccount', { currentAccount: this.cloudId, accountToFollow: this.account }).then(() => {
|
||||
window.location = this.serverData.url
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
script('social', 'ostatus');
|
||||
style('social', 'style');
|
||||
?>
|
||||
<span id="serverData" data-server="<?php p(json_encode($_['serverData']));?>"></span>
|
||||
<div id="vue-content"></div>
|
|
@ -3,11 +3,14 @@ const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
|||
|
||||
|
||||
module.exports = {
|
||||
entry: path.join(__dirname, 'src', 'main.js'),
|
||||
entry: {
|
||||
social: path.join(__dirname, 'src', 'main.js'),
|
||||
ostatus: path.join(__dirname, 'src', 'ostatus.js'),
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, './js'),
|
||||
publicPath: '/js/',
|
||||
filename: 'social.js',
|
||||
filename: '[name].js',
|
||||
chunkFilename: '[name].[chunkhash].js'
|
||||
},
|
||||
module: {
|
||||
|
|
Ładowanie…
Reference in New Issue