This image has been deleted
` : html``} + ${gif && !this.viewImage && this.myAddress !== this.messageObj.sender ? html` +diff --git a/qortal-ui-core/language/us.json b/qortal-ui-core/language/us.json index 1b3e31f7..16cf7867 100644 --- a/qortal-ui-core/language/us.json +++ b/qortal-ui-core/language/us.json @@ -572,23 +572,35 @@ "cchange63": "Enter Enabled", "cchange64": "Enter Disabled", "cchange65": "Please enter a recipient", - "cchange66": "Cannot fetch replied-to message. Message is too old.", - "cchange80": "Gif Explorer", - "cchange81": "Explore Collections", - "cchange82": "My Collections", - "cchange83": "Subscribed Collections", - "cchange84": "Upload your gif files", - "cchange85": "File should be .Gif", - "cchange86": "Upload Collection", - "cchange87": "A collection name is required!", - "cchange88": "Collection Name", - "cchange89": "Gif Collection Uploaded Successfully!", - "cchange90": "Gifs uploading, please wait...", - "cchange91": "Something went wrong! Please try changing tabs and coming back.", - "cchange92": "You currently have no collections.", - "cchange93": "You currently have no subscribed collections.", - "cchange94": "Error fetching image. Retrying...", - "cchange95": "Failed to fetch image! Please visit another collection and try again!" + "cchange66": "Cannot fetch replied-to message. Message is too old." + }, + "gifs": { + "gchange1": "Gif Explorer", + "gchange2": "Explore Collections", + "gchange3": "My Collections", + "gchange4": "Subscribed Collections", + "gchange5": "Upload your gif files", + "gchange6": "File should be .Gif", + "gchange7": "Upload Collection", + "gchange8": "A collection name is required!", + "gchange9": "Collection Name", + "gchange10": "Gif Collection Uploaded Successfully!", + "gchange11": "Gifs uploading, please wait...", + "gchange12": "Something went wrong! Please try changing tabs and coming back.", + "gchange13": "You currently have no collections.", + "gchange14": "You currently have no subscribed collections.", + "gchange15": "Error fetching GIF. Retrying...", + "gchange16": "Failed to fetch GIF! Please visit another collection and try again!", + "gchange17": "Subscribe to this collection", + "gchange18": "Searching for collections...", + "gchange19": "No collections found!", + "gchange20": "Subscribed to collection successfully!", + "gchange21": "Unsubscribed to collection successfully!", + "gchange22": "Unsubscribe from this collection", + "gchange23": "Your gif collection cannot contain two gifs with the same name!", + "gchange24": "This collection name is already taken. Try another name!", + "gchange25": "GIF (click to view)", + "gchange26": "A name is needed to access and send GIF files" }, "welcomepage": { "wcchange1": "Welcome to Q-Chat", diff --git a/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs-css.js b/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs-css.js index 5a9fd29a..7f68de4f 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs-css.js +++ b/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs-css.js @@ -462,10 +462,54 @@ background-color: #03a8f475; .gifs-loading-message { font-family: Montserrat, sans-serif; font-size: 20px; + font-weight: 600; color: var(--chat-bubble-msg-color); margin: 0 0 10px 0; text-align: center; user-select: none; } +.subscribe-button { + position: absolute; + bottom: 3px; + left: 50%; + transform: translateX(-50%); + font-family: Raleway, sans-serif; + font-weight: 500; + font-size: 14px; + background-color: var(--mdc-theme-primary); + border: none; + border-radius: 8px; + outline: none; + padding: 5px 10px; + transition: all 0.3s cubic-bezier(0.5, 1, 0.89, 1); +} + +.subscribe-button:hover { + cursor: pointer; + box-shadow: 0px 3px 4px 0px hsla(0,0%,0%,0.14), 0px 3px 3px -2px hsla(0,0%,0%,0.12), 0px 1px 8px 0px hsla(0,0%,0%,0.2); +} + +.unsubscribe-button { + position: absolute; + width: max-content; + bottom: 3px; + left: 50%; + transform: translateX(-50%); + font-family: Raleway, sans-serif; + font-weight: 500; + font-size: 14px; + background-color: #f44336; + border: none; + border-radius: 8px; + outline: none; + padding: 5px 10px; + transition: all 0.3s cubic-bezier(0.5, 1, 0.89, 1); +} + +.unsubscribe-button:hover { + cursor: pointer; + box-shadow: 0px 3px 4px 0px hsla(0,0%,0%,0.14), 0px 3px 3px -2px hsla(0,0%,0%,0.12), 0px 1px 8px 0px hsla(0,0%,0%,0.2); +} + `; diff --git a/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs.js b/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs.js index 28fa84ea..3fa66eba 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs.js +++ b/qortal-ui-plugins/plugins/core/components/ChatGifs/ChatGifs.js @@ -28,6 +28,10 @@ currentCollection: {type: String}, isLoading: {type: String}, newCollectionName: {type: String}, editor: {type: Object}, +isSubscribed: { type: Boolean }, +setGifsLoading: { attribute: false }, +sendMessage: { attribute: false }, +setOpenGifModal: { attribute: false } }; } @@ -36,22 +40,133 @@ editor: {type: Object}, constructor() { super(); this.uid = new ShortUniqueId(); - this.selectedAddress = - window.parent.reduxStore.getState().app.selectedAddress; + this.selectedAddress = window.parent.reduxStore.getState().app.selectedAddress; this.myGifCollections = []; this.mySubscribedCollections = []; this.exploreCollections = []; this.myAccountName = ''; this.gifsToBeAdded = []; - // mode can be 'myCollection', 'newCollection', 'explore', 'subscribedCollection' this.mode = 'myCollection'; this.currentCollection = null; this.pageNumber = 0; this.isLoading = false; + this.isSubscribed = false; this.newCollectionName = ''; + this.getAllCollections = this.getAllCollections.bind(this); } + async firstUpdated() { + const tooltip = this.shadowRoot.querySelector('vaadin-tooltip'); + const overlay = tooltip.shadowRoot.querySelector( + 'vaadin-tooltip-overlay' + ); + overlay.shadowRoot.getElementById('overlay').style.cssText = + 'background-color: transparent; border-radius: 10px; box-shadow: rgb(50 50 93 / 25%) 0px 2px 5px -1px, rgb(0 0 0 / 30%) 0px 1px 3px -1px'; + overlay.shadowRoot.getElementById('content').style.cssText = + 'background-color: var(--gif-tooltip-bg); color: var(--chat-bubble-msg-color); text-align: center; padding: 20px 10px; font-family: Roboto, sans-serif; letter-spacing: 0.3px; font-weight: 300; font-size: 13.5px; transition: all 0.3s ease-in-out;'; + + try { + this.isLoading = true; + const myCollections = await this.getMyGifCollections(); + const savedCollections = await this.getSavedCollections(); + const allCollections = await this.getAllCollections(); + + if (!Array.isArray(myCollections) && !Array.isArray(savedCollections)) { + parentEpml.request('showSnackBar', get('gifs.gchange12')); + return; + } + + await new Promise((res) => { + setTimeout(() => { + res(); + }, 1000) + }); + this.myGifCollections = myCollections; + this.mySubscribedCollections = savedCollections; + this.exploreCollections = allCollections; + } catch (error) { + console.error(error); + } finally { + this.isLoading = false; + } + } + + async updated(changedProperties) { + if (changedProperties && changedProperties.has('mode')) { + const mode = this.mode; + if (mode === 'myCollection') { + try { + this.myGifCollections = []; + this.isLoading = true; + const collections = await this.getMyGifCollections(); + await new Promise((res) => { + setTimeout(() => { + res(); + }, 1000) + }); + this.myGifCollections = collections; + } catch (error) { + console.error(error); + } finally { + this.isLoading = false; + } + } + + if (mode === 'explore') { + try { + this.exploreCollections = []; + this.isLoading = true; + const allCollections = await this.getAllCollections(); + await new Promise((res) => { + setTimeout(() => { + res(); + }, 1000) + }); + this.exploreCollections = allCollections; + } catch (error) { + console.error(error); + } finally { + this.isLoading = false; + } + } + if (mode === 'subscribedCollection') { + try { + this.mySubscribedCollections = []; + this.isLoading = true; + const savedCollections = await this.getSavedCollections(); + await new Promise((res) => { + setTimeout(() => { + res(); + }, 1000) + }); + this.mySubscribedCollections = savedCollections; + } catch (error) { + console.error(error); + } finally { + this.isLoading = false; + } + } + } + + if (changedProperties && changedProperties.has('currentCollection')) { + if (this.mode === 'explore') { + console.log(this.mySubscribedCollections, "subbed collections here"); + const subbedCollection = this.mySubscribedCollections.find((collection) => ((collection.name === this.currentCollection.name) && (collection.identifier === this.currentCollection.identifier))); + console.log({subbedCollection}); + if (subbedCollection) { + this.isSubscribed = true; + } else { + this.isSubscribed = false; + } + } + } + } + async structureCollections(gifCollections) { + const userName = await this.getName(this.selectedAddress.address); + if (!userName) { + return; + } try { const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[ @@ -73,7 +188,12 @@ editor: {type: Object}, }; if (metaData.files) { const metaDataArray = metaData.files.map((data) => { - return `${nodeUrl}/arbitrary/GIF_REPOSITORY/${this.myAccountName}/${collection.identifier}?filepath=${data}`; + return { + url: `${nodeUrl}/arbitrary/GIF_REPOSITORY/${this.myAccountName}/${collection.identifier}?filepath=${data}`, + filePath: data, + identifier: collection.identifier, + name: this.myAccountName + }; }); collectionObj = { @@ -190,8 +310,8 @@ editor: {type: Object}, const gifCollectionWithMetaData = await this.structureCollections( getAllGifCollections ); - this.exploreCollections = gifCollectionWithMetaData; this.pageNumber = this.pageNumber + 1; + return gifCollectionWithMetaData; } async getSavedCollections() { @@ -222,90 +342,6 @@ editor: {type: Object}, return savedCollectionsWithMetaData; } - async firstUpdated() { - const tooltip = this.shadowRoot.querySelector('vaadin-tooltip'); - const overlay = tooltip.shadowRoot.querySelector( - 'vaadin-tooltip-overlay' - ); - overlay.shadowRoot.getElementById('overlay').style.cssText = - 'background-color: transparent; border-radius: 10px; box-shadow: rgb(50 50 93 / 25%) 0px 2px 5px -1px, rgb(0 0 0 / 30%) 0px 1px 3px -1px'; - overlay.shadowRoot.getElementById('content').style.cssText = - 'background-color: var(--gif-tooltip-bg); color: var(--chat-bubble-msg-color); text-align: center; padding: 20px 10px; font-family: Roboto, sans-serif; letter-spacing: 0.3px; font-weight: 300; font-size: 13.5px; transition: all 0.3s ease-in-out;'; - - try { - this.isLoading = true; - const myCollections = await this.getMyGifCollections(); - const savedCollections = await this.getSavedCollections(); - - if (!Array.isArray(myCollections) && !Array.isArray(savedCollections)) { - parentEpml.request('showSnackBar', get('chatpage.cchange91')); - return; - } - - await new Promise((res) => { - setTimeout(() => { - res(); - }, 1000) - }); - this.myGifCollections = myCollections; - this.mySubscribedCollections = savedCollections; - await this.getAllCollections(); - this.isLoading = false; - } catch (error) { - this.isLoading = false; - console.error(error); - } - } - - async updated(changedProperties) { - if (changedProperties && changedProperties.has('mode')) { - const mode = this.mode; - if (mode === 'myCollection') { - try { - this.myGifCollections = []; - this.isLoading = true; - const collections = await this.getMyGifCollections(); - await new Promise((res) => { - setTimeout(() => { - res(); - }, 1000) - }); - this.myGifCollections = collections; - this.isLoading = false; - } catch (error) { - this.isLoading = false; - } - } - - if (mode === 'explore') { - try { - this.isLoading = true; - - await this.getAllCollections(); - this.isLoading = false; - } catch (error) { - this.isLoading = false; - } - } - if (mode === 'subscribedCollection') { - try { - this.mySubscribedCollections = []; - this.isLoading = true; - const savedCollections = await this.getSavedCollections(); - await new Promise((res) => { - setTimeout(() => { - res(); - }, 1000) - }); - this.mySubscribedCollections = savedCollections; - this.isLoading = false; - } catch (error) { - this.isLoading = false; - } - } - } - } - async getName(recipient) { try { const getNames = await parentEpml.request('apiCall', { @@ -323,6 +359,26 @@ editor: {type: Object}, } } + removeDotGIF(arr) { + return arr.map(obj => { + const newObj = { ...obj }; + if (newObj.hasOwnProperty('name') && newObj.name.endsWith('.gif')) { + newObj.name = newObj.name.slice(0, -4); + } + return newObj; + }); + } + + addDotGIF(arr) { + return arr.map(obj => { + const newObj = { ...obj }; + if (newObj.hasOwnProperty('name') && !newObj.name.endsWith('.gif')) { + newObj.name += '.gif'; + } + return newObj; + }); + } + addGifs(gifs) { const mapGifs = gifs.map((file) => { return { @@ -330,28 +386,59 @@ editor: {type: Object}, name: file.name, }; }); - this.gifsToBeAdded = [...this.gifsToBeAdded, ...mapGifs]; + const removedExtensions = this.removeDotGIF(mapGifs); + this.gifsToBeAdded = [...this.gifsToBeAdded, ...removedExtensions]; } async uploadGifCollection() { if (!this.newCollectionName) { - parentEpml.request('showSnackBar', get('chatpage.cchange87')); + parentEpml.request('showSnackBar', get('gifs.gchange8')); return; } try { this.setGifsLoading(true); this.isLoading = true; - const userName = await this.getName(this.selectedAddress.address); - const doesNameExist = await parentEpml.request('apiCall', { + const userName = await this.getName(this.selectedAddress.address); + const doesNameExist = await parentEpml.request('apiCall', { url: `/arbitrary/resources?service=GIF_REPOSITORY&limit=0&name=${userName}&identifier=${this.newCollectionName}`, }); - if (doesNameExist.length !== 0) { - parentEpml.request('showSnackBar', get('chatpage.cchange87')); - this.isLoading = false; - this.setGifsLoading(false); + if (!userName) { + parentEpml.request('showSnackBar', get('chatpage.cchange27')); + this.setGifsLoading(false); + this.isLoading = false; return; } + + if (doesNameExist.length !== 0) { + parentEpml.request('showSnackBar', get('gifs.gchange24')); + this.isLoading = false; + this.setGifsLoading(false); + return; + } + + function validateDuplicateGifNames(arr) { + let names = []; + for (let i = 0; i < arr.length; i++) { + if (names.includes(arr[i].name)) { + return false; + } + names.push(arr[i].name); + } + return true; + } + + let result = validateDuplicateGifNames(this.gifsToBeAdded); + + if (!result) { + parentEpml.request('showSnackBar', get('gifs.gchange23')); + this.isLoading = false; + this.setGifsLoading(false); + return; + } + + const addedGifExtensionsArr = this.addDotGIF(this.gifsToBeAdded); + function blobToBase64(blob) { return new Promise((resolve, _) => { const reader = new FileReader(); @@ -360,37 +447,24 @@ editor: {type: Object}, }); } const zipFileWriter = new zip.BlobWriter('application/zip'); - // Creates a TextReader object storing the text of the entry to add in the zip - // (i.e. "Hello world!"). - const helloWorldReader = new zip.TextReader('Hello world!'); - - // Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry - // "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and - // closes the writer. const zipWriter = new zip.ZipWriter(zipFileWriter, { bufferedWrite: true, }); - for (let i = 0; i < this.gifsToBeAdded.length; i++) { + for (let i = 0; i < addedGifExtensionsArr.length; i++) { await zipWriter.add( - this.gifsToBeAdded[i].name, - new zip.BlobReader(this.gifsToBeAdded[i].file) + addedGifExtensionsArr[i].name, + new zip.BlobReader(addedGifExtensionsArr[i].file) ); } await zipWriter.close(); + const zipFileBlob = await zipFileWriter.getData(); + const blobTobase = await blobToBase64(zipFileBlob); - if (!userName) { - parentEpml.request('showSnackBar', get('chatpage.cchange27')); - this.setGifsLoading(false); - this.isLoading = false; - return; - } - const id = this.uid(); - const identifier = `gif_${id}`; await publishData({ registeredName: userName, file: blobTobase.split(',')[1], @@ -421,21 +495,30 @@ editor: {type: Object}, clearInterval(interval); res(); } - } catch (error) {} + } catch (error) { + console.error(error); + this.isLoading = false; + this.setGifsLoading(false); + this.mode = 'myCollection'; + this.gifsToBeAdded = []; + this.newCollectionName = ''; + parentEpml.request('showSnackBar', get('gifs.gchange12')); + } stop = false; } }; interval = setInterval(getAnswer, 5000); }); saveAs(zipFileBlob, 'zipfile'); - this.isLoading = false; - this.setGifsLoading(false); - this.mode = 'myCollection'; - this.gifsToBeAdded = []; - this.newCollectionName = ''; - parentEpml.request('showSnackBar', get('chatpage.cchange89')); + this.isLoading = false; + this.setGifsLoading(false); + this.mode = 'myCollection'; + this.gifsToBeAdded = []; + this.newCollectionName = ''; + parentEpml.request('showSnackBar', get('gifs.gchange10')); } catch (error) { console.log(error); + parentEpml.request('showSnackBar', get('gifs.gchange12')); } } @@ -448,15 +531,36 @@ editor: {type: Object}, this.gifsToBeAdded = []; } + async subscribeToCollection() { + await this.addCollectionToList( + `${this.currentCollection.name}/${this.currentCollection.identifier}` + ); + parentEpml.request('showSnackBar', get('gifs.gchange20')); + this.isSubscribed = true; + const savedCollections = await this.getSavedCollections(); + this.mySubscribedCollections = savedCollections; + } + + async unsubscribeToCollection() { + await this.removeCollectionFromList( + `${this.currentCollection.name}/${this.currentCollection.identifier}` + ); + parentEpml.request('showSnackBar', get('gifs.gchange21')); + this.isSubscribed = false; + const savedCollections = await this.getSavedCollections(); + this.mySubscribedCollections = savedCollections; + } + render() { + console.log(8, "chat gifs here"); console.log('this.currentCollection', this.currentCollection); - console.log(31, 'chat gifs here'); return html`
${translate( - 'chatpage.cchange80' + 'gifs.gchange1' )}
- ${translate('chatpage.cchange84')} + ${translate('gifs.gchange5')}
- ${translate('chatpage.cchange85')} + ${translate('gifs.gchange6')}
This image has been deleted
` : html``} + ${gif && !this.viewImage && this.myAddress !== this.messageObj.sender ? html` +