qxmpp-project / qxmpp

Cross-platform C++ XMPP client and server library
408 stars 197 forks source link

Empty Roster #494

Closed timakas closed 1 year ago

timakas commented 1 year ago

For some reason after I connect to my openfire server and login successfully, the returned roster is empty, even though I know there are jid's already in the logged in users roster. Can someone please let me know where I could be going wrong? I've followed the "example_2_rosterHandling" setup.

MainClient::MainClient(QObject *parent) : QXmppClient(parent), m_rosterManager(findExtension()) { connect(this, &QXmppClient::messageReceived, this, &MainClient::messageReceived); connect(this, &QXmppClient::connected, this, &MainClient::onConnected); connect(this, &QXmppClient::disconnected, this, &MainClient::onDisconnected); connect(this, &QXmppClient::error, this, &MainClient::onXmppError); connect(this, &QXmppClient::stateChanged, this, &MainClient::onStateChanged); connect(m_rosterManager, &QXmppRosterManager::rosterReceived, this, &MainClient::rosterReceived); }

void MainClient::rosterReceived() { qInfo() << "Roster Slot Triggered";

const QStringList jids = m_rosterManager->getRosterBareJids();

if(jids.isEmpty()){
    qInfo()<< "Roster is Empty";

} else {
    for(const QString &bareJid : jids){
        QString name = m_rosterManager->getRosterEntry(bareJid).name();
        if(name.isEmpty()){
            name = "-";
        }
        qDebug("Roster Received: %s [%s]", qPrintable(bareJid), qPrintable(name));
    }
}
if(bool test = m_rosterManager->isRosterReceived()){
    qInfo() << "Roster Received Status = " << test;
}

}

App Output

I libmain_app_x86_64.so: Connecting... I libmain_app_x86_64.so: State: QXmppClient::ConnectingState I libmain_app_x86_64.so: State: QXmppClient::ConnectingState I libmain_app_x86_64.so: State: QXmppClient::ConnectingState I libmain_app_x86_64.so: Connected... I libmain_app_x86_64.so: State: QXmppClient::ConnectedState I libmain_app_x86_64.so: Roster Slot Triggered I libmain_app_x86_64.so: Roster is Empty I libmain_app_x86_64.so: Roster Received Status = true

timakas commented 1 year ago

My bad, it turns out I had to set the Subscription for each contact in the roster on the Openfire server. It works now.