Skip to content

Commit 8c571dd

Browse files
Merge pull request #45848 from nextcloud/fix/comment-deleting-with-activities
Fix/comment deleting with activities installed
2 parents f94b0c3 + bd7c29c commit 8c571dd

20 files changed

+115
-18
lines changed

apps/comments/src/comments-activity-tab.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import Vue from 'vue'
77
import logger from './logger.js'
88
import { getComments } from './services/GetComments.js'
99

10+
import { PiniaVuePlugin, createPinia } from 'pinia'
11+
12+
Vue.use(PiniaVuePlugin)
13+
1014
let ActivityTabPluginView
1115
let ActivityTabPluginInstance
1216

@@ -16,16 +20,19 @@ let ActivityTabPluginInstance
1620
export function registerCommentsPlugins() {
1721
window.OCA.Activity.registerSidebarAction({
1822
mount: async (el, { context, fileInfo, reload }) => {
23+
const pinia = createPinia()
24+
1925
if (!ActivityTabPluginView) {
2026
const { default: ActivityCommmentAction } = await import('./views/ActivityCommentAction.vue')
21-
ActivityTabPluginView = Vue.extend(ActivityCommmentAction)
27+
ActivityTabPluginView = ActivityCommmentAction
2228
}
2329
ActivityTabPluginInstance = new ActivityTabPluginView({
2430
parent: context,
2531
propsData: {
2632
reloadCallback: reload,
2733
resourceId: fileInfo.id,
2834
},
35+
pinia,
2936
})
3037
ActivityTabPluginInstance.$mount(el)
3138
logger.info('Comments plugin mounted in Activity sidebar action', { fileInfo })
@@ -42,7 +49,7 @@ export function registerCommentsPlugins() {
4249
const { data: comments } = await getComments({ resourceType: 'files', resourceId: fileInfo.id }, { limit, offset })
4350
logger.debug('Loaded comments', { fileInfo, comments })
4451
const { default: CommentView } = await import('./views/ActivityCommentEntry.vue')
45-
const CommentsViewObject = Vue.extend(CommentView)
52+
const CommentsViewObject = CommentView
4653

4754
return comments.map((comment) => ({
4855
timestamp: moment(comment.props.creationDateTime).toDate().getTime(),

apps/comments/src/components/Comment.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-->
55
<template>
66
<component :is="tag"
7-
v-show="!deleted"
7+
v-show="!deleted && !isLimbo"
88
:class="{'comment--loading': loading}"
99
class="comment">
1010
<!-- Comment header toolbar -->
@@ -121,6 +121,8 @@ import IconDelete from 'vue-material-design-icons/Delete.vue'
121121
import IconEdit from 'vue-material-design-icons/Pencil.vue'
122122
123123
import CommentMixin from '../mixins/CommentMixin.js'
124+
import { mapStores } from 'pinia'
125+
import { useDeletedCommentLimbo } from '../store/deletedCommentLimbo.js'
124126
125127
// Dynamic loading
126128
const NcRichContenteditable = () => import('@nextcloud/vue/dist/Components/NcRichContenteditable.js')
@@ -193,6 +195,7 @@ export default {
193195
},
194196
195197
computed: {
198+
...mapStores(useDeletedCommentLimbo),
196199
197200
/**
198201
* Is the current user the author of this comment
@@ -225,6 +228,10 @@ export default {
225228
timestamp() {
226229
return Date.parse(this.creationDateTime)
227230
},
231+
232+
isLimbo() {
233+
return this.deletedCommentLimboStore.checkForId(this.id)
234+
},
228235
},
229236
230237
watch: {

apps/comments/src/mixins/CommentMixin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { showError, showUndo, TOAST_UNDO_TIMEOUT } from '@nextcloud/dialogs'
77
import NewComment from '../services/NewComment.js'
88
import DeleteComment from '../services/DeleteComment.js'
99
import EditComment from '../services/EditComment.js'
10+
import { mapStores } from 'pinia'
11+
import { useDeletedCommentLimbo } from '../store/deletedCommentLimbo.js'
1012
import logger from '../logger.js'
1113

1214
export default {
@@ -37,6 +39,10 @@ export default {
3739
}
3840
},
3941

42+
computed: {
43+
...mapStores(useDeletedCommentLimbo),
44+
},
45+
4046
methods: {
4147
// EDITION
4248
onEdit() {
@@ -64,11 +70,14 @@ export default {
6470

6571
// DELETION
6672
onDeleteWithUndo() {
73+
this.$emit('delete')
6774
this.deleted = true
75+
this.deletedCommentLimboStore.addId(this.id)
6876
const timeOutDelete = setTimeout(this.onDelete, TOAST_UNDO_TIMEOUT)
6977
showUndo(t('comments', 'Comment deleted'), () => {
7078
clearTimeout(timeOutDelete)
7179
this.deleted = false
80+
this.deletedCommentLimboStore.removeId(this.id)
7281
})
7382
},
7483
async onDelete() {
@@ -80,6 +89,7 @@ export default {
8089
showError(t('comments', 'An error occurred while trying to delete the comment'))
8190
console.error(error)
8291
this.deleted = false
92+
this.deletedCommentLimboStore.removeId(this.id)
8393
}
8494
},
8595

apps/comments/src/services/CommentsInstance.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
77
import { getRequestToken } from '@nextcloud/auth'
88
import Vue from 'vue'
9+
import { PiniaVuePlugin, createPinia } from 'pinia'
910
import CommentsApp from '../views/Comments.vue'
1011
import logger from '../logger.js'
1112

13+
Vue.use(PiniaVuePlugin)
1214
// eslint-disable-next-line camelcase
1315
__webpack_nonce__ = btoa(getRequestToken())
1416

@@ -34,13 +36,16 @@ export default class CommentInstance {
3436
* @param {object} options the vue options (propsData, parent, el...)
3537
*/
3638
constructor(resourceType = 'files', options = {}) {
39+
const pinia = createPinia()
40+
3741
// Merge options and set `resourceType` property
3842
options = {
3943
...options,
4044
propsData: {
4145
...(options.propsData ?? {}),
4246
resourceType,
4347
},
48+
pinia,
4449
}
4550
// Init Comments component
4651
const View = Vue.extend(CommentsApp)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { defineStore } from 'pinia'
7+
8+
export const useDeletedCommentLimbo = defineStore('deletedCommentLimbo', {
9+
state: () => ({
10+
idsInLimbo: [],
11+
}),
12+
actions: {
13+
addId(id) {
14+
this.idsInLimbo.push(id)
15+
},
16+
17+
removeId(id) {
18+
const index = this.idsInLimbo.indexOf(id)
19+
if (index > -1) {
20+
this.idsInLimbo.splice(index, 1)
21+
}
22+
},
23+
24+
checkForId(id) {
25+
this.idsInLimbo.includes(id)
26+
},
27+
},
28+
})

dist/3920-3920.js.license

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
4141
SPDX-FileCopyrightText: Irakli Gozalishvili <[email protected]> (http://jeditoolkit.com)
4242
SPDX-FileCopyrightText: Hypercontext
4343
SPDX-FileCopyrightText: Guillaume Chau <[email protected]>
44+
SPDX-FileCopyrightText: Guillaume Chau
4445
SPDX-FileCopyrightText: GitHub Inc.
4546
SPDX-FileCopyrightText: Feross Aboukhadijeh
4647
SPDX-FileCopyrightText: Evan You
4748
SPDX-FileCopyrightText: Eugene Sharygin <[email protected]>
4849
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
50+
SPDX-FileCopyrightText: Eduardo San Martin Morote
4951
SPDX-FileCopyrightText: Dylan Piercey <[email protected]>
5052
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
5153
SPDX-FileCopyrightText: David Clark
@@ -96,6 +98,9 @@ This file is generated from multiple sources. Included packages:
9698
- @nextcloud/vue
9799
- version: 8.14.0
98100
- license: AGPL-3.0-or-later
101+
- @vue/devtools-api
102+
- version: 6.6.1
103+
- license: MIT
99104
- @vueuse/components
100105
- version: 10.11.0
101106
- license: MIT
@@ -279,6 +284,9 @@ This file is generated from multiple sources. Included packages:
279284
- path
280285
- version: 0.12.7
281286
- license: MIT
287+
- pinia
288+
- version: 2.1.7
289+
- license: MIT
282290
- possible-typed-array-names
283291
- version: 1.0.0
284292
- license: MIT

dist/7462-7462.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/7462-7462.js.license

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
4141
SPDX-FileCopyrightText: Irakli Gozalishvili <[email protected]> (http://jeditoolkit.com)
4242
SPDX-FileCopyrightText: Hypercontext
4343
SPDX-FileCopyrightText: Guillaume Chau <[email protected]>
44+
SPDX-FileCopyrightText: Guillaume Chau
4445
SPDX-FileCopyrightText: GitHub Inc.
4546
SPDX-FileCopyrightText: Feross Aboukhadijeh
4647
SPDX-FileCopyrightText: Evan You
4748
SPDX-FileCopyrightText: Eugene Sharygin <[email protected]>
4849
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
50+
SPDX-FileCopyrightText: Eduardo San Martin Morote
4951
SPDX-FileCopyrightText: Dylan Piercey <[email protected]>
5052
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
5153
SPDX-FileCopyrightText: David Clark
@@ -96,6 +98,9 @@ This file is generated from multiple sources. Included packages:
9698
- @nextcloud/vue
9799
- version: 8.14.0
98100
- license: AGPL-3.0-or-later
101+
- @vue/devtools-api
102+
- version: 6.6.1
103+
- license: MIT
99104
- @vueuse/components
100105
- version: 10.11.0
101106
- license: MIT
@@ -279,6 +284,9 @@ This file is generated from multiple sources. Included packages:
279284
- path
280285
- version: 0.12.7
281286
- license: MIT
287+
- pinia
288+
- version: 2.1.7
289+
- license: MIT
282290
- possible-typed-array-names
283291
- version: 1.0.0
284292
- license: MIT

dist/7462-7462.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/8057-8057.js.license

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ SPDX-FileCopyrightText: Jacob Clevenger<https://github.com/wheatjs>
4141
SPDX-FileCopyrightText: Irakli Gozalishvili <[email protected]> (http://jeditoolkit.com)
4242
SPDX-FileCopyrightText: Hypercontext
4343
SPDX-FileCopyrightText: Guillaume Chau <[email protected]>
44+
SPDX-FileCopyrightText: Guillaume Chau
4445
SPDX-FileCopyrightText: GitHub Inc.
4546
SPDX-FileCopyrightText: Feross Aboukhadijeh
4647
SPDX-FileCopyrightText: Evan You
4748
SPDX-FileCopyrightText: Eugene Sharygin <[email protected]>
4849
SPDX-FileCopyrightText: Eric Norris (https://github.com/ericnorris)
50+
SPDX-FileCopyrightText: Eduardo San Martin Morote
4951
SPDX-FileCopyrightText: Dylan Piercey <[email protected]>
5052
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <[email protected]> (https://cure53.de/)
5153
SPDX-FileCopyrightText: David Clark
@@ -96,6 +98,9 @@ This file is generated from multiple sources. Included packages:
9698
- @nextcloud/vue
9799
- version: 8.14.0
98100
- license: AGPL-3.0-or-later
101+
- @vue/devtools-api
102+
- version: 6.6.1
103+
- license: MIT
99104
- @vueuse/components
100105
- version: 10.11.0
101106
- license: MIT
@@ -279,6 +284,9 @@ This file is generated from multiple sources. Included packages:
279284
- path
280285
- version: 0.12.7
281286
- license: MIT
287+
- pinia
288+
- version: 2.1.7
289+
- license: MIT
282290
- possible-typed-array-names
283291
- version: 1.0.0
284292
- license: MIT

0 commit comments

Comments
 (0)