mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-14 11:15:50 +00:00
ability to fetch after and before, max 100 msgs
This commit is contained in:
parent
657409a028
commit
adfe69cce3
@ -1354,6 +1354,7 @@ class ChatPage extends LitElement {
|
|||||||
this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light'
|
this.theme = localStorage.getItem('qortalTheme') ? localStorage.getItem('qortalTheme') : 'light'
|
||||||
this.updateMessageHash = {}
|
this.updateMessageHash = {}
|
||||||
this.addToUpdateMessageHashmap = this.addToUpdateMessageHashmap.bind(this)
|
this.addToUpdateMessageHashmap = this.addToUpdateMessageHashmap.bind(this)
|
||||||
|
this.getAfterMessages = this.getAfterMessages.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpenGifModal(value) {
|
setOpenGifModal(value) {
|
||||||
@ -2488,6 +2489,7 @@ class ChatPage extends LitElement {
|
|||||||
.messages=${this.messagesRendered}
|
.messages=${this.messagesRendered}
|
||||||
.escapeHTML=${escape}
|
.escapeHTML=${escape}
|
||||||
.getOldMessage=${this.getOldMessage}
|
.getOldMessage=${this.getOldMessage}
|
||||||
|
.getAfterMessages=${this.getAfterMessages}
|
||||||
.setRepliedToMessageObj=${(val) => this.setRepliedToMessageObj(val)}
|
.setRepliedToMessageObj=${(val) => this.setRepliedToMessageObj(val)}
|
||||||
.setEditedMessageObj=${(val) => this.setEditedMessageObj(val)}
|
.setEditedMessageObj=${(val) => this.setEditedMessageObj(val)}
|
||||||
.sendMessage=${(val) => this._sendMessage(val)}
|
.sendMessage=${(val) => this._sendMessage(val)}
|
||||||
@ -2630,8 +2632,8 @@ class ChatPage extends LitElement {
|
|||||||
_publicKey: this._publicKey,
|
_publicKey: this._publicKey,
|
||||||
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
||||||
}));
|
}));
|
||||||
|
const lengthOfExistingMsgs = this.messagesRendered
|
||||||
this.messagesRendered = [...decodeMsgs, ...this.messagesRendered].sort(function (a, b) {
|
this.messagesRendered = [...decodeMsgs, ...this.messagesRendered.slice(0, 80)].sort(function (a, b) {
|
||||||
return a.timestamp
|
return a.timestamp
|
||||||
- b.timestamp
|
- b.timestamp
|
||||||
})
|
})
|
||||||
@ -2665,7 +2667,79 @@ class ChatPage extends LitElement {
|
|||||||
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
||||||
}));
|
}));
|
||||||
|
|
||||||
this.messagesRendered = [...decodeMsgs, ...this.messagesRendered].sort(function (a, b) {
|
this.messagesRendered = [...decodeMsgs, ...this.messagesRendered.slice(0,80)].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)
|
||||||
|
|
||||||
|
if (findElement) {
|
||||||
|
findElement.scrollIntoView({ behavior: 'auto', block: 'center' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async getAfterMessages(scrollElement) {
|
||||||
|
const firstMsg = this.messagesRendered.at(-1)
|
||||||
|
const timestamp = scrollElement.messageObj.timestamp
|
||||||
|
|
||||||
|
if (this.isReceipient) {
|
||||||
|
const getInitialMessages = await parentEpml.request('apiCall', {
|
||||||
|
type: 'api',
|
||||||
|
url: `/chat/messages?involving=${window.parent.reduxStore.getState().app.selectedAddress.address}&involving=${this._chatId}&limit=20&reverse=true&after=${timestamp}&haschatreference=false&encoding=BASE64`
|
||||||
|
})
|
||||||
|
|
||||||
|
const decodeMsgs = getInitialMessages.map((eachMessage) => {
|
||||||
|
return this.decodeMessage(eachMessage)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
queue.push(() => replaceMessagesEdited({
|
||||||
|
decodedMessages: decodeMsgs,
|
||||||
|
parentEpml,
|
||||||
|
isReceipient: this.isReceipient,
|
||||||
|
decodeMessageFunc: this.decodeMessage,
|
||||||
|
_publicKey: this._publicKey,
|
||||||
|
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
||||||
|
}));
|
||||||
|
this.messagesRendered = [ ...this.messagesRendered.slice(-80), ...decodeMsgs].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)
|
||||||
|
|
||||||
|
if (findElement) {
|
||||||
|
findElement.scrollIntoView({ behavior: 'auto', block: 'center' })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const getInitialMessages = await parentEpml.request('apiCall', {
|
||||||
|
type: 'api',
|
||||||
|
url: `/chat/messages?txGroupId=${Number(this._chatId)}&limit=20&reverse=true&after=${timestamp}&haschatreference=false&encoding=BASE64`
|
||||||
|
})
|
||||||
|
|
||||||
|
const decodeMsgs = getInitialMessages.map((eachMessage) => {
|
||||||
|
return this.decodeMessage(eachMessage)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
queue.push(() => replaceMessagesEdited({
|
||||||
|
decodedMessages: decodeMsgs,
|
||||||
|
parentEpml,
|
||||||
|
isReceipient: this.isReceipient,
|
||||||
|
decodeMessageFunc: this.decodeMessage,
|
||||||
|
_publicKey: this._publicKey,
|
||||||
|
addToUpdateMessageHashmap: this.addToUpdateMessageHashmap
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.messagesRendered = [...this.messagesRendered.slice(-80), ...decodeMsgs].sort(function (a, b) {
|
||||||
return a.timestamp
|
return a.timestamp
|
||||||
- b.timestamp
|
- b.timestamp
|
||||||
})
|
})
|
||||||
@ -2682,7 +2756,6 @@ class ChatPage extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async addToUpdateMessageHashmap(array){
|
async addToUpdateMessageHashmap(array){
|
||||||
console.log({array})
|
|
||||||
const viewElement = this.shadowRoot.querySelector('chat-scroller').shadowRoot.getElementById('viewElement')
|
const viewElement = this.shadowRoot.querySelector('chat-scroller').shadowRoot.getElementById('viewElement')
|
||||||
const originalScrollTop = viewElement.scrollTop;
|
const originalScrollTop = viewElement.scrollTop;
|
||||||
const originalScrollHeight = viewElement.scrollHeight;
|
const originalScrollHeight = viewElement.scrollHeight;
|
||||||
|
@ -172,6 +172,7 @@ class ChatScroller extends LitElement {
|
|||||||
theme: { type: String, reflect: true },
|
theme: { type: String, reflect: true },
|
||||||
getNewMessage: { attribute: false },
|
getNewMessage: { attribute: false },
|
||||||
getOldMessage: { attribute: false },
|
getOldMessage: { attribute: false },
|
||||||
|
getAfterMessages: {attribute: false},
|
||||||
escapeHTML: { attribute: false },
|
escapeHTML: { attribute: false },
|
||||||
messages: { type: Array },
|
messages: { type: Array },
|
||||||
hideMessages: { type: Array },
|
hideMessages: { type: Array },
|
||||||
@ -304,6 +305,8 @@ class ChatScroller extends LitElement {
|
|||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
<div style=${"height: 1px;"} id='downObserver'></div>
|
<div style=${"height: 1px;"} id='downObserver'></div>
|
||||||
|
<!-- <div style=${"height: 1px; margin-top: -100px"} id='bottomObserverForFetchingMessages'></div> -->
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
@ -399,6 +402,9 @@ class ChatScroller extends LitElement {
|
|||||||
_getOldMessage(_scrollElement) {
|
_getOldMessage(_scrollElement) {
|
||||||
this.getOldMessage(_scrollElement)
|
this.getOldMessage(_scrollElement)
|
||||||
}
|
}
|
||||||
|
_getAfterMessages(_scrollElement) {
|
||||||
|
this.getAfterMessages(_scrollElement)
|
||||||
|
}
|
||||||
|
|
||||||
_getOldMessageAfter(_scrollElement) {
|
_getOldMessageAfter(_scrollElement) {
|
||||||
this.getOldMessageAfter(_scrollElement)
|
this.getOldMessageAfter(_scrollElement)
|
||||||
@ -417,11 +423,11 @@ class ChatScroller extends LitElement {
|
|||||||
|
|
||||||
_downObserverHandler(entries) {
|
_downObserverHandler(entries) {
|
||||||
if (!entries[0].isIntersecting) {
|
if (!entries[0].isIntersecting) {
|
||||||
let _scrollElement = entries[0].target.previousElementSibling
|
|
||||||
// this._getOldMessageAfter(_scrollElement)
|
|
||||||
this.showLastMessageRefScroller(true)
|
this.showLastMessageRefScroller(true)
|
||||||
} else {
|
} else {
|
||||||
|
let _scrollElement = entries[0].target.previousElementSibling
|
||||||
this.showLastMessageRefScroller(false)
|
this.showLastMessageRefScroller(false)
|
||||||
|
this._getAfterMessages(_scrollElement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,9 +443,7 @@ class ChatScroller extends LitElement {
|
|||||||
|
|
||||||
downElementObserver() {
|
downElementObserver() {
|
||||||
const options = {
|
const options = {
|
||||||
root: this.viewElement,
|
|
||||||
rootMargin: '0px',
|
|
||||||
threshold: 1
|
|
||||||
}
|
}
|
||||||
// identify an element to observe
|
// identify an element to observe
|
||||||
const elementToObserve = this.downObserverElement
|
const elementToObserve = this.downObserverElement
|
||||||
|
Loading…
x
Reference in New Issue
Block a user