diff --git a/core/language/us.json b/core/language/us.json index 128d1c66..cb820354 100644 --- a/core/language/us.json +++ b/core/language/us.json @@ -833,7 +833,9 @@ "cchange82": "This attachment has been deleted", "cchange90": "No messages", "cchange91": "Sending...", - "cchange92": "Unread messages below" + "cchange92": "Unread messages below", + "cchange93": "Image copied to clipboard", + "cchange94": "loaded" }, "welcomepage": { "wcchange1": "Welcome to Q-Chat", diff --git a/plugins/plugins/core/components/ChatImage.js b/plugins/plugins/core/components/ChatImage.js index a0f2abb0..238404ba 100644 --- a/plugins/plugins/core/components/ChatImage.js +++ b/plugins/plugins/core/components/ChatImage.js @@ -9,8 +9,11 @@ import { } from 'lit-translate'; import axios from 'axios' import { RequestQueueWithPromise } from '../../utils/queue'; - +import '@material/mwc-menu'; +import '@material/mwc-list/mwc-list-item.js' +import { Epml } from '../../../epml'; const requestQueue = new RequestQueueWithPromise(5); +const parentEpml = new Epml({ type: 'WINDOW', source: window.parent }) export class ChatImage extends LitElement { static get properties() { @@ -24,11 +27,15 @@ export class ChatImage extends LitElement { static get styles() { return css` + * { + --mdc-theme-text-primary-on-background: var(--black); + } img { max-width:45vh; max-height:40vh; border-radius: 5px; cursor: pointer; + position: relative; } .smallLoading, .smallLoading:after { @@ -54,6 +61,10 @@ export class ChatImage extends LitElement { height: 40vh; } + mwc-menu { + position: absolute; + } + @@ -96,6 +107,7 @@ export class ChatImage extends LitElement { this.nodeUrl = this.getNodeUrl() this.myNode = this.getMyNode() this.hasCalledWhenDownloaded = false + this.isFetching = false this.observer = new IntersectionObserver(entries => { for (const entry of entries) { @@ -130,16 +142,14 @@ getMyNode(){ async fetchResource() { try { - // await qortalRequest({ - // action: 'GET_QDN_RESOURCE_PROPERTIES', - // name, - // service, - // identifier - // }) + if(this.isFetching) return + this.isFetching = true await axios.get(`${this.nodeUrl}/arbitrary/resource/properties/${this.resource.service}/${this.resource.name}/${this.resource.identifier}?apiKey=${this.myNode.apiKey}`) + this.isFetching = false - - } catch (error) {} + } catch (error) { + this.isFetching = false + } } async fetchVideoUrl() { @@ -200,7 +210,9 @@ getMyNode(){ } this.status = res - + if(this.status.status === 'DOWNLOADED'){ + this.fetchResource() + } } // check if progress is 100% and clear interval if true @@ -237,14 +249,70 @@ getMyNode(){ return true } - async updated(changedProperties) { - if (changedProperties && changedProperties.has('status')) { - if(this.hasCalledWhenDownloaded === false && this.status.status === 'DOWNLOADED'){ - this.fetchResource() - this.hasCalledWhenDownloaded = true - } - } + + + + showContextMenu(e) { + e.preventDefault(); + e.stopPropagation(); + + const contextMenu = this.shadowRoot.getElementById('contextMenu'); + const containerRect = e.currentTarget.getBoundingClientRect(); + + // Adjusting the positions + const adjustedX = e.clientX - containerRect.left; + const adjustedY = e.clientY - containerRect.top; + + contextMenu.style.top = `${adjustedY}px`; + contextMenu.style.left = `${adjustedX}px`; + + contextMenu.open = true; } + + + + + + async handleCopy(e) { + e.stopPropagation(); + const image = this.shadowRoot.querySelector('img'); + + // Create a canvas and draw the image on it. + const canvas = document.createElement('canvas'); + canvas.width = image.naturalWidth; + canvas.height = image.naturalHeight; + const ctx = canvas.getContext('2d'); + ctx.drawImage(image, 0, 0); + + // Convert canvas image to blob + canvas.toBlob(blob => { + try { + const clipboardItem = new ClipboardItem({ 'image/png': blob }); + navigator.clipboard.write([clipboardItem]).then(() => { + const msg = get("chatpage.cchange93") + parentEpml.request('showSnackBar', msg) + console.log('Image copied to clipboard'); + }).catch(err => { + console.error('Failed to copy image: ', err); + }); + } catch (error) { + console.error('Error copying the image: ', error); + } + }, 'image/png'); + } + + + + + handleMenuBlur() { + setTimeout(() => { + if (!this.isMenuItemClicked) { + const contextMenu = this.shadowRoot.getElementById('contextMenu'); + contextMenu.open = false; + } + }, 100); +} + render() { @@ -269,17 +337,23 @@ getMyNode(){
-${`${Math.round(this.status.percentLoaded || 0 - ).toFixed(0)}% loaded`}
+${`${Math.round(this.status.percentLoaded || 0 + ).toFixed(0)}% `}${translate('chatpage.cchange94')}
` : '' } ${this.status.status === 'READY' ? html` -