2019-11-15 17:36:47 +00:00
|
|
|
<template>
|
2021-06-10 08:02:43 +00:00
|
|
|
<li
|
2022-11-22 11:47:38 +00:00
|
|
|
class="bg-white dark:bg-zinc-800 rounded p-2"
|
2021-06-10 08:02:43 +00:00
|
|
|
:class="{
|
|
|
|
reply: comment.inReplyToComment,
|
2022-11-22 11:47:38 +00:00
|
|
|
'bg-mbz-purple-50 dark:bg-mbz-purple-500': comment.isAnnouncement,
|
|
|
|
'bg-mbz-bluegreen-50 dark:bg-mbz-bluegreen-600': commentSelected,
|
2022-07-12 08:55:28 +00:00
|
|
|
'shadow-none': !rootComment,
|
2021-06-10 08:02:43 +00:00
|
|
|
}"
|
|
|
|
>
|
2022-10-25 17:01:26 +00:00
|
|
|
<article :id="commentId" dir="auto" class="mbz-comment">
|
2022-07-12 08:55:28 +00:00
|
|
|
<div>
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
<div class="flex items-center gap-1" v-if="actorComment">
|
|
|
|
<popover-actor-card
|
|
|
|
:actor="actorComment"
|
|
|
|
:inline="true"
|
|
|
|
v-if="!comment.deletedAt && actorComment.avatar"
|
|
|
|
>
|
|
|
|
<figure>
|
|
|
|
<img
|
|
|
|
class="rounded-xl"
|
|
|
|
:src="actorComment.avatar.url"
|
|
|
|
alt=""
|
|
|
|
width="24"
|
|
|
|
height="24"
|
|
|
|
/>
|
|
|
|
</figure>
|
|
|
|
</popover-actor-card>
|
|
|
|
<AccountCircle v-else />
|
|
|
|
<strong
|
|
|
|
v-if="!comment.deletedAt"
|
|
|
|
dir="auto"
|
|
|
|
:class="{ organizer: commentFromOrganizer }"
|
|
|
|
>{{ actorComment?.name }}</strong
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
|
2022-10-25 17:01:26 +00:00
|
|
|
<p v-else :href="commentURL">
|
2022-07-12 08:55:28 +00:00
|
|
|
<span>{{ t("[deleted]") }}</span>
|
2022-10-25 17:01:26 +00:00
|
|
|
</p>
|
2022-07-12 08:55:28 +00:00
|
|
|
<a :href="commentURL">
|
|
|
|
<small v-if="comment.updatedAt">{{
|
2021-06-01 16:08:03 +00:00
|
|
|
formatDistanceToNow(new Date(comment.updatedAt), {
|
2022-07-12 08:55:28 +00:00
|
|
|
locale: dateFnsLocale,
|
2021-06-01 16:08:03 +00:00
|
|
|
addSuffix: true,
|
|
|
|
})
|
|
|
|
}}</small>
|
|
|
|
</a>
|
2020-02-18 07:57:00 +00:00
|
|
|
</div>
|
2022-07-12 08:55:28 +00:00
|
|
|
<div
|
|
|
|
v-if="!comment.deletedAt"
|
|
|
|
v-html="comment.text"
|
|
|
|
dir="auto"
|
|
|
|
:lang="comment.language"
|
2022-11-29 07:19:12 +00:00
|
|
|
class="prose dark:prose-invert xl:prose-lg !max-w-full"
|
|
|
|
:class="{ 'text-black dark:text-white': comment.isAnnouncement }"
|
2022-07-12 08:55:28 +00:00
|
|
|
/>
|
|
|
|
<div v-else>{{ t("[This comment has been deleted]") }}</div>
|
2022-10-25 17:01:26 +00:00
|
|
|
<nav class="flex gap-1 mt-1" v-if="!comment.deletedAt">
|
|
|
|
<button
|
|
|
|
class="cursor-pointer flex hover:bg-zinc-300 dark:hover:bg-zinc-600 rounded p-1"
|
|
|
|
v-if="
|
|
|
|
currentActor?.id &&
|
|
|
|
event.options.commentModeration !== CommentModeration.CLOSED &&
|
|
|
|
!comment.deletedAt
|
|
|
|
"
|
|
|
|
@click="createReplyToComment()"
|
|
|
|
>
|
|
|
|
<Reply />
|
|
|
|
<span>{{ t("Reply") }}</span>
|
|
|
|
</button>
|
|
|
|
<o-dropdown aria-role="list">
|
|
|
|
<template #trigger>
|
|
|
|
<button
|
|
|
|
class="cursor-pointer flex hover:bg-zinc-300 dark:hover:bg-zinc-600 rounded p-1"
|
|
|
|
>
|
|
|
|
<DotsHorizontal />
|
|
|
|
<span class="sr-only">{{ t("More options") }}</span>
|
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
<o-dropdown-item
|
|
|
|
aria-role="listitem"
|
|
|
|
v-if="actorComment?.id === currentActor?.id"
|
|
|
|
>
|
|
|
|
<button class="flex items-center gap-1" @click="deleteComment">
|
|
|
|
<Delete :size="16" />
|
|
|
|
<span>{{ t("Delete") }}</span>
|
|
|
|
</button>
|
|
|
|
</o-dropdown-item>
|
|
|
|
<o-dropdown-item aria-role="listitem">
|
|
|
|
<button
|
|
|
|
@click="isReportModalActive = true"
|
|
|
|
class="flex items-center gap-1"
|
|
|
|
>
|
|
|
|
<Alert :size="16" />
|
|
|
|
<span>{{ t("Report") }}</span>
|
|
|
|
</button>
|
|
|
|
</o-dropdown-item>
|
|
|
|
</o-dropdown>
|
|
|
|
</nav>
|
2022-07-12 08:55:28 +00:00
|
|
|
<div class="" v-if="comment.totalReplies">
|
2022-10-25 17:01:26 +00:00
|
|
|
<button
|
2022-07-12 08:55:28 +00:00
|
|
|
v-if="!showReplies"
|
|
|
|
@click="showReplies = true"
|
2022-10-25 17:01:26 +00:00
|
|
|
class="flex cursor-pointer hover:bg-zinc-300 dark:hover:bg-zinc-600 rounded p-1"
|
2022-07-12 08:55:28 +00:00
|
|
|
>
|
|
|
|
<ChevronDown />
|
|
|
|
<span>{{
|
|
|
|
t(
|
|
|
|
"View a reply",
|
|
|
|
{
|
|
|
|
totalReplies: comment.totalReplies,
|
|
|
|
},
|
|
|
|
comment.totalReplies
|
|
|
|
)
|
|
|
|
}}</span>
|
2022-10-25 17:01:26 +00:00
|
|
|
</button>
|
|
|
|
<button
|
2022-07-12 08:55:28 +00:00
|
|
|
v-else-if="comment.totalReplies && showReplies"
|
|
|
|
@click="showReplies = false"
|
2022-10-25 17:01:26 +00:00
|
|
|
class="flex cursor-pointer hover:bg-zinc-300 dark:hover:bg-zinc-600 rounded p-1"
|
2022-07-12 08:55:28 +00:00
|
|
|
>
|
|
|
|
<ChevronUp />
|
|
|
|
<span>{{ t("Hide replies") }}</span>
|
2022-10-25 17:01:26 +00:00
|
|
|
</button>
|
2022-07-12 08:55:28 +00:00
|
|
|
</div>
|
2020-02-18 07:57:00 +00:00
|
|
|
</div>
|
|
|
|
</article>
|
2020-11-30 09:24:11 +00:00
|
|
|
<form
|
|
|
|
@submit.prevent="replyToComment"
|
2022-07-12 08:55:28 +00:00
|
|
|
v-if="currentActor?.id"
|
2020-11-30 09:24:11 +00:00
|
|
|
v-show="replyTo"
|
|
|
|
>
|
2022-07-12 08:55:28 +00:00
|
|
|
<article class="flex gap-2">
|
|
|
|
<figure v-if="currentActor?.avatar" class="mt-4">
|
|
|
|
<img
|
|
|
|
:src="currentActor?.avatar.url"
|
|
|
|
alt=""
|
|
|
|
width="48"
|
|
|
|
height="48"
|
|
|
|
class="rounded-md"
|
|
|
|
/>
|
2020-02-18 07:57:00 +00:00
|
|
|
</figure>
|
2022-07-12 08:55:28 +00:00
|
|
|
<AccountCircle v-else :size="48" />
|
|
|
|
<div class="flex-1">
|
|
|
|
<div class="flex gap-1 items-center">
|
|
|
|
<strong>{{ currentActor?.name }}</strong>
|
|
|
|
<small dir="ltr">@{{ currentActor?.preferredUsername }}</small>
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-2">
|
|
|
|
<editor
|
|
|
|
ref="commentEditor"
|
|
|
|
v-model="newComment.text"
|
|
|
|
mode="comment"
|
|
|
|
:current-actor="currentActor"
|
|
|
|
:aria-label="t('Comment body')"
|
|
|
|
class="flex-1"
|
2022-10-25 17:01:26 +00:00
|
|
|
@submit="replyToComment"
|
2022-10-31 10:43:18 +00:00
|
|
|
:placeholder="t('Write a new reply')"
|
2022-07-12 08:55:28 +00:00
|
|
|
/>
|
|
|
|
<o-button
|
|
|
|
:disabled="newComment.text.trim().length === 0"
|
|
|
|
native-type="submit"
|
|
|
|
variant="primary"
|
|
|
|
class="self-end"
|
|
|
|
>{{ t("Post a reply") }}</o-button
|
|
|
|
>
|
2020-02-18 07:57:00 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
</form>
|
2022-10-25 17:01:26 +00:00
|
|
|
<transition-group
|
|
|
|
name="comment-replies"
|
|
|
|
v-if="showReplies"
|
|
|
|
tag="ul"
|
|
|
|
class="flex flex-col gap-2"
|
|
|
|
>
|
|
|
|
<EventComment
|
|
|
|
v-for="reply in comment.replies"
|
|
|
|
:key="reply.id"
|
|
|
|
:comment="reply"
|
|
|
|
:event="event"
|
|
|
|
:currentActor="currentActor"
|
|
|
|
:rootComment="false"
|
|
|
|
@create-comment="emit('create-comment', $event)"
|
|
|
|
@delete-comment="emit('delete-comment', $event)"
|
|
|
|
@report-comment="emit('report-comment', $event)"
|
|
|
|
class="ml-2"
|
|
|
|
/>
|
|
|
|
</transition-group>
|
|
|
|
<o-modal
|
|
|
|
v-model:active="isReportModalActive"
|
|
|
|
has-modal-card
|
|
|
|
ref="reportModal"
|
|
|
|
:close-button-aria-label="t('Close')"
|
|
|
|
>
|
|
|
|
<ReportModal
|
|
|
|
:on-confirm="reportComment"
|
|
|
|
:title="t('Report this comment')"
|
|
|
|
:outside-domain="comment.actor?.domain"
|
|
|
|
/>
|
|
|
|
</o-modal>
|
2020-02-18 07:57:00 +00:00
|
|
|
</li>
|
2019-11-15 17:36:47 +00:00
|
|
|
</template>
|
2022-07-12 08:55:28 +00:00
|
|
|
<script lang="ts" setup>
|
2022-10-31 10:43:18 +00:00
|
|
|
import type EditorComponent from "@/components/TextEditor.vue";
|
2020-10-13 18:39:59 +00:00
|
|
|
import { formatDistanceToNow } from "date-fns";
|
2020-11-27 18:27:44 +00:00
|
|
|
import { CommentModeration } from "@/types/enums";
|
2020-02-18 07:57:00 +00:00
|
|
|
import { CommentModel, IComment } from "../../types/comment.model";
|
2022-07-12 08:55:28 +00:00
|
|
|
import { IPerson } from "../../types/actor";
|
2020-11-06 10:34:32 +00:00
|
|
|
import { IEvent } from "../../types/event.model";
|
2020-07-09 15:24:28 +00:00
|
|
|
import PopoverActorCard from "../Account/PopoverActorCard.vue";
|
2022-07-12 08:55:28 +00:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
defineAsyncComponent,
|
|
|
|
inject,
|
|
|
|
onMounted,
|
|
|
|
ref,
|
|
|
|
nextTick,
|
|
|
|
} from "vue";
|
|
|
|
import { useRoute } from "vue-router";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import AccountCircle from "vue-material-design-icons/AccountCircle.vue";
|
|
|
|
import Delete from "vue-material-design-icons/Delete.vue";
|
|
|
|
import Alert from "vue-material-design-icons/Alert.vue";
|
|
|
|
import ChevronUp from "vue-material-design-icons/ChevronUp.vue";
|
|
|
|
import ChevronDown from "vue-material-design-icons/ChevronDown.vue";
|
2022-10-25 17:01:26 +00:00
|
|
|
import DotsHorizontal from "vue-material-design-icons/DotsHorizontal.vue";
|
2022-07-12 08:55:28 +00:00
|
|
|
import Reply from "vue-material-design-icons/Reply.vue";
|
2022-07-12 08:55:28 +00:00
|
|
|
import type { Locale } from "date-fns";
|
2022-10-25 17:01:26 +00:00
|
|
|
import ReportModal from "@/components/Report/ReportModal.vue";
|
|
|
|
import { useCreateReport } from "@/composition/apollo/report";
|
|
|
|
import { Snackbar } from "@/plugins/snackbar";
|
|
|
|
import { useProgrammatic } from "@oruga-ui/oruga-next";
|
2022-07-12 08:55:28 +00:00
|
|
|
|
2022-08-26 14:08:58 +00:00
|
|
|
const Editor = defineAsyncComponent(
|
|
|
|
() => import("@/components/TextEditor.vue")
|
|
|
|
);
|
2022-07-12 08:55:28 +00:00
|
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
comment: IComment;
|
|
|
|
event: IEvent;
|
|
|
|
currentActor: IPerson;
|
|
|
|
rootComment?: boolean;
|
|
|
|
}>(),
|
|
|
|
{ rootComment: true }
|
|
|
|
);
|
|
|
|
|
2022-10-25 17:01:26 +00:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: "create-comment", comment: IComment): void;
|
|
|
|
(e: "delete-comment", comment: IComment): void;
|
|
|
|
(e: "report-comment", comment: IComment): void;
|
|
|
|
}>();
|
2022-07-12 08:55:28 +00:00
|
|
|
|
|
|
|
const commentEditor = ref<typeof EditorComponent | null>(null);
|
|
|
|
|
|
|
|
const newComment = ref<IComment>(new CommentModel());
|
|
|
|
const replyTo = ref(false);
|
|
|
|
const showReplies = ref(false);
|
|
|
|
const route = useRoute();
|
|
|
|
const { t } = useI18n({ useScope: "global" });
|
2022-10-25 17:01:26 +00:00
|
|
|
const isReportModalActive = ref(false);
|
2022-07-12 08:55:28 +00:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
if (route?.hash.includes(`#comment-${props.comment.uuid}`)) {
|
|
|
|
showReplies.value = true;
|
2021-05-17 09:36:28 +00:00
|
|
|
}
|
2022-07-12 08:55:28 +00:00
|
|
|
});
|
2021-05-17 09:36:28 +00:00
|
|
|
|
2022-07-12 08:55:28 +00:00
|
|
|
const createReplyToComment = async (): Promise<void> => {
|
|
|
|
if (replyTo.value) {
|
|
|
|
replyTo.value = false;
|
|
|
|
newComment.value = new CommentModel();
|
|
|
|
return;
|
2019-11-15 17:36:47 +00:00
|
|
|
}
|
2022-07-12 08:55:28 +00:00
|
|
|
replyTo.value = true;
|
|
|
|
if (props.comment.actor) {
|
|
|
|
commentEditor.value?.replyToComment(props.comment.actor);
|
|
|
|
await nextTick(); // wait for the mention to be injected
|
|
|
|
commentEditor.value?.focus();
|
2019-11-15 17:36:47 +00:00
|
|
|
}
|
2022-07-12 08:55:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const replyToComment = (): void => {
|
|
|
|
newComment.value.inReplyToComment = props.comment;
|
|
|
|
newComment.value.originComment = props.comment.originComment ?? props.comment;
|
|
|
|
newComment.value.actor = props.currentActor;
|
2022-08-26 14:08:58 +00:00
|
|
|
console.debug(newComment.value);
|
2022-07-12 08:55:28 +00:00
|
|
|
emit("create-comment", newComment.value);
|
|
|
|
newComment.value = new CommentModel();
|
|
|
|
replyTo.value = false;
|
|
|
|
showReplies.value = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const deleteComment = (): void => {
|
|
|
|
emit("delete-comment", props.comment);
|
|
|
|
showReplies.value = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const commentSelected = computed((): boolean => {
|
|
|
|
return `#${commentId.value}` === route?.hash;
|
|
|
|
});
|
|
|
|
|
|
|
|
const commentFromOrganizer = computed((): boolean => {
|
|
|
|
const organizerId =
|
|
|
|
props.event?.organizerActor?.id || props.event?.attributedTo?.id;
|
|
|
|
return organizerId !== undefined && props.comment?.actor?.id === organizerId;
|
|
|
|
});
|
|
|
|
|
|
|
|
const commentId = computed((): string => {
|
|
|
|
if (props.comment.originComment)
|
|
|
|
return `comment-${props.comment.originComment.uuid}-${props.comment.uuid}`;
|
|
|
|
return `comment-${props.comment.uuid}`;
|
|
|
|
});
|
|
|
|
|
|
|
|
const commentURL = computed((): string => {
|
|
|
|
if (!props.comment.local && props.comment.url) return props.comment.url;
|
|
|
|
return `#${commentId.value}`;
|
|
|
|
});
|
|
|
|
|
|
|
|
const reportModal = (): void => {
|
|
|
|
if (!props.comment.actor) return;
|
|
|
|
emit("report-comment", props.comment);
|
|
|
|
// this.$buefy.modal.open({
|
|
|
|
// component: ReportModal,
|
|
|
|
// props: {
|
|
|
|
// title: t("Report this comment"),
|
|
|
|
// comment: props.comment,
|
|
|
|
// onConfirm: reportComment,
|
|
|
|
// outsideDomain: props.comment.actor?.domain,
|
|
|
|
// },
|
|
|
|
// // https://github.com/buefy/buefy/pull/3589
|
|
|
|
// // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// // @ts-ignore
|
|
|
|
// closeButtonAriaLabel: this.t("Close"),
|
|
|
|
// });
|
|
|
|
};
|
|
|
|
|
2022-10-25 17:01:26 +00:00
|
|
|
const {
|
|
|
|
mutate: createReportMutation,
|
|
|
|
onError: onCreateReportError,
|
|
|
|
onDone: oneCreateReportDone,
|
|
|
|
} = useCreateReport();
|
2022-07-12 08:55:28 +00:00
|
|
|
|
2022-10-25 17:01:26 +00:00
|
|
|
const reportComment = async (
|
|
|
|
content: string,
|
|
|
|
forward: boolean
|
|
|
|
): Promise<void> => {
|
|
|
|
if (!props.comment.actor) return;
|
|
|
|
createReportMutation({
|
|
|
|
eventId: props.event.id,
|
|
|
|
reportedId: props.comment.actor?.id ?? "",
|
|
|
|
commentsIds: [props.comment.id ?? ""],
|
|
|
|
content,
|
|
|
|
forward,
|
|
|
|
});
|
|
|
|
};
|
2020-10-01 16:53:42 +00:00
|
|
|
|
2022-10-25 17:01:26 +00:00
|
|
|
const snackbar = inject<Snackbar>("snackbar");
|
|
|
|
const { oruga } = useProgrammatic();
|
|
|
|
|
|
|
|
onCreateReportError((e) => {
|
|
|
|
isReportModalActive.value = false;
|
|
|
|
if (e.message) {
|
|
|
|
snackbar?.open({
|
|
|
|
message: e.message,
|
|
|
|
variant: "danger",
|
|
|
|
position: "bottom",
|
|
|
|
});
|
2020-10-01 16:53:42 +00:00
|
|
|
}
|
2022-10-25 17:01:26 +00:00
|
|
|
});
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2022-10-25 17:01:26 +00:00
|
|
|
oneCreateReportDone(() => {
|
|
|
|
isReportModalActive.value = false;
|
|
|
|
oruga.notification.open({
|
|
|
|
message: t("Comment from {'@'}{username} reported", {
|
|
|
|
username: props.comment.actor?.preferredUsername,
|
|
|
|
}),
|
|
|
|
variant: "success",
|
|
|
|
position: "bottom-right",
|
|
|
|
duration: 5000,
|
|
|
|
});
|
|
|
|
});
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2022-10-25 17:01:26 +00:00
|
|
|
const actorComment = computed(() => props.comment.actor);
|
|
|
|
const dateFnsLocale = inject<Locale>("dateFnsLocale");
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
article.mbz-comment .mention.h-card {
|
|
|
|
@apply inline-block border border-zinc-600 dark:border-zinc-300 rounded py-0.5 px-1;
|
2020-02-18 07:57:00 +00:00
|
|
|
}
|
2019-11-15 17:36:47 +00:00
|
|
|
</style>
|