1
0

comments-activity-tab.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
  3. *
  4. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import moment from '@nextcloud/moment'
  23. import Vue from 'vue'
  24. import logger from './logger.js'
  25. import { getComments } from './services/GetComments.js'
  26. let ActivityTabPluginView
  27. let ActivityTabPluginInstance
  28. /**
  29. * Register the comments plugins for the Activity sidebar
  30. */
  31. export function registerCommentsPlugins() {
  32. window.OCA.Activity.registerSidebarAction({
  33. mount: async (el, { context, fileInfo, reload }) => {
  34. if (!ActivityTabPluginView) {
  35. const { default: ActivityCommmentAction } = await import('./views/ActivityCommentAction.vue')
  36. ActivityTabPluginView = Vue.extend(ActivityCommmentAction)
  37. }
  38. ActivityTabPluginInstance = new ActivityTabPluginView({
  39. parent: context,
  40. propsData: {
  41. reloadCallback: reload,
  42. resourceId: fileInfo.id,
  43. },
  44. })
  45. ActivityTabPluginInstance.$mount(el)
  46. logger.info('Comments plugin mounted in Activity sidebar action', { fileInfo })
  47. },
  48. unmount: () => {
  49. // destroy previous instance if available
  50. if (ActivityTabPluginInstance) {
  51. ActivityTabPluginInstance.$destroy()
  52. }
  53. },
  54. })
  55. window.OCA.Activity.registerSidebarEntries(async ({ fileInfo, limit, offset }) => {
  56. const { data: comments } = await getComments({ resourceType: 'files', resourceId: fileInfo.id }, { limit, offset })
  57. logger.debug('Loaded comments', { fileInfo, comments })
  58. const { default: CommentView } = await import('./views/ActivityCommentEntry.vue')
  59. const CommentsViewObject = Vue.extend(CommentView)
  60. return comments.map((comment) => ({
  61. timestamp: moment(comment.props.creationDateTime).toDate().getTime(),
  62. mount(element, { context, reload }) {
  63. this._CommentsViewInstance = new CommentsViewObject({
  64. parent: context,
  65. propsData: {
  66. comment,
  67. resourceId: fileInfo.id,
  68. reloadCallback: reload,
  69. },
  70. })
  71. this._CommentsViewInstance.$mount(element)
  72. },
  73. unmount() {
  74. this._CommentsViewInstance.$destroy()
  75. },
  76. }))
  77. })
  78. window.OCA.Activity.registerSidebarFilter((activity) => activity.type !== 'comments')
  79. logger.info('Comments plugin registered for Activity sidebar action')
  80. }