コード例 #1
0
JabberClient::MessageRequest::~MessageRequest()
{
    if (m_from.empty() || m_body.empty())
        return;
    Contact *contact;
    JabberUserData *data = m_client->findContact(m_from.c_str(), NULL, false, contact);
    if (data == NULL){
        data = m_client->findContact(m_from.c_str(), NULL, true, contact);
        if (data == NULL)
            return;
        contact->setTemporary(CONTACT_TEMP);
    }
    Message *msg;
	if (m_errorCode || !m_error.empty()){
		JabberMessageError *m = new JabberMessageError;
		m->setError(QString::fromUtf8(m_error.c_str()));
		m->setCode(m_errorCode);
		msg = m;
    }else if (m_subj.empty()){
        msg = new Message(MessageGeneric);
    }else{
        JabberMessage *m = new JabberMessage;
        m->setSubject(QString::fromUtf8(m_subj.c_str()));
        msg = m;
    }
    msg->setText(QString::fromUtf8(m_body.c_str()));
    msg->setFlags(MESSAGE_RECEIVED);
    msg->setClient(m_client->dataName(data).c_str());
    msg->setContact(contact->id());
    Event e(EventMessageReceived, msg);
    if (!e.process())
        delete msg;
}
コード例 #2
0
JabberClient::MessageRequest::~MessageRequest()
{
    if (m_from.empty())
        return;
    Contact *contact;
    JabberUserData *data = m_client->findContact(m_from.c_str(), NULL, false, contact);
    if (data == NULL) {
        data = m_client->findContact(m_from.c_str(), NULL, true, contact);
        if (data == NULL)
            return;
        contact->setTemporary(CONTACT_TEMP);
    }
    Message *msg = NULL;
    if (!m_id.empty()) {
        string typing_id;
        if (data->TypingId)
            typing_id = data->TypingId;
        string new_typing_id;
        bool bProcess = false;
        while (!typing_id.empty()) {
            string id = getToken(typing_id, ';');
            if (id == m_id) {
                if (!m_bCompose)
                    continue;
                bProcess = true;
            }
            if (!new_typing_id.empty())
                new_typing_id += ";";
            new_typing_id += id;
        }
        if (!bProcess && m_bCompose) {
            if (!new_typing_id.empty())
                new_typing_id += ";";
            new_typing_id += m_id;
        }
        if (set_str(&data->TypingId, new_typing_id.c_str())) {
            Event e(EventContactStatus, contact);
            e.process();
        }
    }
    if (m_errorCode || !m_error.empty()) {
        if (!m_bEvent) {
            JabberMessageError *m = new JabberMessageError;
            m->setError(QString::fromUtf8(m_error.c_str()));
            m->setCode(m_errorCode);
            msg = m;
        }
    } else if (m_bBody) {
        if (m_subj.empty()) {
            msg = new Message(MessageGeneric);
        } else {
            JabberMessage *m = new JabberMessage;
            m->setSubject(QString::fromUtf8(m_subj.c_str()));
            msg = m;
        }
    }
    if (msg == NULL)
        return;
    msg->setText(QString::fromUtf8(m_body.c_str()));
    msg->setFlags(MESSAGE_RECEIVED);
    msg->setClient(m_client->dataName(data).c_str());
    msg->setContact(contact->id());
    Event e(EventMessageReceived, msg);
    if (!e.process())
        delete msg;
}