How to get messages from selected topic

29 views
Skip to first unread message

Cong Luong Van

unread,
May 10, 2022, 12:27:56 AM5/10/22
to Tinode General
Here is code. But console.log nothing

function selectTopic = (topic) => {
       const t = tinode.getTopic(topic.name)

    if (!t.isSubscribed()) {
        let getQuery = t.startMetaQuery().withLaterDesc().withLaterSub().withLaterData(25)
        t.subscribe(getQuery.build())
            .then(() => handleMessages(topic.name))
    }
}

function handleMessages(topicId) => {
    const topic = tinode.getTopic(topicId)
    topic.messages((message) => {
        console.log('loop message', message)
    })
}

Gene

unread,
May 10, 2022, 1:25:33 PM5/10/22
to Tinode General
On Monday, May 9, 2022 at 9:27:56 PM UTC-7 Cong Luong Van wrote:
Here is code. But console.log nothing

function selectTopic = (topic) => {
       const t = tinode.getTopic(topic.name)

    if (!t.isSubscribed()) {
        let getQuery = t.startMetaQuery().withLaterDesc().withLaterSub().withLaterData(25)
        t.subscribe(getQuery.build())
            .then(() => handleMessages(topic.name))

This promise gets resolved on subscription confirmation, before the messages are received. See here:
Reply all
Reply to author
Forward
0 new messages