keanu-weblite/src/components/messages/MessageOutgoingImage.vue

85 lines
2.2 KiB
Vue
Raw Normal View History

<template>
<message-outgoing v-bind="{ ...$props, ...$attrs }" v-on="$listeners">
<div class="bubble image-bubble" ref="imageRef">
<v-img
:aspect-ratio="16 / 9"
ref="image"
:src="src"
:cover="cover"
:contain="contain"
/>
2021-01-11 17:44:09 +01:00
</div>
<v-dialog
v-model="dialog"
:width="$vuetify.breakpoint.smAndUp ? '940px' : '90%'"
>
<v-img :src="src"/>
</v-dialog>
</message-outgoing>
</template>
<script>
2020-11-21 14:57:43 +01:00
import util from "../../plugins/utils";
import MessageOutgoing from "./MessageOutgoing.vue";
export default {
extends: MessageOutgoing,
components: { MessageOutgoing },
data() {
return {
src: undefined,
2021-03-10 13:40:32 +01:00
cover: true,
contain: false,
dialog: false
2021-01-11 17:44:09 +01:00
};
},
methods: {
// listen for custom hammerJs singletab click to differentiate it from double click(heart animation).
initMessageOutImageHammerJs(element) {
const hammerInstance = util.singleOrDoubleTabRecognizer(element);
hammerInstance.on("singletap doubletap", (ev) => {
if(ev.type === 'singletap') {
this.dialog = true;
}
});
}
},
mounted() {
const width = this.$refs.image.$el.clientWidth;
const height = (width * 9) / 16;
2020-11-21 14:57:43 +01:00
util
.getThumbnail(this.$matrix.matrixClient, this.event, this.$config, width, height)
2020-11-21 14:57:43 +01:00
.then((url) => {
2021-03-10 13:40:32 +01:00
const info = this.event.getContent().info;
// JPEGs use cover, PNG and GIF ect contain. This is because PNG and GIF are expected to
// be stickers and small emoji type things.
if (info && info.mimetype && info.mimetype.startsWith("image/jp")) {
this.cover = true;
this.contain = false;
} else {
this.cover = false;
this.contain = true;
}
2020-11-21 14:57:43 +01:00
this.src = url;
if(this.$refs.imageRef) {
this.initMessageOutImageHammerJs(this.$refs.imageRef);
}
2020-11-21 14:57:43 +01:00
})
.catch((err) => {
console.log("Failed to fetch thumbnail: ", err);
});
2020-11-19 17:08:58 +01:00
},
beforeDestroy() {
if (this.src) {
const objectUrl = this.src;
this.src = null;
URL.revokeObjectURL(objectUrl);
}
2020-11-21 14:57:43 +01:00
},
};
</script>
<style lang="scss">
@import "@/assets/css/chat.scss";
</style>