Merge pull request #3030 from nextcloud/backport/3014
Proper error handling when fetching comments fails
This commit is contained in:
@@ -22,7 +22,9 @@
|
|||||||
.icon-activity {
|
.icon-activity {
|
||||||
@include icon-color('activity-dark', 'activity', $color-black);
|
@include icon-color('activity-dark', 'activity', $color-black);
|
||||||
}
|
}
|
||||||
|
.icon-comment--unread {
|
||||||
|
@include icon-color('comment', 'actions', $color-primary, 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
.avatardiv.circles {
|
.avatardiv.circles {
|
||||||
background: var(--color-primary);
|
background: var(--color-primary);
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class Card extends RelationalEntity {
|
|||||||
protected $notified = false;
|
protected $notified = false;
|
||||||
protected $deletedAt = 0;
|
protected $deletedAt = 0;
|
||||||
protected $commentsUnread = 0;
|
protected $commentsUnread = 0;
|
||||||
|
protected $commentsCount = 0;
|
||||||
|
|
||||||
protected $relatedStack = null;
|
protected $relatedStack = null;
|
||||||
protected $relatedBoard = null;
|
protected $relatedBoard = null;
|
||||||
@@ -75,6 +76,7 @@ class Card extends RelationalEntity {
|
|||||||
$this->addRelation('attachmentCount');
|
$this->addRelation('attachmentCount');
|
||||||
$this->addRelation('participants');
|
$this->addRelation('participants');
|
||||||
$this->addRelation('commentsUnread');
|
$this->addRelation('commentsUnread');
|
||||||
|
$this->addRelation('commentsCount');
|
||||||
$this->addResolvable('owner');
|
$this->addResolvable('owner');
|
||||||
|
|
||||||
$this->addRelation('relatedStack');
|
$this->addRelation('relatedStack');
|
||||||
|
|||||||
@@ -105,8 +105,10 @@ class CardService {
|
|||||||
$card->setAttachmentCount($this->attachmentService->count($cardId));
|
$card->setAttachmentCount($this->attachmentService->count($cardId));
|
||||||
$user = $this->userManager->get($this->currentUser);
|
$user = $this->userManager->get($this->currentUser);
|
||||||
$lastRead = $this->commentsManager->getReadMark('deckCard', (string)$card->getId(), $user);
|
$lastRead = $this->commentsManager->getReadMark('deckCard', (string)$card->getId(), $user);
|
||||||
$count = $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId(), $lastRead);
|
$countUnreadComments = $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId(), $lastRead);
|
||||||
$card->setCommentsUnread($count);
|
$countComments = $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId());
|
||||||
|
$card->setCommentsUnread($countUnreadComments);
|
||||||
|
$card->setCommentsCount($countComments);
|
||||||
|
|
||||||
$stack = $this->stackMapper->find($card->getStackId());
|
$stack = $this->stackMapper->find($card->getStackId());
|
||||||
$board = $this->boardService->find($stack->getBoardId());
|
$board = $this->boardService->find($stack->getBoardId());
|
||||||
|
|||||||
@@ -7,7 +7,11 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CommentItem v-if="replyTo" :comment="replyTo" :reply="true" />
|
<CommentItem v-if="replyTo"
|
||||||
|
:comment="replyTo"
|
||||||
|
:reply="true"
|
||||||
|
:preview="true"
|
||||||
|
@cancel="cancelReply" />
|
||||||
<CommentForm v-model="newComment" @submit="createComment" />
|
<CommentForm v-model="newComment" @submit="createComment" />
|
||||||
|
|
||||||
<ul v-if="getCommentsForCard(card.id).length > 0" id="commentsFeed">
|
<ul v-if="getCommentsForCard(card.id).length > 0" id="commentsFeed">
|
||||||
@@ -23,8 +27,8 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<div v-else-if="isLoading" class="icon icon-loading" />
|
<div v-else-if="isLoading" class="icon icon-loading" />
|
||||||
<div v-else class="emptycontent">
|
<div v-else class="emptycontent">
|
||||||
<div class="icon-comment" />
|
<div :class="{ 'icon-comment': !error, 'icon-error': error }" />
|
||||||
<p>{{ t('deck', 'No comments yet. Begin the discussion!') }}</p>
|
<p>{{ error || t('deck', 'No comments yet. Begin the discussion!') }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -36,6 +40,7 @@ import CommentItem from './CommentItem'
|
|||||||
import CommentForm from './CommentForm'
|
import CommentForm from './CommentForm'
|
||||||
import InfiniteLoading from 'vue-infinite-loading'
|
import InfiniteLoading from 'vue-infinite-loading'
|
||||||
import { getCurrentUser } from '@nextcloud/auth'
|
import { getCurrentUser } from '@nextcloud/auth'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CardSidebarTabComments',
|
name: 'CardSidebarTabComments',
|
||||||
components: {
|
components: {
|
||||||
@@ -60,6 +65,7 @@ export default {
|
|||||||
newComment: '',
|
newComment: '',
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
currentUser: getCurrentUser(),
|
currentUser: getCurrentUser(),
|
||||||
|
error: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -85,20 +91,35 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async infiniteHandler($state) {
|
async infiniteHandler($state) {
|
||||||
|
this.error = null
|
||||||
|
try {
|
||||||
await this.loadMore()
|
await this.loadMore()
|
||||||
if (this.hasMoreComments(this.card.id)) {
|
if (this.hasMoreComments(this.card.id)) {
|
||||||
$state.loaded()
|
$state.loaded()
|
||||||
} else {
|
} else {
|
||||||
$state.complete()
|
$state.complete()
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to fetch more comments during infinite loading', e)
|
||||||
|
this.error = t('deck', 'Failed to load comments')
|
||||||
|
$state.complete()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async loadComments() {
|
async loadComments() {
|
||||||
|
this.$store.dispatch('setReplyTo', null)
|
||||||
|
this.error = null
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
|
try {
|
||||||
await this.$store.dispatch('fetchComments', { cardId: this.card.id })
|
await this.$store.dispatch('fetchComments', { cardId: this.card.id })
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
if (this.card.commentsUnread > 0) {
|
if (this.card.commentsUnread > 0) {
|
||||||
await this.$store.dispatch('markCommentsAsRead', this.card.id)
|
await this.$store.dispatch('markCommentsAsRead', this.card.id)
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.isLoading = false
|
||||||
|
console.error('Failed to fetch more comments during infinite loading', e)
|
||||||
|
this.error = t('deck', 'Failed to load comments')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async createComment(content) {
|
async createComment(content) {
|
||||||
const commentObj = {
|
const commentObj = {
|
||||||
@@ -115,6 +136,9 @@ export default {
|
|||||||
await this.$store.dispatch('fetchMore', { cardId: this.card.id })
|
await this.$store.dispatch('fetchMore', { cardId: this.card.id })
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
},
|
},
|
||||||
|
cancelReply() {
|
||||||
|
this.$store.dispatch('setReplyTo', null)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<div ref="contentEditable"
|
<div ref="contentEditable"
|
||||||
|
class="comment-form__contenteditable"
|
||||||
contenteditable
|
contenteditable
|
||||||
@keydown.enter="handleKeydown"
|
@keydown.enter="handleKeydown"
|
||||||
@paste="onPaste"
|
@paste="onPaste"
|
||||||
@@ -175,6 +176,11 @@ export default {
|
|||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
@import '../../css/comments';
|
@import '../../css/comments';
|
||||||
|
|
||||||
|
.comment-form__contenteditable {
|
||||||
|
word-break: break-word;
|
||||||
|
border-radius: var(--border-radius-large)
|
||||||
|
}
|
||||||
|
|
||||||
.atwho-wrap {
|
.atwho-wrap {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
& > div[contenteditable] {
|
& > div[contenteditable] {
|
||||||
|
|||||||
@@ -1,11 +1,23 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="reply" class="reply">
|
<div v-if="reply" class="reply" :class="{ 'reply--preview': preview }">
|
||||||
<span class="reply--hint">{{ t('deck', 'In reply to') }} <UserBubble :user="comment.actorId" :display-name="comment.actorDisplayName" /></span>
|
<div class="reply--wrapper">
|
||||||
|
<div class="reply--header">
|
||||||
|
<div class="reply--hint">
|
||||||
|
{{ t('deck', 'In reply to') }}
|
||||||
|
<UserBubble :user="comment.actorId" :display-name="comment.actorDisplayName" />
|
||||||
|
</div>
|
||||||
|
<Actions v-if="preview" class="reply--cancel">
|
||||||
|
<ActionButton icon="icon-close" @click="$emit('cancel')">
|
||||||
|
{{ t('deck', 'Cancel reply') }}
|
||||||
|
</ActionButton>
|
||||||
|
</Actions>
|
||||||
|
</div>
|
||||||
<RichText class="comment--content"
|
<RichText class="comment--content"
|
||||||
:text="richText(comment)"
|
:text="richText(comment)"
|
||||||
:arguments="richArgs(comment)"
|
:arguments="richArgs(comment)"
|
||||||
:autolink="true" />
|
:autolink="true" />
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<li v-else class="comment">
|
<li v-else class="comment">
|
||||||
<template>
|
<template>
|
||||||
<div class="comment--header">
|
<div class="comment--header">
|
||||||
@@ -14,13 +26,19 @@
|
|||||||
{{ comment.actorDisplayName }}
|
{{ comment.actorDisplayName }}
|
||||||
</span>
|
</span>
|
||||||
<Actions v-show="!edit" :force-menu="true">
|
<Actions v-show="!edit" :force-menu="true">
|
||||||
<ActionButton icon="icon-reply" @click="replyTo()">
|
<ActionButton icon="icon-reply" :close-after-click="true" @click="replyTo()">
|
||||||
{{ t('deck', 'Reply') }}
|
{{ t('deck', 'Reply') }}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
<ActionButton v-if="canEdit" icon="icon-rename" @click="showUpdateForm()">
|
<ActionButton v-if="canEdit"
|
||||||
|
icon="icon-rename"
|
||||||
|
:close-after-click="true"
|
||||||
|
@click="showUpdateForm()">
|
||||||
{{ t('deck', 'Update') }}
|
{{ t('deck', 'Update') }}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
<ActionButton v-if="canEdit" icon="icon-delete" @click="deleteComment()">
|
<ActionButton v-if="canEdit"
|
||||||
|
icon="icon-delete"
|
||||||
|
:close-after-click="true"
|
||||||
|
@click="deleteComment()">
|
||||||
{{ t('deck', 'Delete') }}
|
{{ t('deck', 'Delete') }}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</Actions>
|
</Actions>
|
||||||
@@ -86,6 +104,10 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
preview: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -175,20 +197,41 @@ export default {
|
|||||||
@import '../../css/comments';
|
@import '../../css/comments';
|
||||||
|
|
||||||
.reply {
|
.reply {
|
||||||
border-left: 3px solid var(--color-primary-element);
|
margin: 0 0 0 44px;
|
||||||
padding-left: 5px;
|
|
||||||
margin-left: 2px;
|
&.reply--preview {
|
||||||
margin-bottom: 5px;
|
margin: 4px 0;
|
||||||
|
padding: 8px;
|
||||||
|
background-color: var(--color-background-hover);
|
||||||
|
border-radius: var(--border-radius-large);
|
||||||
|
|
||||||
|
.reply--wrapper {
|
||||||
|
margin: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reply--cancel {
|
||||||
|
margin-right: -12px;
|
||||||
|
margin-top: -12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.reply--wrapper {
|
||||||
|
border-left: 4px solid var(--color-border-dark);
|
||||||
|
padding-left: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
&::v-deep .rich-text--wrapper {
|
&::v-deep .rich-text--wrapper {
|
||||||
margin-top: -3px;
|
margin-top: -3px;
|
||||||
color: var(--color-text-light);
|
color: var(--color-text-lighter);
|
||||||
|
}
|
||||||
|
|
||||||
|
.reply--header {
|
||||||
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.reply--hint {
|
.reply--hint {
|
||||||
font-size: 0.9em;
|
|
||||||
color: var(--color-text-lighter);
|
color: var(--color-text-lighter);
|
||||||
vertical-align: top;
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.comment--content {
|
.comment--content {
|
||||||
|
|||||||
@@ -22,7 +22,13 @@
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="card" class="badges">
|
<div v-if="card" class="badges">
|
||||||
<div v-if="card.commentsUnread > 0" class="icon icon-comment" />
|
<div v-if="card.commentsCount > 0"
|
||||||
|
v-tooltip="commentsHint"
|
||||||
|
class="icon icon-comment"
|
||||||
|
:class="{ 'icon-comment--unread': card.commentsUnread > 0 }"
|
||||||
|
@click.stop="openComments">
|
||||||
|
{{ card.commentsCount }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="card.description && checkListCount > 0" class="card-tasks icon icon-checkmark">
|
<div v-if="card.description && checkListCount > 0" class="card-tasks icon icon-checkmark">
|
||||||
{{ checkListCheckedCount }}/{{ checkListCount }}
|
{{ checkListCheckedCount }}/{{ checkListCount }}
|
||||||
@@ -58,6 +64,21 @@ export default {
|
|||||||
checkListCheckedCount() {
|
checkListCheckedCount() {
|
||||||
return (this.card.description.match(/^\s*([*+-]|(\d\.))\s+\[\s*x\s*\](.*)$/gim) || []).length
|
return (this.card.description.match(/^\s*([*+-]|(\d\.))\s+\[\s*x\s*\](.*)$/gim) || []).length
|
||||||
},
|
},
|
||||||
|
commentsHint() {
|
||||||
|
if (this.card.commentsUnread > 0) {
|
||||||
|
return t('deck', '{count} comments, {unread} unread', {
|
||||||
|
count: this.card.commentsCount,
|
||||||
|
unread: this.card.commentsUnread
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
openComments() {
|
||||||
|
const boardId = this.card && this.card.boardId ? this.card.boardId : this.$route.params.id
|
||||||
|
this.$router.push({ name: 'card', params: { id: boardId, cardId: this.card.id, tabId: 'comments' } })
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -70,7 +91,7 @@ export default {
|
|||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
padding: 12px 18px;
|
padding: 10px 20px;
|
||||||
padding-right: 4px;
|
padding-right: 4px;
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
background-position: left;
|
background-position: left;
|
||||||
@@ -78,8 +99,8 @@ export default {
|
|||||||
span {
|
span {
|
||||||
margin-left: 18px;
|
margin-left: 18px;
|
||||||
}
|
}
|
||||||
&.icon-edit {
|
&.icon-comment--unread {
|
||||||
opacity: 0.5;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,4 +48,5 @@
|
|||||||
|
|
||||||
.comment--content {
|
.comment--content {
|
||||||
margin-left: 44px;
|
margin-left: 44px;
|
||||||
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ class CardTest extends TestCase {
|
|||||||
'assignedUsers' => null,
|
'assignedUsers' => null,
|
||||||
'deletedAt' => 0,
|
'deletedAt' => 0,
|
||||||
'commentsUnread' => 0,
|
'commentsUnread' => 0,
|
||||||
|
'commentsCount' => 0,
|
||||||
'lastEditor' => null,
|
'lastEditor' => null,
|
||||||
'ETag' => $card->getETag(),
|
'ETag' => $card->getETag(),
|
||||||
], $card->jsonSerialize());
|
], $card->jsonSerialize());
|
||||||
@@ -109,6 +110,7 @@ class CardTest extends TestCase {
|
|||||||
'assignedUsers' => null,
|
'assignedUsers' => null,
|
||||||
'deletedAt' => 0,
|
'deletedAt' => 0,
|
||||||
'commentsUnread' => 0,
|
'commentsUnread' => 0,
|
||||||
|
'commentsCount' => 0,
|
||||||
'lastEditor' => null,
|
'lastEditor' => null,
|
||||||
'ETag' => $card->getETag(),
|
'ETag' => $card->getETag(),
|
||||||
], $card->jsonSerialize());
|
], $card->jsonSerialize());
|
||||||
@@ -145,6 +147,7 @@ class CardTest extends TestCase {
|
|||||||
'assignedUsers' => ['user1'],
|
'assignedUsers' => ['user1'],
|
||||||
'deletedAt' => 0,
|
'deletedAt' => 0,
|
||||||
'commentsUnread' => 0,
|
'commentsUnread' => 0,
|
||||||
|
'commentsCount' => 0,
|
||||||
'lastEditor' => null,
|
'lastEditor' => null,
|
||||||
'ETag' => $card->getETag(),
|
'ETag' => $card->getETag(),
|
||||||
], $card->jsonSerialize());
|
], $card->jsonSerialize());
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ class CardServiceTest extends TestCase {
|
|||||||
$this->userManager->expects($this->once())
|
$this->userManager->expects($this->once())
|
||||||
->method('get')
|
->method('get')
|
||||||
->willReturn($user);
|
->willReturn($user);
|
||||||
$this->commentsManager->expects($this->once())
|
$this->commentsManager->expects($this->any())
|
||||||
->method('getNumberOfCommentsForObject')
|
->method('getNumberOfCommentsForObject')
|
||||||
->willReturn(0);
|
->willReturn(0);
|
||||||
$boardMock = $this->createMock(Board::class);
|
$boardMock = $this->createMock(Board::class);
|
||||||
|
|||||||
Reference in New Issue
Block a user