Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2020-10-21 17:30:34 +0300
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2020-10-28 12:26:08 +0300
commit72aeb8ef05e3d2b1cf63c659648ad8659474903b (patch)
tree365cdd1744e1e2e14e83fafba970030675eca253 /apps/comments/src
parent3cb10bc66f004892d5bfc77fbb0f9a4634a7ff47 (diff)
Add mentions data
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/comments/src')
-rw-r--r--apps/comments/src/components/Comment.vue11
-rw-r--r--apps/comments/src/mixins/CommentMixin.js4
-rw-r--r--apps/comments/src/services/GetComments.js3
-rw-r--r--apps/comments/src/services/NewComment.js3
-rw-r--r--apps/comments/src/utils/fileUtils.js122
-rw-r--r--apps/comments/src/views/Comments.vue29
6 files changed, 35 insertions, 137 deletions
diff --git a/apps/comments/src/components/Comment.vue b/apps/comments/src/components/Comment.vue
index 8324305873c..a8a46ba031f 100644
--- a/apps/comments/src/components/Comment.vue
+++ b/apps/comments/src/components/Comment.vue
@@ -67,7 +67,8 @@
<!-- Message editor -->
<div class="comment__editor " v-if="editor || editing">
- <RichContenteditable v-model="localMessage"
+ <RichContenteditable ref="editor"
+ v-model="localMessage"
:auto-complete="autoComplete"
:contenteditable="!loading"
@submit="onSubmit" />
@@ -121,10 +122,6 @@ export default {
inheritAttrs: false,
props: {
- source: {
- type: Object,
- default: () => ({}),
- },
actorDisplayName: {
type: String,
required: true,
@@ -227,6 +224,10 @@ export default {
if (this.editor) {
this.onNewComment(this.localMessage.trim())
+ this.$nextTick(() => {
+ // Focus the editor again
+ this.$refs.editor.$el.focus()
+ })
return
}
this.onEditComment(this.localMessage.trim())
diff --git a/apps/comments/src/mixins/CommentMixin.js b/apps/comments/src/mixins/CommentMixin.js
index 03f5db0846f..7b6e7a9b0a0 100644
--- a/apps/comments/src/mixins/CommentMixin.js
+++ b/apps/comments/src/mixins/CommentMixin.js
@@ -32,8 +32,7 @@ export default {
default: null,
},
message: {
- // GenFileInfo can convert message as numbers if they doesn't contains text
- type: [String, Number],
+ type: String,
default: '',
},
ressourceId: {
@@ -103,6 +102,7 @@ export default {
const newComment = await NewComment(this.commentsType, this.ressourceId, message)
this.logger.debug('New comment posted', { commentsType: this.commentsType, ressourceId: this.ressourceId, newComment })
this.$emit('new', newComment)
+
// Clear old content
this.$emit('update:message', '')
this.localMessage = ''
diff --git a/apps/comments/src/services/GetComments.js b/apps/comments/src/services/GetComments.js
index 66bdbff4503..4d2c4d21425 100644
--- a/apps/comments/src/services/GetComments.js
+++ b/apps/comments/src/services/GetComments.js
@@ -23,7 +23,6 @@
import { parseXML, prepareFileFromProps } from 'webdav/dist/node/interface/dav'
import { processResponsePayload } from 'webdav/dist/node/response'
import client from './DavClient'
-import { genFileInfo } from '../utils/fileUtils'
export const DEFAULT_LIMIT = 20
/**
@@ -61,7 +60,7 @@ export default async function({ commentsType, ressourceId }, options = {}) {
.then(parseXML)
.then(xml => processMultistatus(xml, true))
.then(comments => processResponsePayload(response, comments, true))
- .then(response => response.data.map(genFileInfo))
+ .then(response => response.data)
}
// https://github.com/perry-mitchell/webdav-client/blob/9de2da4a2599e06bd86c2778145b7ade39fe0b3c/source/interface/directoryContents.js#L32
diff --git a/apps/comments/src/services/NewComment.js b/apps/comments/src/services/NewComment.js
index 96aee85e010..5bf200d1c8e 100644
--- a/apps/comments/src/services/NewComment.js
+++ b/apps/comments/src/services/NewComment.js
@@ -20,7 +20,6 @@
*
*/
-import { genFileInfo } from '../utils/fileUtils'
import { getCurrentUser } from '@nextcloud/auth'
import { getRootPath } from '../utils/davUtils'
import axios from '@nextcloud/axios'
@@ -56,5 +55,5 @@ export default async function(commentsType, ressourceId, message) {
details: true,
})
- return genFileInfo(comment)
+ return comment.data
}
diff --git a/apps/comments/src/utils/fileUtils.js b/apps/comments/src/utils/fileUtils.js
deleted file mode 100644
index 298732c8af0..00000000000
--- a/apps/comments/src/utils/fileUtils.js
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * @copyright Copyright (c) 2019 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * 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 camelcase from 'camelcase'
-import { isNumber } from './numberUtil'
-
-/**
- * Get an url encoded path
- *
- * @param {String} path the full path
- * @returns {string} url encoded file path
- */
-const encodeFilePath = function(path) {
- const pathSections = (path.startsWith('/') ? path : `/${path}`).split('/')
- let relativePath = ''
- pathSections.forEach((section) => {
- if (section !== '') {
- relativePath += '/' + encodeURIComponent(section)
- }
- })
- return relativePath
-}
-
-/**
- * Extract dir and name from file path
- *
- * @param {String} path the full path
- * @returns {String[]} [dirPath, fileName]
- */
-const extractFilePaths = function(path) {
- const pathSections = path.split('/')
- const fileName = pathSections[pathSections.length - 1]
- const dirPath = pathSections.slice(0, pathSections.length - 1).join('/')
- return [dirPath, fileName]
-}
-
-/**
- * Sorting comparison function
- *
- * @param {Object} fileInfo1 file 1 fileinfo
- * @param {Object} fileInfo2 file 2 fileinfo
- * @param {string} key key to sort with
- * @param {boolean} [asc=true] sort ascending?
- * @returns {number}
- */
-const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
-
- if (fileInfo1.isFavorite && !fileInfo2.isFavorite) {
- return -1
- } else if (!fileInfo1.isFavorite && fileInfo2.isFavorite) {
- return 1
- }
-
- // if this is a number, let's sort by integer
- if (isNumber(fileInfo1[key]) && isNumber(fileInfo2[key])) {
- return Number(fileInfo1[key]) - Number(fileInfo2[key])
- }
-
- // else we sort by string, so let's sort directories first
- if (fileInfo1.type === 'directory' && fileInfo2.type !== 'directory') {
- return -1
- } else if (fileInfo1.type !== 'directory' && fileInfo2.type === 'directory') {
- return 1
- }
-
- // finally sort by name
- return asc
- ? fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage())
- : -fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage())
-}
-
-/**
- * Generate a fileinfo object based on the full dav properties
- * It will flatten everything and put all keys to camelCase
- *
- * @param {Object} obj the object
- * @returns {Object}
- */
-const genFileInfo = function(obj) {
- const fileInfo = {}
-
- Object.keys(obj).forEach(key => {
- const data = obj[key]
-
- // flatten object if any
- if (!!data && typeof data === 'object' && !Array.isArray(data)) {
- Object.assign(fileInfo, genFileInfo(data))
- } else {
- // format key and add it to the fileInfo
- if (data === 'false') {
- fileInfo[camelcase(key)] = false
- } else if (data === 'true') {
- fileInfo[camelcase(key)] = true
- } else {
- fileInfo[camelcase(key)] = isNumber(data)
- ? Number(data)
- : data
- }
- }
- })
- return fileInfo
-}
-
-export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo }
diff --git a/apps/comments/src/views/Comments.vue b/apps/comments/src/views/Comments.vue
index b58f3359304..586a12ed8d6 100644
--- a/apps/comments/src/views/Comments.vue
+++ b/apps/comments/src/views/Comments.vue
@@ -38,11 +38,12 @@
<!-- Comments -->
<Comment v-for="comment in comments"
v-else
- :key="comment.id"
- v-bind="comment"
+ :key="comment.props.id"
+ v-bind="comment.props"
:auto-complete="autoComplete"
+ :message.sync="comment.props.message"
:ressource-id="ressourceId"
- :message.sync="comment.message"
+ :user-data="genMentionsData(comment.props.mentions)"
class="comments__list"
@delete="onDelete" />
@@ -149,6 +150,26 @@ export default {
},
/**
+ * Make sure we have all mentions as Array of objects
+ * @param {Array} mentions the mentions list
+ * @returns {Object[]}
+ */
+ genMentionsData(mentions) {
+ const list = Object.values(mentions).flat()
+ return list.reduce((mentions, mention) => {
+ mentions[mention.mentionId] = {
+ // TODO: support groups
+ icon: 'icon-user',
+ id: mention.mentionId,
+ label: mention.mentionDisplayName,
+ source: 'users',
+ primary: getCurrentUser().uid === mention.mentionId,
+ }
+ return mentions
+ }, {})
+ },
+
+ /**
* Get the existing shares infos
*/
async getComments() {
@@ -224,7 +245,7 @@ export default {
* @param {number} id the deleted comment
*/
onDelete(id) {
- const index = this.comments.findIndex(comment => comment.id === id)
+ const index = this.comments.findIndex(comment => comment.props.id === id)
if (index > -1) {
this.comments.splice(index, 1)
} else {