FreeDATA/gui_vue/src/components/chat_messages_received.vue

82 lines
2.2 KiB
Vue
Raw Normal View History

2023-09-14 19:17:05 +00:00
<template>
<div class="row justify-content-start mb-2">
<div :class="messageWidthClass">
<div class="card bg-light border-0 text-dark">
2023-09-21 21:04:12 +00:00
<div class="card-header" v-if="getFileContent['filesize'] !== 0">
<p class="card-text">{{ getFileContent["filename"] }} | {{ getFileContent["filesize"] }} Bytes | {{ getFileContent["filetype"] }}</p>
</div>
2023-09-14 19:17:05 +00:00
<div class="card-body">
<p class="card-text">{{ message.msg }}</p>
</div>
2023-09-22 21:21:44 +00:00
2023-09-14 19:17:05 +00:00
<div class="card-footer p-0 bg-light border-top-0">
<p class="text-muted p-0 m-0 me-1 text-end">{{ getDateTime }}</p> <!-- Display formatted timestamp in card-footer -->
</div>
</div>
</div>
2023-09-22 21:21:44 +00:00
<!-- Delete button outside of the card -->
<div class="col-2">
<button class="btn btn-outline-secondary" @click="deleteMessage"><i class="bi bi-trash"></i></button>
</div>
2023-09-14 19:17:05 +00:00
</div>
</template>
2023-09-22 21:21:44 +00:00
2023-09-13 21:28:20 +00:00
<script>
2023-09-22 21:21:44 +00:00
import {deleteMessageFromDB} from '../js/chatHandler'
2023-09-13 21:28:20 +00:00
export default {
props: {
2023-09-14 19:17:05 +00:00
message: Object,
2023-09-13 21:28:20 +00:00
},
2023-09-14 19:17:05 +00:00
computed: {
2023-09-21 21:04:12 +00:00
getFileContent(){
try{
var filename = Object.keys(this.message._attachments)[0]
var filesize = this.message._attachments[filename]["length"]
var filetype = filename.split(".")[1]
return {filename: filename, filesize: filesize, filetype: filetype}
} catch (e){
console.log("file not loaded from database - empty?")
// we are only checking against filesize for displaying attachments
return {filesize: 0}
}
},
2023-09-14 19:17:05 +00:00
messageWidthClass() {
// Calculate a Bootstrap grid class based on message length
// Adjust the logic as needed to fit your requirements
if (this.message.msg.length <= 50) {
return 'col-4';
} else if (this.message.msg.length <= 100) {
return 'col-6';
} else {
return 'col-9';
}
},
2023-09-22 21:21:44 +00:00
deleteMessage(){
deleteMessageFromDB(this.message._id)
},
2023-09-14 19:17:05 +00:00
getDateTime() {
var datetime = new Date(this.message.timestamp * 1000).toLocaleString(
navigator.language,
{
2023-09-13 21:28:20 +00:00
2023-09-14 19:17:05 +00:00
hour: '2-digit',
minute: '2-digit',
}
);
return datetime;
},
},
};
2023-09-13 21:28:20 +00:00
</script>