Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark comments as read #32775

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions apps/comments/src/services/ReadComments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @copyright 2023 Christopher Ng <chrng8@gmail.com>
*
* @author Christopher Ng <chrng8@gmail.com>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import client from './DavClient.js'

import type { Response } from 'webdav'

/**
* Mark comments older than the date timestamp as read
*
* @param commentsType the ressource type
* @param ressourceId the ressource ID
* @param date the date object
*/
export const markCommentsAsRead = (
commentsType: string,
ressourceId: number,
date: Date,
): Promise<Response> => {
const ressourcePath = ['', commentsType, ressourceId].join('/')
const readMarker = date.toUTCString()

return client.customRequest(ressourcePath, {
method: 'PROPPATCH',
data: `<?xml version="1.0"?>
<d:propertyupdate
xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns">
<d:set>
<d:prop>
<oc:readMarker>${readMarker}</oc:readMarker>
</d:prop>
</d:set>
</d:propertyupdate>`,
})
}
18 changes: 17 additions & 1 deletion apps/comments/src/views/Comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
-->

<template>
<div class="comments" :class="{ 'icon-loading': isFirstLoading }">
<div class="comments"
:class="{ 'icon-loading': isFirstLoading }"
v-observe-visibility="onVisibilityChange">
<!-- Editor -->
<Comment v-bind="editorData"
:auto-complete="autoComplete"
Expand Down Expand Up @@ -83,9 +85,11 @@
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
import VTooltip from 'v-tooltip'
import Vue from 'vue'
import VueObserveVisibility from 'vue-observe-visibility'

import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand All @@ -96,8 +100,10 @@ import AlertCircleOutlineIcon from 'vue-material-design-icons/AlertCircleOutline
import Comment from '../components/Comment.vue'
import { getComments, DEFAULT_LIMIT } from '../services/GetComments.ts'
import cancelableRequest from '../utils/cancelableRequest.js'
import { markCommentsAsRead } from '../services/ReadComments.ts'

Vue.use(VTooltip)
Vue.use(VueObserveVisibility)

export default {
name: 'Comments',
Expand Down Expand Up @@ -145,6 +151,16 @@ export default {
},

methods: {
async onVisibilityChange(isVisible) {
if (isVisible) {
try {
await markCommentsAsRead(this.commentsType, this.ressourceId, new Date())
} catch (e) {
showError(e.message || t('comments', 'Failed to mark comments as read'))
}
}
},

/**
* Update current ressourceId and fetch new data
*
Expand Down
4 changes: 2 additions & 2 deletions dist/comments-comments-app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/comments-comments-app.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

25 changes: 21 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"vue-localstorage": "^0.6.2",
"vue-material-design-icons": "^5.0.0",
"vue-multiselect": "^2.1.6",
"vue-observe-visibility": "^1.0.0",
"vue-router": "^3.6.5",
"vue-virtual-scroller": "^1.1.2",
"vuedraggable": "^2.24.3",
Expand Down