Skip to content

Commit

Permalink
Add talk integration
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed May 20, 2022
1 parent 9224eb5 commit c86943e
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
use OCA\Guests\GroupBackend;
use OCA\Guests\Hooks;
use OCA\Guests\Listener\ShareAutoAcceptListener;
use OCA\Guests\Listener\TalkIntegrationListener;
use OCA\Guests\Notifications\Notifier;
use OCA\Guests\RestrictionManager;
use OCA\Guests\UserBackend;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\IAppContainer;
use OCP\IServerContainer;
use OCP\IUser;
Expand All @@ -49,6 +51,7 @@ public function __construct(array $urlParams = []) {
public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScriptsListener::class);
$context->registerEventListener(ShareCreatedEvent::class, ShareAutoAcceptListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, TalkIntegrationListener::class);

// need to cheat here since there's no way to register these in IRegistrationContext
$container = $this->getContainer();
Expand Down
51 changes: 51 additions & 0 deletions lib/Listener/TalkIntegrationListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @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\Guests\Listener;

use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

class TalkIntegrationListener implements IEventListener {
public function handle(Event $event): void {
if (!$event instanceof BeforeTemplateRenderedEvent) {
return;
}
if (!$event->isLoggedIn() || $event->getResponse()->getTemplateName() !== 'index') {
return;
}

$params = $event->getResponse()->getParams();
if (!isset($params['app']) || $params['app'] !== 'spreed') {
return;
}

Util::addScript('guests', 'guests-talk');
}
}
37 changes: 37 additions & 0 deletions src/talk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { validate } from 'email-validator'
import Vue from 'vue'

import GuestForm from './views/GuestForm.vue'
import Nextcloud from './mixins/Nextcloud'

Vue.mixin(Nextcloud)

if (!OCA.Guests) {
/**
* @namespace OCA.Guests
*/
OCA.Guests = {}
}

// Init guests modal
const guestForm = new Vue(GuestForm)
const guestRoot = document.createElement('div')
guestRoot.setAttribute('id', 'guest-root')
document.body.appendChild(guestRoot)
guestForm.$mount('#guest-root')

// await page loading and init ShareSearch
window.addEventListener('DOMContentLoaded', () => {
if (!window.OCA?.Talk?.registerParticipantSearchAction) {
return
}

window.OCA.Talk.registerParticipantSearchAction({
icon: 'icon-guests',
label: t('guests', 'Invite guest'),
show: validate,
async callback(query) {
return guestForm.populate({ app: 'talk' }, query)
},
})
})
27 changes: 23 additions & 4 deletions src/views/GuestForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@

<!-- Footer -->
<div class="modal-footer">
<span v-if="error.button">{{ t('guests', 'An error occured, try again') }}</span>
<span v-if="error.button">{{ t('guests', 'An error occurred, try again') }}</span>
<Button type="primary"
native-type="submit"
:disabled="loading">
<template #icon>
<AccountPlus v-if="!loading" :size="20" />
<div v-else class="icon-loading-small" />
</template>
{{ t('guests', 'Invite user and create share') }}
{{ submitLabel }}
</Button>
</div>
</form>
Expand Down Expand Up @@ -89,6 +89,7 @@ export default {
},
data() {
return {
integrationApp: null,
fileInfo: null,
resolve: () => {},
reject: () => {},
Expand Down Expand Up @@ -125,6 +126,13 @@ export default {
: this.guest.email,
})
},
submitLabel() {
if (this.integrationApp === 'talk') {
return t('guests', 'Invite user to conversation')
}
return t('guests', 'Invite user and create share')
},
},
watch: {
Expand All @@ -146,7 +154,7 @@ export default {
},
methods: {
populate(fileInfo, shareWith) {
populate(metaData, shareWith) {
if (
shareWith.indexOf('@') !== -1
&& shareWith.lastIndexOf('.') > shareWith.indexOf('@')
Expand All @@ -156,7 +164,8 @@ export default {
this.guest.fullName = shareWith || ''
}
this.fileInfo = fileInfo
this.integrationApp = metaData?.app || 'files'
this.fileInfo = metaData
this.openModal()
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -197,6 +206,16 @@ export default {
language: this.guest.language,
groups: this.guest.groups,
})
if (this.integrationApp === 'talk') {
this.loading = false
this.resolve({
id: this.guest.email,
source: 'users',
})
this.closeModal()
return
}
await this.addGuestShare()
} catch ({ response }) {
const error = response && response.data && response.data.ocs && response.data.ocs.data
Expand Down
1 change: 1 addition & 0 deletions webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ const path = require('path')
const webpackConfig = require('@nextcloud/webpack-vue-config')

webpackConfig.entry.settings = path.join(__dirname, 'src', 'settings.js')
webpackConfig.entry.talk = path.join(__dirname, 'src', 'talk.js')

module.exports = webpackConfig

0 comments on commit c86943e

Please sign in to comment.