Add support for PDF file captions

This commit is contained in:
N-Pex 2024-10-17 11:33:46 +02:00
parent 5e1223fc01
commit 6f05d14877
6 changed files with 43 additions and 11 deletions

View file

@ -69,6 +69,8 @@
margin-top: 24px; margin-top: 24px;
.message { .message {
color: black !important; color: black !important;
display: flex;
flex-direction: column;
} }
} }
.bubble { .bubble {
@ -172,6 +174,7 @@
.swipeable-thumbnails-view { .swipeable-thumbnails-view {
margin-left: -15px; margin-left: -15px;
margin-right: -15px; margin-right: -15px;
order: 2;
.thumbnail-item.file-item { .thumbnail-item.file-item {
margin: 15px; margin: 15px;
width: auto; width: auto;

View file

@ -292,6 +292,8 @@
</v-card-text> </v-card-text>
</template> </template>
<v-divider></v-divider> <v-divider></v-divider>
<v-textarea v-if="showAttachmentCaptionInput" v-model="attachmentCaption" ref="attachmentCaption" color="black" background-color="transparent"
solo full-width auto-grow rows="1" no-resize hide-details :placeholder="$t('file_mode.add_a_message')"></v-textarea>
<v-card-actions> <v-card-actions>
<v-spacer> <v-spacer>
<div v-if="currentSendError">{{ currentSendError }}</div> <div v-if="currentSendError">{{ currentSendError }}</div>
@ -299,7 +301,7 @@
<v-btn color="primary" text @click="cancelSendAttachment" id="btn-attachment-cancel" :disabled="sendingStatus != sendStatuses.SENDING && sendingStatus != sendStatuses.INITIAL"> <v-btn color="primary" text @click="cancelSendAttachment" id="btn-attachment-cancel" :disabled="sendingStatus != sendStatuses.SENDING && sendingStatus != sendStatuses.INITIAL">
{{ $t("menu.cancel") }} {{ $t("menu.cancel") }}
</v-btn> </v-btn>
<v-btn id="btn-attachment-send" color="primary" text @click="sendAttachment(undefined)" <v-btn id="btn-attachment-send" color="primary" text @click="sendAttachment(attachmentCaption)"
v-if="currentSendShowSendButton" :disabled="currentSendShowSendButton && sendingStatus != sendStatuses.INITIAL">{{ $t("menu.send") }}</v-btn> v-if="currentSendShowSendButton" :disabled="currentSendShowSendButton && sendingStatus != sendStatuses.INITIAL">{{ $t("menu.send") }}</v-btn>
</v-card-actions> </v-card-actions>
</template> </template>
@ -465,6 +467,7 @@ export default {
currentSendShowSendButton: true, currentSendShowSendButton: true,
currentSendError: null, currentSendError: null,
currentSendErrorExceededFile: null, currentSendErrorExceededFile: null,
attachmentCaption: undefined,
showEmojiPicker: false, showEmojiPicker: false,
selectedEvent: null, selectedEvent: null,
editedEvent: null, editedEvent: null,
@ -593,6 +596,12 @@ export default {
isCurrentFileInputsAnArray() { isCurrentFileInputsAnArray() {
return Array.isArray(this.currentFileInputs) return Array.isArray(this.currentFileInputs)
}, },
showAttachmentCaptionInput() {
// IFF we are sending one PDF, add option to set caption.
const imageFiles = this.imageFiles || [];
const otherFiles = this.nonImageFiles || [];
return imageFiles.length == 0 && otherFiles.length == 1 && (otherFiles[0].type === "application/pdf" || (otherFiles[0].name || "").endsWith(".pdf"));
},
currentFileInputsDialog: { currentFileInputsDialog: {
get() { get() {
return this.isCurrentFileInputsAnArray return this.isCurrentFileInputsAnArray
@ -1547,6 +1556,7 @@ export default {
const promise = this.sendAttachments(text, this.currentFileInputs); const promise = this.sendAttachments(text, this.currentFileInputs);
promise.then(() => { promise.then(() => {
this.currentFileInputs = null; this.currentFileInputs = null;
this.attachmentCaption = undefined;
this.sendingStatus = this.sendStatuses.INITIAL; this.sendingStatus = this.sendStatuses.INITIAL;
}) })
.catch((err) => { .catch((err) => {
@ -1565,6 +1575,7 @@ export default {
this.$refs.attachment.value = null; this.$refs.attachment.value = null;
this.cancelSendAttachments(); this.cancelSendAttachments();
this.currentFileInputs = null; this.currentFileInputs = null;
this.attachmentCaption = undefined;
this.currentSendError = null; this.currentSendError = null;
this.currentSendErrorExceededFile = null; this.currentSendErrorExceededFile = null;
this.sendingStatus = this.sendStatuses.INITIAL; this.sendingStatus = this.sendStatuses.INITIAL;

View file

@ -1,5 +1,5 @@
<template> <template>
<message-incoming v-bind="{ ...$props, ...$attrs }" v-on="$listeners" v-if="items.length > 1 || event.isRedacted()"> <message-incoming v-bind="{ ...$props, ...$attrs }" v-on="$listeners" v-if="items.length > 1 || event.isRedacted() || room.displayType == ROOM_TYPE_CHANNEL">
<div class="bubble"> <div class="bubble">
<div class="original-message" v-if="inReplyToText"> <div class="original-message" v-if="inReplyToText">
<div class="original-message-sender">{{ inReplyToSender }}</div> <div class="original-message-sender">{{ inReplyToSender }}</div>
@ -10,7 +10,7 @@
</div> </div>
<div class="message"> <div class="message">
<SwipeableThumbnailsView :items="items" v-if="!event.isRedacted() && room.displayType == ROOM_TYPE_CHANNEL" /> <SwipeableThumbnailsView :items="items" v-if="!event.isRedacted() && room.displayType == ROOM_TYPE_CHANNEL" v-on="$listeners" />
<v-container v-else-if="!event.isRedacted()" fluid class="imageCollection"> <v-container v-else-if="!event.isRedacted()" fluid class="imageCollection">
<v-row wrap> <v-row wrap>
<v-col v-for="({ size, item }) in layoutedItems()" :key="item.event.getId()" :cols="size"> <v-col v-for="({ size, item }) in layoutedItems()" :key="item.event.getId()" :cols="size">
@ -22,7 +22,7 @@
<v-icon :color="this.senderIsAdminOrModerator(this.event) ? 'white' : ''" size="small">block</v-icon> <v-icon :color="this.senderIsAdminOrModerator(this.event) ? 'white' : ''" size="small">block</v-icon>
{{ redactedBySomeoneElse(event) ? $t('message.incoming_message_deleted_text') : $t('message.outgoing_message_deleted_text')}} {{ redactedBySomeoneElse(event) ? $t('message.incoming_message_deleted_text') : $t('message.outgoing_message_deleted_text')}}
</i> </i>
<span v-html="linkify($sanitize(messageText))" v-else /> <span v-html="linkify($sanitize(messageText))" v-else-if="messageText" />
<span class="edit-marker" v-if="event.replacingEventId() && !event.isRedacted()"> <span class="edit-marker" v-if="event.replacingEventId() && !event.isRedacted()">
{{ $t('message.edited') }} {{ $t('message.edited') }}
</span> </span>

View file

@ -1,5 +1,5 @@
<template> <template>
<message-outgoing v-bind="{ ...$props, ...$attrs }" v-on="$listeners" v-if="items.length > 1 || event.isRedacted()"> <message-outgoing v-bind="{ ...$props, ...$attrs }" v-on="$listeners" v-if="items.length > 1 || event.isRedacted() || room.displayType == ROOM_TYPE_CHANNEL">
<div class="bubble"> <div class="bubble">
<div class="original-message" v-if="inReplyToText"> <div class="original-message" v-if="inReplyToText">
<div class="original-message-sender">{{ inReplyToSender }}</div> <div class="original-message-sender">{{ inReplyToSender }}</div>
@ -11,7 +11,7 @@
<div class="message"> <div class="message">
<SwipeableThumbnailsView :items="items" v-if="!event.isRedacted() && room.displayType == ROOM_TYPE_CHANNEL" /> <SwipeableThumbnailsView :items="items" v-if="!event.isRedacted() && room.displayType == ROOM_TYPE_CHANNEL" v-on="$listeners" />
<v-container v-else-if="!event.isRedacted()" fluid class="imageCollection"> <v-container v-else-if="!event.isRedacted()" fluid class="imageCollection">
<v-row wrap> <v-row wrap>
<v-col v-for="({ size, item }) in layoutedItems()" :key="item.event.getId()" :cols="size"> <v-col v-for="({ size, item }) in layoutedItems()" :key="item.event.getId()" :cols="size">
@ -23,7 +23,7 @@
<v-icon size="small">block</v-icon> <v-icon size="small">block</v-icon>
{{ redactedBySomeoneElse(event) ? $t('message.incoming_message_deleted_text') : $t('message.outgoing_message_deleted_text')}} {{ redactedBySomeoneElse(event) ? $t('message.incoming_message_deleted_text') : $t('message.outgoing_message_deleted_text')}}
</i> </i>
<span v-html="linkify($sanitize(messageText))" v-else /> <span v-html="linkify($sanitize(messageText))" v-else-if="messageText" />
<span class="edit-marker" v-if="event.replacingEventId() && !event.isRedacted()"> <span class="edit-marker" v-if="event.replacingEventId() && !event.isRedacted()">
{{ $t('message.edited') }} {{ $t('message.edited') }}
</span> </span>

View file

@ -1,13 +1,13 @@
<template> <template>
<div class="swipeable-thumbnails-view"> <div class="swipeable-thumbnails-view">
<v-responsive :aspect-ratio="16 / 9" class="ma-0 pa-0"> <v-responsive :aspect-ratio="aspectRatio" class="ma-0 pa-0">
<v-carousel height="100%" hide-delimiters show-arrows-on-hover v-model="currentIndex"> <v-carousel height="100%" hide-delimiters :show-arrows="items.length > 1" :show-arrows-on-hover="items.length > 1" v-model="currentIndex">
<v-carousel-item v-for="(item,index) in items" :key="item.event.getId()"> <v-carousel-item v-for="(item,index) in items" :key="item.event.getId()">
<ThumbnailView :item="items[index]" :previewOnly="true" /> <ThumbnailView :item="items[index]" :previewOnly="true" v-on:itemclick="itemClicked" />
</v-carousel-item> </v-carousel-item>
</v-carousel> </v-carousel>
</v-responsive> </v-responsive>
<div class="indicator-container"> <div class="indicator-container" v-show="items.length > 1">
<div v-for="(item,index) in items" :key="index" :class="{'indicator': true, 'current': index == currentIndex}" /> <div v-for="(item,index) in items" :key="index" :class="{'indicator': true, 'current': index == currentIndex}" />
</div> </div>
</div> </div>
@ -16,6 +16,7 @@
<script> <script>
import messageMixin from "../../messages/messageMixin"; import messageMixin from "../../messages/messageMixin";
import ThumbnailView from '../../file_mode/ThumbnailView.vue'; import ThumbnailView from '../../file_mode/ThumbnailView.vue';
import util from "../../../plugins/utils";
export default { export default {
mixins: [messageMixin], mixins: [messageMixin],
@ -33,6 +34,21 @@ export default {
currentIndex: 0, currentIndex: 0,
}; };
}, },
computed: {
aspectRatio() {
return this.items.some((item) =>['m.video','m.image'].includes(item.event.getContent().msgtype)) ? 16/9 : undefined;
}
},
methods: {
itemClicked() {
if (this.items.length > 0 && this.currentIndex < this.items.length) {
const item = this.items[this.currentIndex];
if (util.isFileTypePDF(item.event)) {
this.$emit("download", {event: item.event});
}
}
}
}
}; };
</script> </script>

View file

@ -914,6 +914,7 @@ class Util {
} }
download(matrixClient, event) { download(matrixClient, event) {
console.log("DOWNLOAD");
this this
.getAttachment(matrixClient, event) .getAttachment(matrixClient, event)
.then((url) => { .then((url) => {
@ -924,6 +925,7 @@ class Util {
// PDFs are shown inline, not downloaded // PDFs are shown inline, not downloaded
link.download = event.getContent().body || this.$t("fallbacks.download_name"); link.download = event.getContent().body || this.$t("fallbacks.download_name");
} }
console.log("LINK", link);
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
setTimeout(function () { setTimeout(function () {