Skip to content

Commit 94af306

Browse files
Pytalmarcelklehr
authored andcommitted
fix(comments): Mark comments as read
Signed-off-by: Christopher Ng <chrng8@gmail.com> Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
1 parent 822c872 commit 94af306

10 files changed

Lines changed: 97 additions & 16 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @copyright 2023 Christopher Ng <chrng8@gmail.com>
3+
*
4+
* @author Christopher Ng <chrng8@gmail.com>
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+
23+
import client from './DavClient.js'
24+
25+
import type { Response } from 'webdav'
26+
27+
/**
28+
* Mark comments older than the date timestamp as read
29+
*
30+
* @param commentsType the ressource type
31+
* @param ressourceId the ressource ID
32+
* @param date the date object
33+
*/
34+
export const markCommentsAsRead = (
35+
commentsType: string,
36+
ressourceId: number,
37+
date: Date,
38+
): Promise<Response> => {
39+
const ressourcePath = ['', commentsType, ressourceId].join('/')
40+
const readMarker = date.toUTCString()
41+
42+
return client.customRequest(ressourcePath, {
43+
method: 'PROPPATCH',
44+
data: `<?xml version="1.0"?>
45+
<d:propertyupdate
46+
xmlns:d="DAV:"
47+
xmlns:oc="http://owncloud.org/ns">
48+
<d:set>
49+
<d:prop>
50+
<oc:readMarker>${readMarker}</oc:readMarker>
51+
</d:prop>
52+
</d:set>
53+
</d:propertyupdate>`,
54+
})
55+
}

apps/comments/src/views/Comments.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
-->
2323

2424
<template>
25-
<div class="comments" :class="{ 'icon-loading': isFirstLoading }">
25+
<div class="comments"
26+
:class="{ 'icon-loading': isFirstLoading }"
27+
v-observe-visibility="onVisibilityChange">
2628
<!-- Editor -->
2729
<Comment v-bind="editorData"
2830
:auto-complete="autoComplete"
@@ -83,9 +85,11 @@
8385
import { generateOcsUrl } from '@nextcloud/router'
8486
import { getCurrentUser } from '@nextcloud/auth'
8587
import { loadState } from '@nextcloud/initial-state'
88+
import { showError } from '@nextcloud/dialogs'
8689
import axios from '@nextcloud/axios'
8790
import VTooltip from 'v-tooltip'
8891
import Vue from 'vue'
92+
import VueObserveVisibility from 'vue-observe-visibility'
8993
9094
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
9195
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
@@ -96,8 +100,10 @@ import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline
96100
import Comment from '../components/Comment.vue'
97101
import { getComments, DEFAULT_LIMIT } from '../services/GetComments.ts'
98102
import cancelableRequest from '../utils/cancelableRequest.js'
103+
import { markCommentsAsRead } from '../services/ReadComments.ts'
99104
100105
Vue.use(VTooltip)
106+
Vue.use(VueObserveVisibility)
101107
102108
export default {
103109
name: 'Comments',
@@ -145,6 +151,16 @@ export default {
145151
},
146152
147153
methods: {
154+
async onVisibilityChange(isVisible) {
155+
if (isVisible) {
156+
try {
157+
await markCommentsAsRead(this.commentsType, this.ressourceId, new Date())
158+
} catch (e) {
159+
showError(e.message || t('comments', 'Failed to mark comments as read'))
160+
}
161+
}
162+
},
163+
148164
/**
149165
* Update current ressourceId and fetch new data
150166
*

dist/comments-comments-app.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/comments-comments-app.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/core-common.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/core-common.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

dist/files-main.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

dist/files-main.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"vue-localstorage": "^0.6.2",
108108
"vue-material-design-icons": "^5.0.0",
109109
"vue-multiselect": "^2.1.6",
110+
"vue-observe-visibility": "^1.0.0",
110111
"vue-router": "^3.6.5",
111112
"vue-virtual-scroller": "^1.1.2",
112113
"vuedraggable": "^2.24.3",

0 commit comments

Comments
 (0)