|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { LitElement, html, css } from 'lit'; |
|
|
|
|
import {animate} from '@lit-labs/motion'; |
|
|
|
|
import { animate } from '@lit-labs/motion'; |
|
|
|
|
import { Epml } from '../../../epml.js'; |
|
|
|
|
import { use, get, translate, registerTranslateConfig } from 'lit-translate'; |
|
|
|
|
import { generateHTML } from '@tiptap/core' |
|
|
|
@ -7,7 +7,7 @@ import StarterKit from '@tiptap/starter-kit'
|
|
|
|
|
import Underline from '@tiptap/extension-underline'; |
|
|
|
|
import Placeholder from '@tiptap/extension-placeholder' |
|
|
|
|
import Highlight from '@tiptap/extension-highlight' |
|
|
|
|
import {unsafeHTML} from 'lit/directives/unsafe-html.js'; |
|
|
|
|
import { unsafeHTML } from 'lit/directives/unsafe-html.js'; |
|
|
|
|
import { Editor, Extension } from '@tiptap/core' |
|
|
|
|
import * as zip from "@zip.js/zip.js"; |
|
|
|
|
import './ChatGifs/ChatGifs.js'; |
|
|
|
@ -91,28 +91,28 @@ class ChatPage extends LitElement {
|
|
|
|
|
webSocket: { attribute: false }, |
|
|
|
|
chatHeads: { type: Array }, |
|
|
|
|
forwardActiveChatHeadUrl: { type: Object }, |
|
|
|
|
openForwardOpen: {type: Boolean }, |
|
|
|
|
groupAdmin: {type: Array}, |
|
|
|
|
groupMembers: {type: Array}, |
|
|
|
|
shifted: {type: Boolean}, |
|
|
|
|
groupInfo: {type: Object}, |
|
|
|
|
setActiveChatHeadUrl: {attribute: false}, |
|
|
|
|
openForwardOpen: { type: Boolean }, |
|
|
|
|
groupAdmin: { type: Array }, |
|
|
|
|
groupMembers: { type: Array }, |
|
|
|
|
shifted: { type: Boolean }, |
|
|
|
|
groupInfo: { type: Object }, |
|
|
|
|
setActiveChatHeadUrl: { attribute: false }, |
|
|
|
|
userFound: { type: Array }, |
|
|
|
|
userFoundModalOpen: { type: Boolean }, |
|
|
|
|
webWorker: { type: Object }, |
|
|
|
|
webWorkerFile: { type: Object }, |
|
|
|
|
myTrimmedMeassage: { type: String }, |
|
|
|
|
editor: {type: Object}, |
|
|
|
|
currentEditor: {type: String}, |
|
|
|
|
isEnabledChatEnter: {type: Boolean}, |
|
|
|
|
editor: { type: Object }, |
|
|
|
|
currentEditor: { type: String }, |
|
|
|
|
isEnabledChatEnter: { type: Boolean }, |
|
|
|
|
openTipUser: { type: Boolean }, |
|
|
|
|
openUserInfo: { type: Boolean }, |
|
|
|
|
selectedHead: { type: Object }, |
|
|
|
|
userName: { type: String }, |
|
|
|
|
openGifModal: { type: Boolean }, |
|
|
|
|
gifsLoading: { type: Boolean }, |
|
|
|
|
goToRepliedMessage: {attribute: false}, |
|
|
|
|
isLoadingGoToRepliedMessage: {type: Object} |
|
|
|
|
goToRepliedMessage: { attribute: false }, |
|
|
|
|
isLoadingGoToRepliedMessage: { type: Object } |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1268,7 +1268,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
padding: 5px 0px; |
|
|
|
|
} |
|
|
|
|
` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
constructor() { |
|
|
|
|
super() |
|
|
|
@ -1349,7 +1349,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setOpenGifModal(value){ |
|
|
|
|
setOpenGifModal(value) { |
|
|
|
|
this.openGifModal = value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1379,12 +1379,12 @@ class ChatPage extends LitElement {
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
toggleEnableChatEnter(){ |
|
|
|
|
localStorage.setItem('isEnabledChatEnter', !this.isEnabledChatEnter )
|
|
|
|
|
toggleEnableChatEnter() { |
|
|
|
|
localStorage.setItem('isEnabledChatEnter', !this.isEnabledChatEnter) |
|
|
|
|
this.isEnabledChatEnter = !this.isEnabledChatEnter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
addGifs(gifs){ |
|
|
|
|
addGifs(gifs) { |
|
|
|
|
this.gifsToBeAdded = [...this.gifsToBeAdded, ...gifs] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1450,7 +1450,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
.webWorkerImage=${this.webWorkerFile} |
|
|
|
|
.setGifsLoading=${(val) => this.setGifsLoading(val)} |
|
|
|
|
.sendMessage=${(val) => this._sendMessage(val)} |
|
|
|
|
.setOpenGifModal=${(val)=> this.setOpenGifModal(val)}> |
|
|
|
|
.setOpenGifModal=${(val) => this.setOpenGifModal(val)}> |
|
|
|
|
</chat-gifs> |
|
|
|
|
<div
|
|
|
|
|
class='last-message-ref'
|
|
|
|
@ -1459,7 +1459,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
this.shadowRoot.querySelector("chat-scroller").shadowRoot.getElementById("downObserver") |
|
|
|
|
.scrollIntoView({ |
|
|
|
|
behavior: 'smooth', |
|
|
|
|
block: 'nearest', |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
}}> |
|
|
|
|
</vaadin-icon> |
|
|
|
@ -1531,13 +1531,13 @@ class ChatPage extends LitElement {
|
|
|
|
|
?isLoadingMessages=${this.isLoadingMessages} |
|
|
|
|
?isEditMessageOpen=${this.isEditMessageOpen} |
|
|
|
|
.editor=${this.editor} |
|
|
|
|
.updatePlaceholder=${(editor, value)=> this.updatePlaceholder(editor, value)} |
|
|
|
|
.updatePlaceholder=${(editor, value) => this.updatePlaceholder(editor, value)} |
|
|
|
|
id="_chatEditorDOM" |
|
|
|
|
.repliedToMessageObj=${this.repliedToMessageObj} |
|
|
|
|
.toggleEnableChatEnter=${this.toggleEnableChatEnter} |
|
|
|
|
?isEnabledChatEnter=${this.isEnabledChatEnter} |
|
|
|
|
?openGifModal=${this.openGifModal} |
|
|
|
|
.setOpenGifModal=${(val)=> this.setOpenGifModal(val)} |
|
|
|
|
.setOpenGifModal=${(val) => this.setOpenGifModal(val)} |
|
|
|
|
chatId=${this.chatId} |
|
|
|
|
>
|
|
|
|
|
</chat-text-editor> |
|
|
|
@ -1596,7 +1596,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
?isLoadingMessages=${this.isLoadingMessages} |
|
|
|
|
id="chatTextCaption" |
|
|
|
|
.editor=${this.editorImage} |
|
|
|
|
.updatePlaceholder=${(editor, value)=> this.updatePlaceholder(editor, value)} |
|
|
|
|
.updatePlaceholder=${(editor, value) => this.updatePlaceholder(editor, value)} |
|
|
|
|
> |
|
|
|
|
</chat-text-editor> |
|
|
|
|
</div> |
|
|
|
@ -1609,7 +1609,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
</button> |
|
|
|
|
<button |
|
|
|
|
class="modal-button" |
|
|
|
|
@click=${()=> { |
|
|
|
|
@click=${() => { |
|
|
|
|
const chatTextEditor = this.shadowRoot.getElementById('chatTextCaption') |
|
|
|
|
chatTextEditor.sendMessageFunc({ |
|
|
|
|
type: 'image', |
|
|
|
@ -1649,7 +1649,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
?isLoadingMessages=${this.isLoadingMessages} |
|
|
|
|
id="chatAttachmentId" |
|
|
|
|
.editor=${this.editorAttachment} |
|
|
|
|
.updatePlaceholder=${(editor, value)=> this.updatePlaceholder(editor, value)} |
|
|
|
|
.updatePlaceholder=${(editor, value) => this.updatePlaceholder(editor, value)} |
|
|
|
|
> |
|
|
|
|
</chat-text-editor> |
|
|
|
|
</div> |
|
|
|
@ -1688,7 +1688,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
this.openForwardOpen = false; |
|
|
|
|
this.forwardActiveChatHeadUrl = {}; |
|
|
|
|
this.requestUpdate(); |
|
|
|
|
} }
|
|
|
|
|
}}
|
|
|
|
|
style=${this.openForwardOpen ? "display: block" : "display: none"}> |
|
|
|
|
<div> |
|
|
|
|
<div class="dialog-container"> |
|
|
|
@ -1759,7 +1759,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
return html` |
|
|
|
|
<chat-select
|
|
|
|
|
activeChatHeadUrl=${this.forwardActiveChatHeadUrl.url}
|
|
|
|
|
.setActiveChatHeadUrl=${(val)=> { |
|
|
|
|
.setActiveChatHeadUrl=${(val) => { |
|
|
|
|
this.forwardActiveChatHeadUrl = { |
|
|
|
|
...this.forwardActiveChatHeadUrl, |
|
|
|
|
url: val |
|
|
|
@ -1783,7 +1783,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
</button> |
|
|
|
|
<button |
|
|
|
|
class="modal-button" |
|
|
|
|
@click=${()=> { |
|
|
|
|
@click=${() => { |
|
|
|
|
this.sendForwardMessage() |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
@ -1832,8 +1832,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
this.setUserName(""); |
|
|
|
|
this.setSelectedHead({}); |
|
|
|
|
}}
|
|
|
|
|
style=${ |
|
|
|
|
this.openUserInfo ? "display: block" : "display: none" |
|
|
|
|
style=${this.openUserInfo ? "display: block" : "display: none" |
|
|
|
|
}> |
|
|
|
|
<user-info |
|
|
|
|
.setOpenUserInfo=${(val) => this.setOpenUserInfo(val)} |
|
|
|
@ -1846,8 +1845,8 @@ class ChatPage extends LitElement {
|
|
|
|
|
</div> |
|
|
|
|
<div class="chat-right-panel ${this.shifted ? "movedin" : "movedout"}" ${animate()}> |
|
|
|
|
<chat-right-panel
|
|
|
|
|
.getMoreMembers=${(val)=> this.getMoreMembers(val)}
|
|
|
|
|
.toggle=${(val)=> this._toggle(val)}
|
|
|
|
|
.getMoreMembers=${(val) => this.getMoreMembers(val)}
|
|
|
|
|
.toggle=${(val) => this._toggle(val)}
|
|
|
|
|
.selectedAddress=${this.selectedAddress}
|
|
|
|
|
.groupMembers=${this.groupMembers}
|
|
|
|
|
.groupAdmin=${this.groupAdmin}
|
|
|
|
@ -1863,7 +1862,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getMoreMembers(groupId){ |
|
|
|
|
async getMoreMembers(groupId) { |
|
|
|
|
try { |
|
|
|
|
const getMembers = await parentEpml.request("apiCall", { |
|
|
|
|
type: "api", |
|
|
|
@ -1903,7 +1902,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
const elementChatImageId = this.shadowRoot.getElementById('chatTextCaption').shadowRoot.getElementById('newChat'); |
|
|
|
|
const elementChatAttachmentId = this.shadowRoot.getElementById('chatAttachmentId').shadowRoot.getElementById('newAttachmentChat'); |
|
|
|
|
this.editor = new Editor({ |
|
|
|
|
onUpdate: ()=> { |
|
|
|
|
onUpdate: () => { |
|
|
|
|
this.shadowRoot.getElementById('_chatEditorDOM').getMessageSize(this.editor.getJSON()) |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
@ -1917,10 +1916,10 @@ class ChatPage extends LitElement {
|
|
|
|
|
}), |
|
|
|
|
Extension.create({ |
|
|
|
|
name: 'shortcuts', |
|
|
|
|
addKeyboardShortcuts:()=> { |
|
|
|
|
addKeyboardShortcuts: () => { |
|
|
|
|
return { |
|
|
|
|
'Enter': ()=> { |
|
|
|
|
if(this.isEnabledChatEnter){ |
|
|
|
|
'Enter': () => { |
|
|
|
|
if (this.isEnabledChatEnter) { |
|
|
|
|
const chatTextEditor = this.shadowRoot.getElementById('_chatEditorDOM') |
|
|
|
|
chatTextEditor.sendMessageFunc({ |
|
|
|
|
}) |
|
|
|
@ -1929,7 +1928,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
"Shift-Enter": () => { |
|
|
|
|
if(this.isEnabledChatEnter){ |
|
|
|
|
if (this.isEnabledChatEnter) { |
|
|
|
|
this.editor.commands.first(() => [ |
|
|
|
|
this.editor.commands.newlineInCode() |
|
|
|
|
]) |
|
|
|
@ -1939,12 +1938,13 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this.editorImage = new Editor({ |
|
|
|
|
onUpdate: ()=> { |
|
|
|
|
onUpdate: () => { |
|
|
|
|
this.shadowRoot.getElementById('chatTextCaption').getMessageSize(this.editorImage.getJSON()) |
|
|
|
|
}, |
|
|
|
|
element: elementChatImageId, |
|
|
|
@ -1956,9 +1956,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
placeholder: 'Write something …', |
|
|
|
|
}), |
|
|
|
|
Extension.create({ |
|
|
|
|
addKeyboardShortcuts:()=> { |
|
|
|
|
addKeyboardShortcuts: () => { |
|
|
|
|
return { |
|
|
|
|
'Enter':() => { |
|
|
|
|
'Enter': () => { |
|
|
|
|
const chatTextEditor = this.shadowRoot.getElementById('chatTextCaption') |
|
|
|
|
chatTextEditor.sendMessageFunc({ |
|
|
|
|
type: 'image' |
|
|
|
@ -1966,7 +1966,8 @@ class ChatPage extends LitElement {
|
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -1983,9 +1984,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
placeholder: 'Write something …', |
|
|
|
|
}), |
|
|
|
|
Extension.create({ |
|
|
|
|
addKeyboardShortcuts:()=> { |
|
|
|
|
addKeyboardShortcuts: () => { |
|
|
|
|
return { |
|
|
|
|
'Enter':()=> { |
|
|
|
|
'Enter': () => { |
|
|
|
|
const chatTextEditor = this.shadowRoot.getElementById('chatAttachmentId') |
|
|
|
|
chatTextEditor.sendMessageFunc({ |
|
|
|
|
type: 'attachment' |
|
|
|
@ -1993,42 +1994,76 @@ class ChatPage extends LitElement {
|
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
] |
|
|
|
|
}) |
|
|
|
|
document.addEventListener('keydown', this.initialChat); |
|
|
|
|
document.addEventListener('paste', this.pasteImage); |
|
|
|
|
if(this.chatId){ |
|
|
|
|
window.parent.reduxStore.dispatch( window.parent.reduxAction.addChatLastSeen({ |
|
|
|
|
if (this.chatId) { |
|
|
|
|
window.parent.reduxStore.dispatch(window.parent.reduxAction.addChatLastSeen({ |
|
|
|
|
key: this.chatId, |
|
|
|
|
timestamp: Date.now() |
|
|
|
|
})) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let callback = (entries, observer) => { |
|
|
|
|
entries.forEach(entry => { |
|
|
|
|
if (entry.isIntersecting) { |
|
|
|
|
|
|
|
|
|
this.isPageVisible = true |
|
|
|
|
if (this.chatId) { |
|
|
|
|
window.parent.reduxStore.dispatch(window.parent.reduxAction.addChatLastSeen({ |
|
|
|
|
key: this.chatId, |
|
|
|
|
timestamp: Date.now() |
|
|
|
|
})) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.isPageVisible = false |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let options = { |
|
|
|
|
root: null, |
|
|
|
|
rootMargin: '0px', |
|
|
|
|
threshold: 0.5 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Create the observer with the callback function and options
|
|
|
|
|
this.observer = new IntersectionObserver(callback, options); |
|
|
|
|
const mainContainer = this.shadowRoot.querySelector('.main-container') |
|
|
|
|
|
|
|
|
|
this.observer.observe(mainContainer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
disconnectedCallback() { |
|
|
|
|
super.disconnectedCallback(); |
|
|
|
|
if(this.webSocket){ |
|
|
|
|
if (this.webSocket) { |
|
|
|
|
this.webSocket.close(1000, 'switch chat') |
|
|
|
|
this.webSocket= '' |
|
|
|
|
this.webSocket = '' |
|
|
|
|
} |
|
|
|
|
if(this.webWorker){ |
|
|
|
|
if (this.webWorker) { |
|
|
|
|
this.webWorker.terminate(); |
|
|
|
|
} |
|
|
|
|
if(this.webWorkerFile){ |
|
|
|
|
if (this.webWorkerFile) { |
|
|
|
|
this.webWorkerFile.terminate(); |
|
|
|
|
} |
|
|
|
|
if(this.editor){ |
|
|
|
|
if (this.editor) { |
|
|
|
|
this.editor.destroy() |
|
|
|
|
} |
|
|
|
|
if(this.editorImage){ |
|
|
|
|
if (this.editorImage) { |
|
|
|
|
this.editorImage.destroy() |
|
|
|
|
} |
|
|
|
|
if (this.observer) { |
|
|
|
|
this.observer.disconnect(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
document.removeEventListener('keydown', this.initialChat); |
|
|
|
|
document.removeEventListener('paste', this.pasteImage); |
|
|
|
|
if(this.chatId){ |
|
|
|
|
window.parent.reduxStore.dispatch( window.parent.reduxAction.addChatLastSeen({ |
|
|
|
|
if (this.chatId) { |
|
|
|
|
window.parent.reduxStore.dispatch(window.parent.reduxAction.addChatLastSeen({ |
|
|
|
|
key: this.chatId, |
|
|
|
|
timestamp: Date.now() |
|
|
|
|
})) |
|
|
|
@ -2051,7 +2086,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async pasteImage (e) {
|
|
|
|
|
async pasteImage(e) { |
|
|
|
|
const event = e; |
|
|
|
|
const handleTransferIntoURL = (dataTransfer) => { |
|
|
|
|
try { |
|
|
|
@ -2071,8 +2106,8 @@ class ChatPage extends LitElement {
|
|
|
|
|
const item_list = await navigator.clipboard.read(); |
|
|
|
|
let image_type; |
|
|
|
|
const item = item_list.find(item => |
|
|
|
|
item.types.some( type => {
|
|
|
|
|
if (type.startsWith( 'image/')) { |
|
|
|
|
item.types.some(type => { |
|
|
|
|
if (type.startsWith('image/')) { |
|
|
|
|
image_type = type; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -2098,22 +2133,22 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async goToRepliedMessage(message, clickedOnMessage){ |
|
|
|
|
async goToRepliedMessage(message, clickedOnMessage) { |
|
|
|
|
const findMessage = this.shadowRoot.querySelector('chat-scroller').shadowRoot.getElementById(message.signature) |
|
|
|
|
|
|
|
|
|
if(findMessage){ |
|
|
|
|
if (findMessage) { |
|
|
|
|
findMessage.scrollIntoView({ behavior: 'smooth', block: 'center' }) |
|
|
|
|
const findElement = findMessage.shadowRoot.querySelector('.message-parent') |
|
|
|
|
if(findElement){ |
|
|
|
|
if (findElement) { |
|
|
|
|
findElement.classList.add('blink-bg') |
|
|
|
|
setTimeout(()=> { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
findElement.classList.remove('blink-bg') |
|
|
|
|
}, 2000) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if((message.timestamp - this.messagesRendered[0].timestamp) > 86400000){ |
|
|
|
|
if ((message.timestamp - this.messagesRendered[0].timestamp) > 86400000) { |
|
|
|
|
let errorMsg = get("chatpage.cchange66") |
|
|
|
|
parentEpml.request('showSnackBar', `${errorMsg}`) |
|
|
|
|
return |
|
|
|
@ -2122,9 +2157,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if((message.timestamp - this.messagesRendered[0].timestamp) < 86400000){ |
|
|
|
|
if ((message.timestamp - this.messagesRendered[0].timestamp) < 86400000) { |
|
|
|
|
const findOriginalMessage = this.shadowRoot.querySelector('chat-scroller').shadowRoot.getElementById(clickedOnMessage.signature) |
|
|
|
|
if(findOriginalMessage){ |
|
|
|
|
if (findOriginalMessage) { |
|
|
|
|
const messageClientRect = findOriginalMessage.getBoundingClientRect() |
|
|
|
|
this.isLoadingGoToRepliedMessage = { |
|
|
|
|
...this.isLoadingGoToRepliedMessage, |
|
|
|
@ -2136,16 +2171,16 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
await this.getOldMessageDynamic(0, this.messagesRendered[0].timestamp, message.timestamp - 7200000) |
|
|
|
|
const findMessage = this.shadowRoot.querySelector('chat-scroller').shadowRoot.getElementById(message.signature) |
|
|
|
|
if(findMessage){ |
|
|
|
|
if (findMessage) { |
|
|
|
|
this.isLoadingGoToRepliedMessage = { |
|
|
|
|
...this.isLoadingGoToRepliedMessage, |
|
|
|
|
loading: false |
|
|
|
|
} |
|
|
|
|
findMessage.scrollIntoView({block: 'center' }) |
|
|
|
|
findMessage.scrollIntoView({ block: 'center' }) |
|
|
|
|
const findElement = findMessage.shadowRoot.querySelector('.message-parent') |
|
|
|
|
if(findElement){ |
|
|
|
|
if (findElement) { |
|
|
|
|
findElement.classList.add('blink-bg') |
|
|
|
|
setTimeout(()=> { |
|
|
|
|
setTimeout(() => { |
|
|
|
|
findElement.classList.remove('blink-bg') |
|
|
|
|
}, 2000) |
|
|
|
|
} |
|
|
|
@ -2194,7 +2229,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setForwardProperties(forwardedMessage){ |
|
|
|
|
setForwardProperties(forwardedMessage) { |
|
|
|
|
this.openForwardOpen = true |
|
|
|
|
this.forwardedMessage = forwardedMessage |
|
|
|
|
} |
|
|
|
@ -2255,7 +2290,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
this.initChatEditor(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async initUpdate(){ |
|
|
|
|
async initUpdate() { |
|
|
|
|
this.pageNumber = 1 |
|
|
|
|
const getAddressPublicKey = () => { |
|
|
|
|
|
|
|
|
@ -2301,7 +2336,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
const isRecipient = this.chatId.includes('direct') === true ? true : false; |
|
|
|
|
const groupId = this.chatId.split('/')[1]; |
|
|
|
|
if(!isRecipient && groupId.toString() !== '0'){ |
|
|
|
|
if (!isRecipient && groupId.toString() !== '0') { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
const getMembers = await parentEpml.request("apiCall", { |
|
|
|
@ -2379,7 +2414,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
const isEnabledChatEnter = localStorage.getItem('isEnabledChatEnter') |
|
|
|
|
|
|
|
|
|
if(isEnabledChatEnter){ |
|
|
|
|
if (isEnabledChatEnter) { |
|
|
|
|
this.isEnabledChatEnter = isEnabledChatEnter === 'false' ? false : true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2406,14 +2441,14 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async getName (recipient) { |
|
|
|
|
async getName(recipient) { |
|
|
|
|
try { |
|
|
|
|
const getNames = await parentEpml.request("apiCall", { |
|
|
|
|
type: "api", |
|
|
|
|
url: `/names/address/${recipient}`, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (Array.isArray(getNames) && getNames.length > 0 ) { |
|
|
|
|
if (Array.isArray(getNames) && getNames.length > 0) { |
|
|
|
|
return getNames[0].name |
|
|
|
|
} else { |
|
|
|
|
return '' |
|
|
|
@ -2425,14 +2460,14 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async renderPlaceholder() { |
|
|
|
|
const getName = async (recipient)=> { |
|
|
|
|
const getName = async (recipient) => { |
|
|
|
|
try { |
|
|
|
|
const getNames = await parentEpml.request("apiCall", { |
|
|
|
|
type: "api", |
|
|
|
|
url: `/names/address/${recipient}`, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (Array.isArray(getNames) && getNames.length > 0 ) { |
|
|
|
|
if (Array.isArray(getNames) && getNames.length > 0) { |
|
|
|
|
return getNames[0].name |
|
|
|
|
} else { |
|
|
|
|
return '' |
|
|
|
@ -2443,7 +2478,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
let userName = "" |
|
|
|
|
if(this.isReceipient){ |
|
|
|
|
if (this.isReceipient) { |
|
|
|
|
userName = await getName(this._chatId); |
|
|
|
|
} |
|
|
|
|
const mstring = get("chatpage.cchange8"); |
|
|
|
@ -2461,12 +2496,12 @@ class ChatPage extends LitElement {
|
|
|
|
|
.setRepliedToMessageObj=${(val) => this.setRepliedToMessageObj(val)} |
|
|
|
|
.setEditedMessageObj=${(val) => this.setEditedMessageObj(val)} |
|
|
|
|
.sendMessage=${(val) => this._sendMessage(val)} |
|
|
|
|
.sendMessageForward=${(messageText, typeMessage, chatReference, isForward, forwardParams)=> this.sendMessage(messageText, typeMessage, chatReference, isForward, forwardParams)} |
|
|
|
|
.sendMessageForward=${(messageText, typeMessage, chatReference, isForward, forwardParams) => this.sendMessage(messageText, typeMessage, chatReference, isForward, forwardParams)} |
|
|
|
|
.showLastMessageRefScroller=${(val) => this.showLastMessageRefScroller(val)} |
|
|
|
|
.emojiPicker=${this.emojiPicker}
|
|
|
|
|
?isLoadingMessages=${this.isLoadingOldMessages} |
|
|
|
|
.setIsLoadingMessages=${(val) => this.setIsLoadingMessages(val)} |
|
|
|
|
.setForwardProperties=${(forwardedMessage)=> this.setForwardProperties(forwardedMessage)} |
|
|
|
|
.setForwardProperties=${(forwardedMessage) => this.setForwardProperties(forwardedMessage)} |
|
|
|
|
.setOpenPrivateMessage=${(val) => this.setOpenPrivateMessage(val)} |
|
|
|
|
.setOpenTipUser=${(val) => this.setOpenTipUser(val)} |
|
|
|
|
.setOpenUserInfo=${(val) => this.setOpenUserInfo(val)} |
|
|
|
@ -2474,13 +2509,13 @@ class ChatPage extends LitElement {
|
|
|
|
|
.setSelectedHead=${(val) => this.setSelectedHead(val)} |
|
|
|
|
?openTipUser=${this.openTipUser} |
|
|
|
|
.selectedHead=${this.selectedHead} |
|
|
|
|
.goToRepliedMessage=${(val, val2)=> this.goToRepliedMessage(val, val2)} |
|
|
|
|
.getOldMessageAfter=${(val)=> this.getOldMessageAfter(val)} |
|
|
|
|
.goToRepliedMessage=${(val, val2) => this.goToRepliedMessage(val, val2)} |
|
|
|
|
.getOldMessageAfter=${(val) => this.getOldMessageAfter(val)} |
|
|
|
|
> |
|
|
|
|
</chat-scroller> |
|
|
|
|
` |
|
|
|
|
} |
|
|
|
|
setIsLoadingMessages(val){ |
|
|
|
|
setIsLoadingMessages(val) { |
|
|
|
|
this.isLoadingOldMessages = val |
|
|
|
|
} |
|
|
|
|
async getUpdateComplete() { |
|
|
|
@ -2499,7 +2534,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updatePlaceholder(editor, text){ |
|
|
|
|
updatePlaceholder(editor, text) { |
|
|
|
|
editor.extensionManager.extensions.forEach((extension) => { |
|
|
|
|
if (extension.name === "placeholder") { |
|
|
|
|
|
|
|
|
@ -2537,7 +2572,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
await this.getUpdateComplete(); |
|
|
|
|
const viewElement = this.shadowRoot.querySelector('chat-scroller').shadowRoot.getElementById('viewElement'); |
|
|
|
|
|
|
|
|
|
if(viewElement){ |
|
|
|
|
if (viewElement) { |
|
|
|
|
viewElement.scrollTop = 200 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2572,7 +2607,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
await this.getUpdateComplete(); |
|
|
|
|
const viewElement = this.shadowRoot.querySelector('chat-scroller').shadowRoot.getElementById('viewElement'); |
|
|
|
|
|
|
|
|
|
if(viewElement){ |
|
|
|
|
if (viewElement) { |
|
|
|
|
viewElement.scrollTop = 200 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2612,9 +2647,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
await this.getUpdateComplete(); |
|
|
|
|
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template')); |
|
|
|
|
|
|
|
|
|
const findElement = marginElements.find((item)=> item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
const findElement = marginElements.find((item) => item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
|
|
|
|
|
if(findElement){ |
|
|
|
|
if (findElement) { |
|
|
|
|
findElement.scrollIntoView({ behavior: 'auto', block: 'center' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2645,9 +2680,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
this.isLoadingOldMessages = false |
|
|
|
|
await this.getUpdateComplete(); |
|
|
|
|
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template')); |
|
|
|
|
const findElement = marginElements.find((item)=> item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
const findElement = marginElements.find((item) => item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
|
|
|
|
|
if(findElement){ |
|
|
|
|
if (findElement) { |
|
|
|
|
findElement.scrollIntoView({ behavior: 'auto', block: 'center' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2683,9 +2718,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
await this.getUpdateComplete(); |
|
|
|
|
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template')); |
|
|
|
|
|
|
|
|
|
const findElement = marginElements.find((item)=> item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
const findElement = marginElements.find((item) => item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
|
|
|
|
|
if(findElement){ |
|
|
|
|
if (findElement) { |
|
|
|
|
findElement.scrollIntoView({ behavior: 'auto', block: 'center' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2709,16 +2744,16 @@ class ChatPage extends LitElement {
|
|
|
|
|
_publicKey: this._publicKey |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
this.messagesRendered = [ ...this.messagesRendered, ...replacedMessages].sort(function (a, b) { |
|
|
|
|
this.messagesRendered = [...this.messagesRendered, ...replacedMessages].sort(function (a, b) { |
|
|
|
|
return a.timestamp |
|
|
|
|
- b.timestamp |
|
|
|
|
}) |
|
|
|
|
this.isLoadingOldMessages = false |
|
|
|
|
await this.getUpdateComplete(); |
|
|
|
|
const marginElements = Array.from(this.shadowRoot.querySelector('chat-scroller').shadowRoot.querySelectorAll('message-template')); |
|
|
|
|
const findElement = marginElements.find((item)=> item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
const findElement = marginElements.find((item) => item.messageObj.signature === scrollElement.messageObj.signature) |
|
|
|
|
|
|
|
|
|
if(findElement){ |
|
|
|
|
if (findElement) { |
|
|
|
|
findElement.scrollIntoView({ behavior: 'auto', block: 'center' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2770,12 +2805,12 @@ class ChatPage extends LitElement {
|
|
|
|
|
isNotInitial: true |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const renderEachMessage = replacedMessages.map(async(msg)=> { |
|
|
|
|
const renderEachMessage = replacedMessages.map(async (msg) => { |
|
|
|
|
await this.renderNewMessage(msg) |
|
|
|
|
}) |
|
|
|
|
await Promise.all(renderEachMessage) |
|
|
|
|
if(this.chatId){ |
|
|
|
|
window.parent.reduxStore.dispatch( window.parent.reduxAction.addChatLastSeen({ |
|
|
|
|
if (this.chatId && this.isPageVisible) { |
|
|
|
|
window.parent.reduxStore.dispatch(window.parent.reduxAction.addChatLastSeen({ |
|
|
|
|
key: this.chatId, |
|
|
|
|
timestamp: Date.now() |
|
|
|
|
})) |
|
|
|
@ -2793,7 +2828,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
setRepliedToMessageObj(messageObj) { |
|
|
|
|
this.editor.commands.focus('end') |
|
|
|
|
this.repliedToMessageObj = {...messageObj}; |
|
|
|
|
this.repliedToMessageObj = { ...messageObj }; |
|
|
|
|
this.editedMessageObj = null; |
|
|
|
|
this.requestUpdate(); |
|
|
|
|
} |
|
|
|
@ -2802,7 +2837,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
setEditedMessageObj(messageObj) { |
|
|
|
|
this.editor.commands.focus('end') |
|
|
|
|
this.editedMessageObj = {...messageObj}; |
|
|
|
|
this.editedMessageObj = { ...messageObj }; |
|
|
|
|
this.repliedToMessageObj = null; |
|
|
|
|
this.requestUpdate(); |
|
|
|
|
} |
|
|
|
@ -2828,12 +2863,14 @@ class ChatPage extends LitElement {
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
async renderNewMessage(newMessage) { |
|
|
|
|
if(newMessage.chatReference){ |
|
|
|
|
const findOriginalMessageIndex = this.messagesRendered.findIndex(msg=> msg.signature === newMessage.chatReference || (msg.chatReference && msg.chatReference === newMessage.chatReference) ) |
|
|
|
|
if(findOriginalMessageIndex !== -1 && this.messagesRendered[findOriginalMessageIndex].sender === newMessage.sender){ |
|
|
|
|
if (newMessage.chatReference) { |
|
|
|
|
const findOriginalMessageIndex = this.messagesRendered.findIndex(msg => msg.signature === newMessage.chatReference || (msg.chatReference && msg.chatReference === newMessage.chatReference)) |
|
|
|
|
if (findOriginalMessageIndex !== -1 && this.messagesRendered[findOriginalMessageIndex].sender === newMessage.sender) { |
|
|
|
|
const newMessagesRendered = [...this.messagesRendered] |
|
|
|
|
newMessagesRendered[findOriginalMessageIndex] = {...newMessage, timestamp: newMessagesRendered[findOriginalMessageIndex].timestamp, senderName: newMessagesRendered[findOriginalMessageIndex].senderName, |
|
|
|
|
sender: newMessagesRendered[findOriginalMessageIndex].sender, editedTimestamp: newMessage.timestamp } |
|
|
|
|
newMessagesRendered[findOriginalMessageIndex] = { |
|
|
|
|
...newMessage, timestamp: newMessagesRendered[findOriginalMessageIndex].timestamp, senderName: newMessagesRendered[findOriginalMessageIndex].senderName, |
|
|
|
|
sender: newMessagesRendered[findOriginalMessageIndex].sender, editedTimestamp: newMessage.timestamp |
|
|
|
|
} |
|
|
|
|
this.messagesRendered = newMessagesRendered |
|
|
|
|
await this.getUpdateComplete(); |
|
|
|
|
} |
|
|
|
@ -2869,7 +2906,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
* @param {Object} encodedMessageObj
|
|
|
|
|
*
|
|
|
|
|
*/ |
|
|
|
|
decodeMessage(encodedMessageObj, isReceipient, _publicKey ) { |
|
|
|
|
decodeMessage(encodedMessageObj, isReceipient, _publicKey) { |
|
|
|
|
let isReceipientVar; |
|
|
|
|
let _publicKeyVar; |
|
|
|
|
try { |
|
|
|
@ -2906,6 +2943,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
async fetchChatMessages(chatId) { |
|
|
|
|
|
|
|
|
|
const initDirect = async (cid, noInitial) => { |
|
|
|
|
let timeoutId |
|
|
|
|
let initial = 0 |
|
|
|
|
|
|
|
|
|
let directSocketTimeout |
|
|
|
@ -2932,8 +2970,13 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
// Message Event
|
|
|
|
|
this.webSocket.onmessage = async (e) => { |
|
|
|
|
if (e.data === 'pong') { |
|
|
|
|
clearTimeout(timeoutId); |
|
|
|
|
directSocketTimeout = setTimeout(pingDirectSocket, 45000) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (initial === 0) { |
|
|
|
|
if(noInitial) return |
|
|
|
|
if (noInitial) return |
|
|
|
|
const cachedData = null |
|
|
|
|
let getInitialMessages = [] |
|
|
|
|
if (cachedData && cachedData.length !== 0) { |
|
|
|
@ -2958,7 +3001,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
try { |
|
|
|
|
if(e.data){ |
|
|
|
|
if (e.data) { |
|
|
|
|
this.processMessages(JSON.parse(e.data), false) |
|
|
|
|
} |
|
|
|
|
} catch (error) { |
|
|
|
@ -2972,7 +3015,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
// Closed Event
|
|
|
|
|
this.webSocket.onclose = (e) => { |
|
|
|
|
clearTimeout(directSocketTimeout) |
|
|
|
|
if(e.reason === 'switch chat') return |
|
|
|
|
if (e.reason === 'switch chat') return |
|
|
|
|
restartDirectWebSocket() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2983,10 +3026,13 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
const pingDirectSocket = () => { |
|
|
|
|
this.webSocket.send('ping') |
|
|
|
|
|
|
|
|
|
directSocketTimeout = setTimeout(pingDirectSocket, 295000) |
|
|
|
|
timeoutId = setTimeout(() => { |
|
|
|
|
this.webSocket.close(); |
|
|
|
|
clearTimeout(directSocketTimeout) |
|
|
|
|
}, 5000); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
const restartDirectWebSocket = () => { |
|
|
|
|
const noInitial = true |
|
|
|
@ -2999,6 +3045,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const initGroup = (gId, noInitial) => { |
|
|
|
|
let timeoutId |
|
|
|
|
let groupId = Number(gId) |
|
|
|
|
|
|
|
|
|
let initial = 0 |
|
|
|
@ -3029,9 +3076,13 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
// Message Event
|
|
|
|
|
this.webSocket.onmessage = async (e) => { |
|
|
|
|
|
|
|
|
|
if (e.data === 'pong') { |
|
|
|
|
clearTimeout(timeoutId); |
|
|
|
|
groupSocketTimeout = setTimeout(pingGroupSocket, 45000) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (initial === 0) { |
|
|
|
|
if(noInitial) return |
|
|
|
|
if (noInitial) return |
|
|
|
|
const cachedData = null; |
|
|
|
|
let getInitialMessages = [] |
|
|
|
|
if (cachedData && cachedData.length !== 0) { |
|
|
|
@ -3071,19 +3122,22 @@ class ChatPage extends LitElement {
|
|
|
|
|
// Closed Event
|
|
|
|
|
this.webSocket.onclose = (e) => { |
|
|
|
|
clearTimeout(groupSocketTimeout) |
|
|
|
|
if(e.reason === 'switch chat') return |
|
|
|
|
if (e.reason === 'switch chat') return |
|
|
|
|
restartGroupWebSocket() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Error Event
|
|
|
|
|
this.webSocket.onerror = () => { |
|
|
|
|
clearTimeout(groupSocketTimeout) |
|
|
|
|
this.webSocket.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const pingGroupSocket = () => { |
|
|
|
|
this.webSocket.send('ping') |
|
|
|
|
|
|
|
|
|
groupSocketTimeout = setTimeout(pingGroupSocket, 295000) |
|
|
|
|
timeoutId = setTimeout(() => { |
|
|
|
|
this.webSocket.close(); |
|
|
|
|
clearTimeout(groupSocketTimeout) |
|
|
|
|
}, 5000); // Close the WebSocket connection if no pong message is received within 5 seconds.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
@ -3105,22 +3159,22 @@ class ChatPage extends LitElement {
|
|
|
|
|
// Add to the messages... TODO: Save messages to localstorage and fetch from it to make it persistent...
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
resetChatEditor(){ |
|
|
|
|
if(this.currentEditor === '_chatEditorDOM'){ |
|
|
|
|
resetChatEditor() { |
|
|
|
|
if (this.currentEditor === '_chatEditorDOM') { |
|
|
|
|
this.editor.commands.setContent('') |
|
|
|
|
} |
|
|
|
|
if(this.currentEditor === 'newChat'){ |
|
|
|
|
if (this.currentEditor === 'newChat') { |
|
|
|
|
this.editorImage.commands.setContent('') |
|
|
|
|
} |
|
|
|
|
if(this.currentEditor === 'newAttachmentChat'){ |
|
|
|
|
if (this.currentEditor === 'newAttachmentChat') { |
|
|
|
|
this.editorAttachment.commands.setContent('') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async _sendMessage(outSideMsg, msg) { |
|
|
|
|
if(this.isReceipient){ |
|
|
|
|
if (this.isReceipient) { |
|
|
|
|
let hasPublicKey = true |
|
|
|
|
if(!this._publicKey.hasPubKey){ |
|
|
|
|
if (!this._publicKey.hasPubKey) { |
|
|
|
|
hasPublicKey = false |
|
|
|
|
try { |
|
|
|
|
const res = await parentEpml.request('apiCall', { |
|
|
|
@ -3141,7 +3195,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
} catch (error) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!hasPublicKey || !this._publicKey.hasPubKey){ |
|
|
|
|
if (!hasPublicKey || !this._publicKey.hasPubKey) { |
|
|
|
|
let err4string = get("chatpage.cchange39"); |
|
|
|
|
parentEpml.request('showSnackBar', `${err4string}`) |
|
|
|
|
return |
|
|
|
@ -3159,14 +3213,14 @@ class ChatPage extends LitElement {
|
|
|
|
|
this.isLoading = true; |
|
|
|
|
const trimmedMessage = msg |
|
|
|
|
|
|
|
|
|
const getName = async (recipient)=> { |
|
|
|
|
const getName = async (recipient) => { |
|
|
|
|
try { |
|
|
|
|
const getNames = await parentEpml.request("apiCall", { |
|
|
|
|
type: "api", |
|
|
|
|
url: `/names/address/${recipient}`, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (Array.isArray(getNames) && getNames.length > 0 ) { |
|
|
|
|
if (Array.isArray(getNames) && getNames.length > 0) { |
|
|
|
|
return getNames[0].name |
|
|
|
|
} else { |
|
|
|
|
return '' |
|
|
|
@ -3191,7 +3245,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
this.webWorkerFile = new WebWorkerFile(); |
|
|
|
|
|
|
|
|
|
const b64toBlob = (b64Data, contentType='', sliceSize=512) => { |
|
|
|
|
const b64toBlob = (b64Data, contentType = '', sliceSize = 512) => { |
|
|
|
|
const byteCharacters = atob(b64Data); |
|
|
|
|
const byteArrays = []; |
|
|
|
|
|
|
|
|
@ -3207,7 +3261,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
byteArrays.push(byteArray); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const blob = new Blob(byteArrays, {type: contentType}); |
|
|
|
|
const blob = new Blob(byteArrays, { type: contentType }); |
|
|
|
|
return blob; |
|
|
|
|
} |
|
|
|
|
const blob = b64toBlob(str, 'image/png'); |
|
|
|
@ -3231,7 +3285,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
try { |
|
|
|
|
await publishData({ |
|
|
|
|
registeredName: userName, |
|
|
|
|
file : compressedFile, |
|
|
|
|
file: compressedFile, |
|
|
|
|
service: 'QCHAT_IMAGE', |
|
|
|
|
identifier: identifier, |
|
|
|
|
parentEpml, |
|
|
|
@ -3248,7 +3302,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
typeMessage = 'edit'; |
|
|
|
|
let chatReference = outSideMsg.editedMessageObj.signature; |
|
|
|
|
|
|
|
|
|
if(outSideMsg.editedMessageObj.chatReference){ |
|
|
|
|
if (outSideMsg.editedMessageObj.chatReference) { |
|
|
|
|
chatReference = outSideMsg.editedMessageObj.chatReference; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3280,7 +3334,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
|
|
|
|
|
this.webWorkerFile = new WebWorkerFile(); |
|
|
|
|
|
|
|
|
|
const b64toBlob = (b64Data, contentType='', sliceSize=512) => { |
|
|
|
|
const b64toBlob = (b64Data, contentType = '', sliceSize = 512) => { |
|
|
|
|
const byteCharacters = atob(b64Data); |
|
|
|
|
const byteArrays = []; |
|
|
|
|
|
|
|
|
@ -3296,7 +3350,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
byteArrays.push(byteArray); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const blob = new Blob(byteArrays, {type: contentType}); |
|
|
|
|
const blob = new Blob(byteArrays, { type: contentType }); |
|
|
|
|
return blob; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3339,7 +3393,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
typeMessage = 'edit'; |
|
|
|
|
let chatReference = outSideMsg.editedMessageObj.signature; |
|
|
|
|
|
|
|
|
|
if(outSideMsg.editedMessageObj.chatReference){ |
|
|
|
|
if (outSideMsg.editedMessageObj.chatReference) { |
|
|
|
|
chatReference = outSideMsg.editedMessageObj.chatReference; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3380,10 +3434,10 @@ class ChatPage extends LitElement {
|
|
|
|
|
const identifier = `qchat_${id}`; |
|
|
|
|
let compressedFile = ''; |
|
|
|
|
await new Promise(resolve => { |
|
|
|
|
new Compressor( image, { |
|
|
|
|
new Compressor(image, { |
|
|
|
|
quality: .6, |
|
|
|
|
maxWidth: 1200, |
|
|
|
|
success(result){ |
|
|
|
|
success(result) { |
|
|
|
|
const file = new File([result], "name", { |
|
|
|
|
type: image.type |
|
|
|
|
}); |
|
|
|
@ -3405,9 +3459,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
try { |
|
|
|
|
await publishData({ |
|
|
|
|
registeredName: userName, |
|
|
|
|
file : compressedFile, |
|
|
|
|
file: compressedFile, |
|
|
|
|
service: 'QCHAT_IMAGE', |
|
|
|
|
identifier : identifier, |
|
|
|
|
identifier: identifier, |
|
|
|
|
parentEpml, |
|
|
|
|
metaData: undefined, |
|
|
|
|
uploadType: 'file', |
|
|
|
@ -3487,9 +3541,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
try { |
|
|
|
|
await publishData({ |
|
|
|
|
registeredName: userName, |
|
|
|
|
file : attachment, |
|
|
|
|
file: attachment, |
|
|
|
|
service: 'QCHAT_ATTACHMENT', |
|
|
|
|
identifier : identifier, |
|
|
|
|
identifier: identifier, |
|
|
|
|
parentEpml, |
|
|
|
|
metaData: undefined, |
|
|
|
|
uploadType: 'file', |
|
|
|
@ -3539,11 +3593,11 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let reactions = message.reactions || [] |
|
|
|
|
const findEmojiIndex = reactions.findIndex((reaction)=> reaction.type === outSideMsg.reaction) |
|
|
|
|
if(findEmojiIndex !== -1){ |
|
|
|
|
const findEmojiIndex = reactions.findIndex((reaction) => reaction.type === outSideMsg.reaction) |
|
|
|
|
if (findEmojiIndex !== -1) { |
|
|
|
|
let users = reactions[findEmojiIndex].users || [] |
|
|
|
|
const findUserIndex = users.findIndex((user)=> user.address === this.selectedAddress.address ) |
|
|
|
|
if(findUserIndex !== -1){ |
|
|
|
|
const findUserIndex = users.findIndex((user) => user.address === this.selectedAddress.address) |
|
|
|
|
if (findUserIndex !== -1) { |
|
|
|
|
users.splice(findUserIndex, 1) |
|
|
|
|
} else { |
|
|
|
|
users.push({ |
|
|
|
@ -3556,7 +3610,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
qty: users.length, |
|
|
|
|
users |
|
|
|
|
} |
|
|
|
|
if(users.length === 0){ |
|
|
|
|
if (users.length === 0) { |
|
|
|
|
reactions.splice(findEmojiIndex, 1) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -3581,7 +3635,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
} |
|
|
|
|
else if (this.repliedToMessageObj) { |
|
|
|
|
let chatReference = this.repliedToMessageObj.signature; |
|
|
|
|
if(this.repliedToMessageObj.chatReference){ |
|
|
|
|
if (this.repliedToMessageObj.chatReference) { |
|
|
|
|
chatReference = this.repliedToMessageObj.chatReference; |
|
|
|
|
} |
|
|
|
|
typeMessage = 'reply'; |
|
|
|
@ -3597,7 +3651,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
typeMessage = 'edit' |
|
|
|
|
let chatReference = this.editedMessageObj.signature |
|
|
|
|
|
|
|
|
|
if(this.editedMessageObj.chatReference){ |
|
|
|
|
if (this.editedMessageObj.chatReference) { |
|
|
|
|
chatReference = this.editedMessageObj.chatReference |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -3686,9 +3740,9 @@ class ChatPage extends LitElement {
|
|
|
|
|
const sendForwardRequest = async () => { |
|
|
|
|
|
|
|
|
|
const userInput = this.shadowRoot.getElementById("sendTo").value.trim(); |
|
|
|
|
if(!userInput && !this.forwardActiveChatHeadUrl.url) { |
|
|
|
|
if (!userInput && !this.forwardActiveChatHeadUrl.url) { |
|
|
|
|
let err4string = get("chatpage.cchange65"); |
|
|
|
|
getSendChatResponse(false, true, err4string ); |
|
|
|
|
getSendChatResponse(false, true, err4string); |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
let publicKey = { |
|
|
|
@ -3794,7 +3848,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
const recipientAddress = this.forwardActiveChatHeadUrl.url.split('/')[1]; |
|
|
|
|
this.openForwardOpen = false; |
|
|
|
|
if (isRecipient === true) { |
|
|
|
|
if(!publicKey.hasPubKey){ |
|
|
|
|
if (!publicKey.hasPubKey) { |
|
|
|
|
let err4string = get("chatpage.cchange39"); |
|
|
|
|
parentEpml.request('showSnackBar', `${err4string}`); |
|
|
|
|
getSendChatResponse(false); |
|
|
|
@ -3857,7 +3911,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
let chatBytesArray = null; |
|
|
|
|
|
|
|
|
|
await new Promise((res) => { |
|
|
|
|
worker.postMessage({chatBytes, path, difficulty}); |
|
|
|
|
worker.postMessage({ chatBytes, path, difficulty }); |
|
|
|
|
worker.onmessage = e => { |
|
|
|
|
chatBytesArray = e.data.chatBytesArray; |
|
|
|
|
nonce = e.data.nonce; |
|
|
|
@ -3877,7 +3931,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
const getSendChatResponse = (response, isForward, customErrorMessage) => { |
|
|
|
|
if (response === true) { |
|
|
|
|
this.resetChatEditor() |
|
|
|
|
if(isForward){ |
|
|
|
|
if (isForward) { |
|
|
|
|
let successString = get("blockpage.bcchange15"); |
|
|
|
|
parentEpml.request('showSnackBar', `${successString}`); |
|
|
|
|
} |
|
|
|
@ -3896,7 +3950,7 @@ class ChatPage extends LitElement {
|
|
|
|
|
let err2string = get("chatpage.cchange21"); |
|
|
|
|
parentEpml.request('showSnackBar', `${customErrorMessage || err2string}`); |
|
|
|
|
} |
|
|
|
|
if(isForward && response !== true){ |
|
|
|
|
if (isForward && response !== true) { |
|
|
|
|
this.isLoading = false; |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|