Skip to content

Commit

Permalink
feat:select existing talk roomfor convesations
Browse files Browse the repository at this point in the history
Signed-off-by: greta <[email protected]>
  • Loading branch information
GretaD committed Jan 8, 2025
1 parent 46e2840 commit d9749df
Show file tree
Hide file tree
Showing 4 changed files with 361 additions and 9 deletions.
252 changes: 252 additions & 0 deletions src/components/Editor/AddTalkModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
<template>
<NcModal size="normal" class="modal" :name="t('calendar', 'Select a Talk Room')">
<div class="modal-content">
<h2>{{ t('calendar', 'Add Talk conversation') }}</h2>
<div class="talk-room-list">
<NcEmptyContent v-if="loading"
icon="icon-loading"
class="modal__content__loading"
:description="t('calendar','Fetching Talk rooms...')" />
<NcEmptyContent v-else-if="talkConversations.length === 0"
:description="t('calendar','No Talk room available')" />
<ul v-else>
<li v-for="conversation in talkConversations"
:key="conversation.id"
:class="{ selected: selectedRoom && selectedRoom.id === conversation.id }"

Check warning on line 15 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L11-L15

Added lines #L11 - L15 were not covered by tests
class="talk-room-list__item"
@click="selectRoom(conversation)">
<NcAvatar :url="avatarUrl(conversation)"
:size="34"
:disable-tooltip="true" />
<span>{{ conversation.displayName }}</span>
</li>
</ul>
</div>
<div class="sticky-footer">
<NcButton class="talk_new-room" :disabled="creatingTalkRoom" @click="createTalkRoom">
<template #icon>
<IconAdd :size="20" />
</template>
{{ t('calendar', 'Create a new conversation') }}
</NcButton>
<NcButton type="primary"
class="talk_select-room"
:disabled="!selectedRoom"
@click="selectConversation(selectedRoom)">
{{ t('calendar', 'Select conversation') }}

Check warning on line 36 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L35-L36

Added lines #L35 - L36 were not covered by tests
</NcButton>
</div>
</div>
</NcModal>
</template>

<script>
import {
NcButton,
NcModal,
NcAvatar,
NcEmptyContent,

Check warning on line 48 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L47-L48

Added lines #L47 - L48 were not covered by tests
} from '@nextcloud/vue'
import axios from '@nextcloud/axios'
import { createTalkRoom, generateURLForToken } from '../../services/talkService.js'
import { showError, showSuccess } from '@nextcloud/dialogs'

Check warning on line 52 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L51-L52

Added lines #L51 - L52 were not covered by tests
import { generateOcsUrl } from '@nextcloud/router'
import IconAdd from 'vue-material-design-icons/Plus.vue'
import useCalendarObjectInstanceStore from '../../store/calendarObjectInstance.js'
import { mapStores } from 'pinia'
// Ref https://github.com/nextcloud/spreed/blob/main/docs/constants.md

Check warning on line 58 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L56-L58

Added lines #L56 - L58 were not covered by tests
const CONVERSATION_TYPE_GROUP = 2
const CONVERSATION_TYPE_PUBLIC = 3
const CONVERSATION_OBJECT_TYPE_VIDEO_VERIFICATION = 'share:password'
const PARTICIPANT_TYPE_OWNER = 1

Check warning on line 62 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L61-L62

Added lines #L61 - L62 were not covered by tests
const PARTICIPANT_TYPE_MODERATOR = 2

Check warning on line 64 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L64

