Skip to content

Commit

Permalink
fix(comments): Mark comments as read
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
  • Loading branch information
Pytal authored and nextcloud-command committed May 3, 2023
1 parent c995428 commit e115125
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 16 deletions.
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>`,
})
}
20 changes: 19 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 @@ -84,8 +86,11 @@ import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import { emit } from '@nextcloud/event-bus'
import { showError } from '@nextcloud/dialogs'
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 +101,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 +152,17 @@ export default {
},

methods: {
async onVisibilityChange(isVisible) {
if (isVisible) {
try {
await markCommentsAsRead(this.commentsType, this.ressourceId, new Date())
emit('comments:comments:read', { ressourceId: this.ressourceId })
} 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.

23 changes: 17 additions & 6 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 @@ -108,6 +108,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

0 comments on commit e115125

Please sign in to comment.