예제 #1
0
void QXmppRosterManager::rosterIqReceived(const QXmppRosterIq& rosterIq)
{
    bool isInitial = (m_rosterReqId == rosterIq.id());

    switch(rosterIq.type())
    {
    case QXmppIq::Set:
        {
            // send result iq
            QXmppIq returnIq(QXmppIq::Result);
            returnIq.setId(rosterIq.id());
            m_stream->sendPacket(returnIq);

            // store updated entries and notify changes
            const QList<QXmppRosterIq::Item> items = rosterIq.items();
            for (int i = 0; i < items.count(); i++)
            {
                QString bareJid = items.at(i).bareJid();
                m_entries[bareJid] = items.at(i);
                emit rosterChanged(bareJid);
            }

            // when contact subscribes user...user sends 'subscribed' presence 
            // then after recieving following iq user requests contact for subscription
            
            // check the "from" is newly added in the roster...and remove this ask thing...and do this for all items
            QXmppRosterIq::Item item = items.at(0);
            if (!item.bareJid().isEmpty() &&
                item.subscriptionType() == QXmppRosterIq::Item::From &&
                item.subscriptionStatus().isEmpty())
            {
                QXmppPresence presence;
                presence.setTo(item.bareJid());
                presence.setType(QXmppPresence::Subscribe);
                m_stream->sendPacket(presence);
            }
        }
        break;
    case QXmppIq::Result:
        {
            QList<QXmppRosterIq::Item> items = rosterIq.items();
            for(int i = 0; i < items.count(); ++i)
            {
                QString bareJid = items.at(i).bareJid();
                m_entries[bareJid] = items.at(i);
                if (!isInitial)
                    emit rosterChanged(bareJid);
            }
            if (isInitial)
            {
                m_isRosterReceived = true;
                emit rosterReceived();
            }
            break;
        }
    default:
        break;
    }
}
예제 #2
0
int CUserInfoXmpp::UpdateUserInfo(const QXmppRosterIq::Item &rosterItem)
{
    if(m_szJid.isEmpty())
        m_szJid = rosterItem.bareJid();
    m_Groups = rosterItem.groups();
    SetName(rosterItem.name());
    m_subscriptionType = FromQxmppSubscriptionType(rosterItem.subscriptionType());
    return 0;
}
예제 #3
0
int CFrmUserList::InsertUser(QXmppRosterIq::Item rosterItem)
{
    int nRet = 0;
    CRoster* pRoster = NULL;
    QMap<QString, CRoster*>::iterator itRosters;
    itRosters = m_Rosters.find(rosterItem.bareJid());
    if(m_Rosters.end() == itRosters)
    {
        //新建好友对象实例  
        pRoster = new CRoster(rosterItem);
        m_Rosters.insert(pRoster->BareJid(), pRoster);
    }
    else
    {
        LOG_MODEL_ERROR("Roster", qPrintable("Error:User had existed"));
        return -1;
    }

    nRet = UpdateGroup(pRoster, rosterItem.groups());

    return nRet;
}