Added line #L64 was not covered by tests
export default {
name: 'AddTalkModal',
components: {
NcButton,

Check warning on line 68 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L67-L68

Added lines #L67 - L68 were not covered by tests
NcModal,
IconAdd,
NcAvatar,
NcEmptyContent,
},
props: {

Check warning on line 74 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L70-L74

Added lines #L70 - L74 were not covered by tests
calendarObjectInstance: {
type: Object,
required: true,

Check warning on line 77 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L76-L77

Added lines #L76 - L77 were not covered by tests
},
conversations: {
type: Array,

Check warning on line 80 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L80

Added line #L80 was not covered by tests
required: true,
},
},
data() {
return {
talkConversations: [],
selectedConversation: null,

Check warning on line 87 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L84-L87

Added lines #L84 - L87 were not covered by tests
creatingTalkRoom: false,
selectedRoom: false,

Check warning on line 89 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L89

Added line #L89 was not covered by tests
loading: true,
}
},
computed: {
...mapStores(useCalendarObjectInstanceStore, ['calendarObjectInstance']),

Check warning on line 94 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L93-L94

Added lines #L93 - L94 were not covered by tests
},
async mounted() {

Check warning on line 96 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L96

Added line #L96 was not covered by tests
await this.fetchTalkConversations()
},
methods: {

Check warning on line 99 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L98-L99

Added lines #L98 - L99 were not covered by tests
avatarUrl(conversation) {
return generateOcsUrl('apps/spreed/api/v1/room/{token}/avatar', {

Check warning on line 101 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L101

Added line #L101 was not covered by tests
token: conversation.token,
})
},
async fetchTalkConversations() {
try {
const response = await axios.get(generateOcsUrl('apps/spreed/api/v4/room'))
this.talkConversations = response.data.ocs.data.filter(conversation =>

Check warning on line 108 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L104-L108

Added lines #L104 - L108 were not covered by tests
(conversation.participantType === PARTICIPANT_TYPE_OWNER
|| conversation.participantType === PARTICIPANT_TYPE_MODERATOR)

Check warning on line 110 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L110

Added line #L110 was not covered by tests
&& (conversation.type === CONVERSATION_TYPE_GROUP
|| (conversation.type === CONVERSATION_TYPE_PUBLIC
&& conversation.objectType !== CONVERSATION_OBJECT_TYPE_VIDEO_VERIFICATION)),
)
} catch (error) {

Check warning on line 115 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L113-L115

Added lines #L113 - L115 were not covered by tests
console.error('Error fetching Talk conversations:', error)
showError(this.$t('calendar', 'Error fetching Talk conversations.'))
} finally {

Check warning on line 118 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L117-L118

Added lines #L117 - L118 were not covered by tests
this.loading = false
}
},
selectRoom(conversation) {

Check warning on line 122 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L121-L122

Added lines #L121 - L122 were not covered by tests
this.selectedRoom = conversation
},

Check warning on line 124 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L124

Added line #L124 was not covered by tests
async selectConversation(conversation) {
console.debug('Selected conversation:', conversation)
try {

Check warning on line 128 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L127-L128

Added lines #L127 - L128 were not covered by tests
const url = generateURLForToken(conversation.token)
console.debug('Conversation URL:', url)
if (!url) {
showError(this.$t('calendar', 'Conversation does not have a valid URL.'))
return
}

Check warning on line 136 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L133-L136

Added lines #L133 - L136 were not covered by tests
if ((this.calendarObjectInstance.location ?? '').trim() === '') {
this.calendarObjectInstanceStore.changeLocation({
calendarObjectInstance: this.calendarObjectInstance,
location: url,
})
console.debug('Applied URL to location:', url)
showSuccess(this.$t('calendar', 'Successfully added Talk room link to location.'))
} else {
const NEW_LINE = '\r\n'
const updatedDescription = this.calendarObjectInstance.description
? this.calendarObjectInstance.description + NEW_LINE + NEW_LINE + url
: url
this.calendarObjectInstanceStore.changeDescription({
calendarObjectInstance: this.calendarObjectInstance,

Check warning on line 151 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L151

Added line #L151 was not covered by tests
description: updatedDescription,
})
console.debug('Applied URL to description:', url)
showSuccess(this.$t('calendar', 'Successfully added Talk room link to description.'))
}
this.selectedConversation = conversation
} catch (error) {

Check warning on line 159 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L159

Added line #L159 was not covered by tests
console.error('Error applying conversation to event:', error)
showError(this.$t('calendar', 'Failed to apply Talk room.'))
} finally {
this.closeModal()
}

Check warning on line 164 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L164

Added line #L164 was not covered by tests
},
async createTalkRoom() {

Check warning on line 167 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L166-L167

Added lines #L166 - L167 were not covered by tests
const NEW_LINE = '\r\n'
try {
this.creatingTalkRoom = true
const url = await createTalkRoom(
this.calendarObjectInstance.title,
this.calendarObjectInstance.description,
)

Check warning on line 175 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L175

Added line #L175 was not covered by tests
if (!url) {
throw new Error('No URL returned from createTalkRoom')
}

Check warning on line 179 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L178-L179

Added lines #L178 - L179 were not covered by tests
if ((this.calendarObjectInstance.location ?? '').trim() === '') {
this.$emit('update-location', url)
showSuccess(this.$t('calendar', 'Successfully added Talk room link to location.'))
} else {
const newDescription = this.calendarObjectInstance.description
? this.calendarObjectInstance.description + NEW_LINE + NEW_LINE + url + NEW_LINE
: url
this.$emit('update-description', newDescription)
showSuccess(this.$t('calendar', 'Successfully added Talk room link to description.'))
}
} catch (error) {
console.error('Error creating Talk room:', error)
showError(this.$t('calendar', 'Error creating Talk room.'))
} finally {
this.creatingTalkRoom = false
}
},
closeModal() {
this.$emit('close')
},
},
}
</script>
<style lang="scss" scoped>
.talk-room-list {
flex: 1;
overflow-y: auto;
padding: 10px;
font-weight: 600;
&__item {
display: flex;
gap: 5px;
align-items: center;
padding: 16px;
&:hover {

Check warning on line 217 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L216-L217

Added lines #L216 - L217 were not covered by tests
background-color: var(--color-background-hover);
border-radius: var(--border-radius-large);
}
&.selected {
background-color: var(--color-primary-element);
border-radius: var(--border-radius-large);
color: white;
}
}
}
.sticky-footer {
position: sticky;
bottom: 0;
padding: 16px;
text-align: right;
display: flex;
}
.talk_new-room {
margin-right: auto;
}

Check warning on line 239 in src/components/Editor/AddTalkModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/Editor/AddTalkModal.vue#L238-L239

Added lines #L238 - L239 were not covered by tests
.talk_select-room {
margin-left: auto;
}
h2 {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
height: 30px;
}
</style>
2 changes: 1 addition & 1 deletion src/services/talkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function doesContainTalkLink(text) {
* @param {string} token The token to the call room
* @return {string}
*/
function generateURLForToken(token = '') {
export function generateURLForToken(token = '') {

Check warning on line 129 in src/services/talkService.js

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L129

Added line #L129 was not covered by tests
return window.location.protocol + '//' + window.location.host + generateUrl('/call/' + token)
}

Expand Down
2 changes: 1 addition & 1 deletion src/store/calendarObjectInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ export default defineStore('calendarObjectInstance', {
* @param {string=} data.language Preferred language of the attendee
* @param {string=} data.timezoneId Preferred timezone of the attendee
* @param {object=} data.organizer Principal of the organizer to be set if not present
* @param {string|array} data.member Group membership(s)
* @param {string | Array} data.member Group membership(s)
*/
addAttendee({
calendarObjectInstance,
Expand Down
Loading

0 comments on commit d9749df

Please sign in to comment.