Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Jul 27, 2023
1 parent dd69534 commit c6d2526
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import NewMessage from './NewMessage/NewMessage.vue'
import { CONVERSATION } from '../constants.js'
import { EventBus } from '../services/EventBus.js'

Check warning on line 77 in src/components/ChatView.vue

View workflow job for this annotation

GitHub Actions / eslint

There should be at least one empty line between import groups
import axios from '@nextcloud/axios'

Check warning on line 78 in src/components/ChatView.vue

View workflow job for this annotation

GitHub Actions / eslint

`@nextcloud/axios` import should occur before import of `@nextcloud/vue/dist/Components/NcButton.js`

Check failure on line 78 in src/components/ChatView.vue

View workflow job for this annotation

GitHub Actions / eslint

'axios' is defined but never used
import { generateOcsUrl } from '@nextcloud/router'

Check warning on line 79 in src/components/ChatView.vue

View workflow job for this annotation

GitHub Actions / eslint

`@nextcloud/router` import should occur before import of `@nextcloud/vue/dist/Components/NcButton.js`

Check failure on line 79 in src/components/ChatView.vue

View workflow job for this annotation

GitHub Actions / eslint

'generateOcsUrl' is defined but never used
export default {
Expand Down
27 changes: 18 additions & 9 deletions src/components/ConversationSettings/ConversationSettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
<MatterbridgeSettings />
</NcAppSettingsSection>

<!-- Webhooks and bots settings -->
<NcAppSettingsSection v-if="true"
id="webhooks-bots"
:title="t('spreed', 'Webhooks & Bots')">
<WebhooksBotsSettings :token="token" />
</NcAppSettingsSection>

<!-- Destructive actions -->
<NcAppSettingsSection v-if="canLeaveConversation || canDeleteConversation"
id="dangerzone"
Expand Down Expand Up @@ -118,6 +125,7 @@ import LockingSettings from './LockingSettings.vue'
import MatterbridgeSettings from './Matterbridge/MatterbridgeSettings.vue'
import NotificationsSettings from './NotificationsSettings.vue'
import SipSettings from './SipSettings.vue'
import WebhooksBotsSettings from './WebhooksBotsSettings.vue'
import { PARTICIPANT, CONVERSATION } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
Expand All @@ -126,21 +134,22 @@ export default {
name: 'ConversationSettingsDialog',
components: {
NcAppSettingsDialog,
NcAppSettingsSection,
BasicInfo,
BreakoutRoomsSettings,
ConversationPermissionsSettings,
DangerZone,
ExpirationSettings,
LinkShareSettings,
LobbySettings,
ListableSettings,
LobbySettings,
LockingSettings,
SipSettings,
MatterbridgeSettings,
DangerZone,
NotificationsSettings,
NcAppSettingsDialog,
NcAppSettingsSection,
NcCheckboxRadioSwitch,
ConversationPermissionsSettings,
BreakoutRoomsSettings,
BasicInfo,
NotificationsSettings,
SipSettings,
WebhooksBotsSettings,
},
data() {
Expand Down
210 changes: 210 additions & 0 deletions src/components/ConversationSettings/WebhooksBotsSettings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<!--
- @copyright Copyright (c) 2022 Marco Ambrosini <[email protected]>
-
- @author Marco Ambrosini <[email protected]>
-
- @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/>.
-->

<template>
<div class="webhook-bots-settings">
<p class="webhook-bots-settings__hint">
{{ hintText }}
</p>

<ul v-if="bots?.length" class="webhook-bots-settings__list">
<NcListItem v-for="bot in bots"
:key="bot.id"
:title="bot.name"
:details="bot.state ? 'Enabled' : undefined"
class="webhook-bots-settings__item"
:class="{'webhook-bots-settings__item--disabled': !selfIsOwnerOrModerator }"
force-display-actions
@click.prevent="toggleBotState(bot)">
<template #icon>
<RobotIcon class="webhook-bots-settings__icon"
:class="{'webhook-bots-settings__icon--enabled': bot.state}"
:fill-color="bot.state ? '#fff' : undefined"
:size="32" />
</template>
<template #subtitle>
{{ bot.description ?? 'description is not provided' }}
</template>
<template #actions>
<NcActionButton @click.prevent="toggleBotState(bot)">
<template #icon>
<span v-if="isLoading[bot.id]" class="icon icon-loading" />
<StopIcon v-else-if="bot.state" :size="20" />
<PlayIcon v-else :size="20" />
</template>
{{ toggleButtonTitle(bot) }}
</NcActionButton>
</template>
</NcListItem>
</ul>
<template v-else>
<p> There are no bots available</p>
</template>
</div>
</template>
<script>
import Vue from 'vue'
import PlayIcon from 'vue-material-design-icons/Play.vue'
import RobotIcon from 'vue-material-design-icons/Robot.vue'
import StopIcon from 'vue-material-design-icons/Stop.vue'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcListItem from '@nextcloud/vue/dist/Components/NcListItem.js'
import { PARTICIPANT } from '../../constants.js'
export default {
name: 'WebhooksBotsSettings',
components: {
NcActionButton,
NcListItem,
PlayIcon,
RobotIcon,
StopIcon,
},
props: {
/**
* The conversation's token
*/
token: {
type: String,
required: true,
},
},
data() {
return {
bots: [],
isLoading: {},
}
},
computed: {
hintText() {
return t('spreed', 'Webhooks & Bots')
},
participantType() {
return this.$store.getters.conversation(this.token).participantType
},
selfIsOwnerOrModerator() {
return [PARTICIPANT.TYPE.OWNER, PARTICIPANT.TYPE.MODERATOR, PARTICIPANT.TYPE.GUEST_MODERATOR].includes(this.participantType)
},
},
mounted() {
axios.get(generateOcsUrl('/apps/spreed/api/v1/bot/{token}', { token: this.token })).then((r) => {
this.bots = [...r.data.ocs.data,
{ id: 122, name: 'Dummy bot 1 ', description: 'It does nothing', state: 0 },
{ id: 123, name: 'Dummy bot 2 ', description: 'It does nothing', state: 1 }]
this.bots.forEach(bot => {
this.isLoading[bot.id] = false
})
})
},
methods: {
toggleBotState(bot) {
if (!this.selfIsOwnerOrModerator) {
return
}
Vue.set(this.isLoading, bot.id, true)
if (bot.state === 1) {
// ? axios.delete(generateOcsUrl('/apps/spreed/api/v1/bot/{token}/{id}', { token: this.token, id: bot.id })).then((r) => {
setTimeout(() => {
this.bots.find(b => b.id === bot.id).state = 0
Vue.set(this.isLoading, bot.id, false)
}, 1000)
// })
} else {
// : axios.post(generateOcsUrl('/apps/spreed/api/v1/bot/{token}/{id}', { token: this.token, id: bot.id })).then((r) => {
setTimeout(() => {
this.bots.find(b => b.id === bot.id).state = 1
Vue.set(this.isLoading, bot.id, false)
}, 1000)
// })
}
},
toggleButtonTitle(bot) {
if (bot.state === 1) {
return this.selfIsOwnerOrModerator ? t('spreed', 'Disable') : t('spreed', 'Enabled')
} else {
return this.selfIsOwnerOrModerator ? t('spreed', 'Enable') : t('spreed', 'Disabled')
}
},
},
}
</script>
<style lang="scss" scoped>
.webhook-bots-settings {
&__hint{
margin-bottom: calc(var(--default-grid-baseline) * 2);
color: var(--color-text-lighter);
}
&__list {
}
&__item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 4px 0;
&:not(:last-child) {
border-bottom: 1px solid var(--color-background-darker);
}
}
&__icon {
width: 44px;
height: 44px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 44px;
background-color: var(--color-background-darker);
&--enabled {
background-color: var(--color-primary-element);
}
}
h4 {
font-weight: bold;
font-size: var(--default-font-size);
}
}
</style>

0 comments on commit c6d2526

Please sign in to comment.