Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(talk): Make event attendees Talk room participants #5380

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion src/services/talkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@
import { translate as t } from '@nextcloud/l10n'
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import { getCurrentUser } from '@nextcloud/auth'
import logger from '../utils/logger.js'
import { removeMailtoPrefix } from '../utils/attendee.js'

/**
* Creates a new public talk room
*
* @param {?string} eventTitle Title of the event
* @param {?string} eventDescription Description of the event
* @param {?string[]} attendees Attendees of the event
*
* @return {Promise<string>}
*/
export async function createTalkRoom(eventTitle = null, eventDescription = null) {
export async function createTalkRoom(eventTitle = null, eventDescription = null, attendees = []) {

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L41

Added line #L41 was not covered by tests
const apiVersion = loadState('calendar', 'talk_api_version')
try {
const response = await HTTPClient.post(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room', {
Expand All @@ -57,6 +61,66 @@
}
}

/**
*
* @param eventComponent
*/
export async function updateTalkParticipants(eventComponent) {
const apiVersion = loadState('calendar', 'talk_api_version')
const url = eventComponent.getConferenceList()[0]?.uri ?? eventComponent.location
if (!url || !url.startsWith(window.location.protocol + '//' + window.location.host)) {
logger.debug('Event\'s conference/location is from another host', url)
return

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L68-L73

Added lines #L68 - L73 were not covered by tests
}
const token = url.match(/\/call\/([a-z0-9]*)$/)[1]
if (!token) {
logger.debug('URL ' + url + ' contains no call token')
return

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L75-L78

Added lines #L75 - L78 were not covered by tests
}
try {
const participantsResponse = await HTTPClient.get(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room/' + token + '/participants')

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L80-L81

Added lines #L80 - L81 were not covered by tests
// Ignore if the actor isn't owner of the conversation
if (!participantsResponse.data.ocs.data.some(participant => participant.actorId === getCurrentUser().uid && participant.participantType <= 2)) {
logger.debug('Current user is not a moderator or owner', { currentUser: getCurrentUser().uid, conversation: participantsResponse.data.ocs.data })
return

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L83-L85

Added lines #L83 - L85 were not covered by tests
}

for (const attendee of eventComponent.getAttendeeIterator()) {
logger.debug('Processing attendee', { attendee })
if (['GROUP', 'RESOURCE', 'ROOM'].includes(attendee.userType)) {
continue

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L88-L91

Added lines #L88 - L91 were not covered by tests
}

let participantId = removeMailtoPrefix(attendee.email)
let attendeeSource = 'emails'
try {

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L94-L96

Added lines #L94 - L96 were not covered by tests
// Map attendee email to Nextcloud user uid
const searchResult = await HTTPClient.get(generateOcsUrl('core/autocomplete/', 2) + 'get?search=' + encodeURIComponent(participantId) + '&itemType=&itemId=%20&shareTypes[]=0&limit=2')

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L98

Added line #L98 was not covered by tests
// Only map if there is exactly one result. Use email if there are none or more results.
if (searchResult.data.ocs.data.length === 1) {
participantId = searchResult.data.ocs.data[0].id
attendeeSource = 'users'
} else {
logger.debug('Attendee ' + participantId + ' is not a Nextcloud user')

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L100-L104

Added lines #L100 - L104 were not covered by tests
}
} catch (error) {
logger.info('Could not find user data for attendee ' + participantId, { error })

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L107

Added line #L107 was not covered by tests
}

if (attendeeSource === 'users' && participantId === getCurrentUser().uid) {
logger.debug('Skipping organizer')
continue

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L110-L112

Added lines #L110 - L112 were not covered by tests
}
await HTTPClient.post(generateOcsUrl('apps/spreed/api/' + apiVersion + '/', 2) + 'room/' + token + '/participants', {

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L114

Added line #L114 was not covered by tests
newParticipant: participantId,
source: attendeeSource,
})
}
} catch (error) {
logger.warn('Could not update Talk room attendees', { error })

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

View check run for this annotation

Codecov / codecov/patch

src/services/talkService.js#L120

Added line #L120 was not covered by tests
}
}

/**
* Checks whether the description already contains a talk link
*
Expand Down
2 changes: 2 additions & 0 deletions src/store/calendarObjectInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import settings from './settings.js'
import { getRFCProperties } from '../models/rfcProps.js'
import { generateUrl } from '@nextcloud/router'
import { updateTalkParticipants } from '../services/talkService.js'

const state = {
isNew: null,
Expand Down Expand Up @@ -1640,6 +1641,7 @@
const calendarObject = state.calendarObject

updateEmailAlarms(eventComponent)
updateTalkParticipants(eventComponent)

Check warning on line 1644 in src/store/calendarObjectInstance.js

View check run for this annotation

Codecov / codecov/patch

src/store/calendarObjectInstance.js#L1644

Added line #L1644 was not covered by tests

if (eventComponent.isDirty()) {
const isForkedItem = eventComponent.primaryItem !== null
Expand Down
Loading