Merge pull request #2576 from nextcloud/enh/user_mentions

This commit is contained in:
Julius Härtl 2022-11-17 16:35:44 +01:00 коммит произвёл GitHub
Родитель 5f46481365 851a5f173e
Коммит 9816bc0a15
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -1,5 +1,5 @@
import { emit } from '@nextcloud/event-bus'
import { getRootUrl, imagePath } from '@nextcloud/router'
import { generateOcsUrl, getRootUrl, imagePath } from '@nextcloud/router'
import { getRequestToken } from '@nextcloud/auth'
import Config from './services/config.tsx'
import { setGuestName, shouldAskForGuestName } from './helpers/guestName.js'
@ -146,6 +146,7 @@ const documentsMain = {
renderComplete: false, // false till page is rendered with all required data about the document(s)
$deferredVersionRestoreAck: null,
wopiClientFeatures: null,
users: [],
// generates docKey for given fileId
_generateDocKey(wopiFileId) {
@ -465,6 +466,14 @@ const documentsMain = {
console.debug('[document] Unhandled `Clicked_Button` post message', parsed)
}
break
case 'Views_List':
documentsMain.users = []
parsed.args.forEach((view) => {
if (!view.UserId.startsWith('Guest-')) {
documentsMain.users.push({ id: view.UserId, label: view.UserName })
}
})
break
case 'Get_Views_Resp':
if (documentsMain.openingLocally) {
documentsMain.UI.removeViews(parsed.args)
@ -475,6 +484,9 @@ const documentsMain = {
})
}
break
case 'UI_Mention':
documentsMain.sendUserList(parsed.args.text)
break
default:
console.debug('[document] Unhandled post message', parsed)
}
@ -593,6 +605,25 @@ const documentsMain = {
}
},
async sendUserList(search) {
let users = documentsMain.users
if (Config.get('userId') !== null) {
try {
const result = await axios.get(generateOcsUrl('core/autocomplete/get'), {
params: { search },
})
users = result.data.ocs.data
} catch (e) { }
}
const list = users.map((user) => {
const profile = window.location.protocol + '//' + getNextcloudUrl() + '/index.php/u/' + user.id
return { username: user.label, profile }
})
PostMessages.sendWOPIPostMessage('loolframe', 'Action_Mention', { list })
},
onStartup() {
// Does anything indicate that we need to autostart a session?
const fileId = (getSearchParam('fileId') || '').replace(/^\W*/, '')