示例#1
0
void FacebookChatService::unreadMessageReceived(const QFacebookDownloadUnreadMessageResult &result)
{
    if (m_receivedMessages.find(result.messageId) != std::end(m_receivedMessages))
        return;

    m_receivedMessages.insert(std::make_pair(result.messageId, QDateTime::currentDateTime()));

    auto contact = m_contactManager->byId(account(), QString::number(result.senderUid), ActionCreateAndAdd);
    auto chat = ChatTypeContact::findChat(m_chatManager, m_chatStorage, contact, ActionCreateAndAdd);
    auto message = m_messageStorage->create();
    message.setMessageChat(chat);
    message.setType(MessageType::MessageTypeReceived);
    message.setMessageSender(contact);
    message.setSendDate(result.timestamp);
    message.setReceiveDate(QDateTime::currentDateTime());
    message.setContent(normalizeHtml(plainToHtml(result.text)));

    emit messageReceived(message);
}
示例#2
0
void JabberChatService::handleReceivedMessage(const QXmppMessage &xmppMessage)
{
	if (!m_formattedStringFactory)
		return;

	m_chatStateService->extractReceivedChatState(xmppMessage);

	if (xmppMessage.body().isEmpty())
		return;

	if (xmppMessage.type() == QXmppMessage::Type::Error) // #1642
		return;

	auto message = xmppMessage.type() == QXmppMessage::GroupChat
		? m_roomChatService->handleReceivedMessage(xmppMessage)
		: handleNormalReceivedMessage(xmppMessage);
	if (message.isNull())
		return;

	message.setType(MessageTypeReceived);
	message.setSendDate(xmppMessage.stamp().toLocalTime());
	message.setReceiveDate(QDateTime::currentDateTime());

	auto body = xmppMessage.body();
	if (rawMessageTransformerService())
		body = QString::fromUtf8(rawMessageTransformerService()->transform(body.toUtf8(), message).rawContent());

	auto htmlBody = replacedNewLine(Qt::escape(body), QLatin1String("<br/>"));
	auto formattedString = m_formattedStringFactory.data()->fromHtml(htmlBody);
	if (!formattedString || formattedString->isEmpty())
		return;

	message.setContent(std::move(formattedString));

	auto id = xmppMessage.from();
	auto resourceIndex = id.indexOf('/');
	if (resourceIndex >= 0)
		id = id.mid(0, resourceIndex);
	m_contactMessageTypes.insert(id, xmppMessage.type());

	emit messageReceived(message);
}