Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pagination in getInbox. #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ class MessageService {
this.page = page
}

async getInbox() {
// TODO: add pagination
async getInbox(start=0, limit=-1) {
await this.page.waitForNavigation({ waitUntil: 'load' })
await this.page.waitForSelector('body > mw-app > mw-bootstrap > div > main > mw-main-container > div > mw-main-nav > mws-conversations-list > nav > div.conv-container.ng-star-inserted > mws-conversation-list-item')

const inbox = await this.page.evaluate(() => {
const inbox = await this.page.evaluate((start, limit) => {
function evalConvoElement (conversation: Element) {
const props: Conversation = {
unread: false, // querySelector find .unread class
Expand Down Expand Up @@ -49,13 +48,20 @@ class MessageService {

const conversations = document.querySelectorAll("body > mw-app > mw-bootstrap > div > main > mw-main-container > div > mw-main-nav > mws-conversations-list > nav > div.conv-container.ng-star-inserted > mws-conversation-list-item")
const msgs = []
var i =0
for (const conversation of conversations) {
if (conversation) {
msgs.push(evalConvoElement(conversation))
if(limit >= 0 && i>limit+start) {
break
}
if(i>=start){
msgs.push(evalConvoElement(conversation))
}
i++
}
}
return msgs
})
}, start, limit)
return inbox
}

Expand Down