Skip to content
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
25 changes: 25 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export default class WhatsAppAPI implements PlatformAPI {
if (this.connState.connection === 'close') {
throw this.connState.lastDisconnect?.error || new ConnectionError('failed to open')
}
this.getSubscribedNewsletters()
} catch (error) {
this.logger.info({ msSinceConnect, trace: error.stack }, 'connect failed')

Expand Down Expand Up @@ -1153,4 +1154,28 @@ export default class WhatsAppAPI implements PlatformAPI {
await repo.remove(expiredMessages)
} while (expiredMessages.length > 0)
}

private getSubscribedNewsletters = async () => {
const subscribedNewsletters = await this.client?.getSubscribedNewsletters()
if (subscribedNewsletters) {
await Promise.all(subscribedNewsletters.map(async newsletter => {
const thread = new DBThread()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right to use DBThread here or should we introduce a new DBNewsletter model?

thread.original = {
chat: {
id: newsletter.id,
name: newsletter.threadMetadata.name.text,
createdAt: newsletter.threadMetadata.creationTime,
},
Comment on lines +1164 to +1168

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: map remaining props here

metadata: undefined,
}
thread.shouldFireEvent = false
thread.mapFromOriginal(this)

await this.db.transaction(async db => {
await db.getRepository(DBThread).save(thread)
})
}))
}
return subscribedNewsletters
}
}