Skip to content

Commit

Permalink
fixup! feat(NcAvatar): implement custom javascript hook action for th…
Browse files Browse the repository at this point in the history
…e contacts menu
  • Loading branch information
st3iny committed Nov 25, 2024
1 parent 1c8c35e commit acca9fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/components/NcAvatar/NcAvatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export default {
isAvatarLoaded: false,
isMenuLoaded: false,
contactsMenuLoading: false,
contactsMenuData: {},
contactsMenuActions: [],
contactsMenuOpenState: false,
}
Expand Down Expand Up @@ -586,8 +587,7 @@ export default {
},
ncActionComponentHandlers: {
click: () => {
console.log('click handler')
callContactsMenuHook(item.hook)
callContactsMenuHook(item.hook, this.contactsMenuData)
},
},
}
Expand Down Expand Up @@ -692,6 +692,7 @@ export default {
try {
const user = encodeURIComponent(this.user)
const { data } = await axios.post(generateUrl('contactsmenu/findOne'), `shareType=0&shareWith=${user}`)
this.contactsMenuData = data
this.contactsMenuActions = data.topAction ? [data.topAction].concat(data.actions) : data.actions
} catch (e) {
this.contactsMenuOpenState = false
Expand Down
25 changes: 22 additions & 3 deletions src/functions/contactsMenu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

type ContactsMenuCallback = () => void
// Taken from \OC\Contacts\ContactsMenu\Entry::jsonSerialize
interface ContactsMenuEntry {
id: number|string|null,
fullName: string,
avatar: string|null,
topAction: object|null,
actions: object[],
lastMessage: '',
emailAddresses: string[],
profileTitle: string|null,
profileUrl: string|null,
status: string|null,
statusMessage: null|string,
statusMessageTimestamp: null|number,
statusIcon: null|string,
isUser: boolean,
uid: null|string,
}

type ContactsMenuCallback = (entry: ContactsMenuEntry) => void

interface ContactsMenuHookProps {
id: string;
Expand Down Expand Up @@ -32,8 +51,8 @@ const registerContactsMenuHook = (id: string, callback: ContactsMenuCallback) =>
}
}

const callContactsMenuHook = (id: string) => {
window._vue_contacts_menu_hooks[id]?.callback()
const callContactsMenuHook = (id: string, entry: ContactsMenuEntry) => {
window._vue_contacts_menu_hooks[id]?.callback(entry)
}

const hasContactsMenuHook = (id: string) => {
Expand Down

0 comments on commit acca9fd

Please sign in to comment.