Example #1
0
Jid JabberResourceService::bestChatJid(const Chat &chat) const
{
    if (!chat)
        return Jid{};

    auto chatType = m_chatTypeManager->chatType(chat.type());
    if (!chatType)
        return Jid{};

    if (chatType->name() == "Contact")
    {
        Q_ASSERT(1 == chat.contacts().size());
        return bestContactJid(chat.contacts().toContact());
    }

    if (chatType->name() == "Room")
    {
        auto details = qobject_cast<ChatDetailsRoom *>(chat.details());
        Q_ASSERT(details);

        return Jid::parse(details->room());
    }

    return Jid{};
}
Example #2
0
bool FacebookChatService::sendRawMessage(const Chat &chat, const QByteArray &rawMessage)
{
    auto contact = *chat.contacts().begin();
    m_facebookSession.sendMessage(contact.id().toULongLong(), rawMessage);

    return true;
}
Example #3
0
void Firewall::filterOutgoingMessage(Chat chat, QString &msg, bool &stop)
{
    Q_UNUSED(msg)
    kdebugf();

    foreach (const Contact &contact, chat.contacts())
    {
        Chat chat = ChatManager::instance()->findChat(ContactSet(contact), false);
        if (!chat)
            continue;

        if (contact.ownerBuddy().isAnonymous() && ChatWidgetManager::instance()->byChat(chat, false))
            Passed.insert(contact);
    }

    if (SafeSending)
    {
        foreach (const Contact &contact, chat.contacts())
        {
            Buddy buddy = contact.ownerBuddy();

            BuddyFirewallData *bfd = 0;
            if (buddy.data())
                bfd = buddy.data()->moduleStorableData<BuddyFirewallData>("firewall-secured-sending", Firewall::instance(), false);

            if (!bfd || !bfd->securedSending())
                return;

            if (!SecuredTemporaryAllowed.contains(buddy))
            {
                switch (QMessageBox::warning(0, "Kadu", tr("Are you sure you want to send this message?"), tr("&Yes"), tr("Yes and allow until chat closed"), tr("&No"), 2, 2))
                {
                default:
                    stop = true;
                    return;
                case 0:
                    return;
                case 1:
                    SecuredTemporaryAllowed.insert(buddy);
                    return;
                }
            }
        }
    }

    kdebugf2();
}
Example #4
0
bool GaduChatService::sendMessage(const Chat &chat, FormattedMessage &message, bool silent)
{
	kdebugf();

	QString plain = message.toPlain();
	QList<Contact> contacts = chat.contacts().toContactList();

	if (plain.isEmpty()) // for image sending
		message.prepend(FormattedMessagePart(" ", false, false, false, QColor(0, 0, 0)));

	unsigned int uinsCount = 0;
	unsigned int formatsSize = 0;
	QScopedArrayPointer<unsigned char> formats(GaduFormatter::createFormats(Protocol->account(), message, formatsSize));
	bool stop = false;

	kdebugmf(KDEBUG_INFO, "\n%s\n", (const char *)unicode2latin(plain));

	QByteArray data = plain.toUtf8();

	emit filterRawOutgoingMessage(chat, data, stop);
	plain = QString::fromUtf8(data);
	emit filterOutgoingMessage(chat, plain, stop);

	if (stop)
	{
		kdebugmf(KDEBUG_FUNCTION_END, "end: filter stopped processing\n");
		return false;
	}

	if (data.length() >= 2000)
	{
		MessageDialog::show("dialog-warning", tr("Kadu"), tr("Filtered message too long (%1>=%2)").arg(data.length()).arg(2000));
		kdebugmf(KDEBUG_FUNCTION_END, "end: filtered message too long\n");
		return false;
	}

	uinsCount = contacts.count();

	int messageId = -1;
	if (uinsCount > 1)
	{
		QScopedArrayPointer<UinType> uins(new UinType[uinsCount]);
		unsigned int i = 0;

		foreach (const Contact &contact, contacts)
			uins[i++] = Protocol->uin(contact);

		if (formatsSize)
			messageId = gg_send_message_confer_richtext(
					Protocol->gaduSession(), GG_CLASS_CHAT, uinsCount, uins.data(), (unsigned char *)data.data(),
					formats.data(), formatsSize);
		else
			messageId = gg_send_message_confer(
					Protocol->gaduSession(), GG_CLASS_CHAT, uinsCount, uins.data(), (unsigned char *)data.data());
	}
void AggregateChatManager::chatRemoved(const Chat &chat)
{
	BuddySet buddies = chat.contacts().toBuddySet();

	if (!AggregateChats.contains(buddies))
		return;

	AggregateChats[buddies].removeAll(chat);
	if (AggregateChats[buddies].isEmpty())
		AggregateChats.remove(buddies);
}
void AggregateChatManager::chatAdded(const Chat &chat)
{
	BuddySet buddies = chat.contacts().toBuddySet();

	if (!AggregateChats.contains(buddies))
	{
		QList<Chat> chats;
		chats.append(chat);
		AggregateChats.insert(buddies, chats);
	}
	else
		AggregateChats[buddies].append(chat);
}
Example #7
0
bool Firewall::checkConference(const Chat &chat)
{
    kdebugf();

    if (!IgnoreConferences)
        return false;

    if (chat.contacts().count() < 2)
        return false;

    foreach (const Contact &contact, chat.contacts())
    {
        if (!contact.ownerBuddy().isAnonymous() || Passed.contains(contact))
        {
            kdebugf2();
            return false;
        }
    }

    kdebugf2();
    return true;
}
Chat AggregateChatManager::aggregateChat(const Chat &chat)
{
	return aggregateChat(chat.contacts().toBuddySet());
}
Example #9
0
bool Firewall::checkChat(const Chat &chat, const Contact &sender, const QString &message, bool &ignore)
{
    kdebugf();

    if (!CheckChats)
        return false;

    // konferencja
    if (chat.contacts().count() > 1)
    {
        kdebugf2();
        return false;
    }

    if (!sender.ownerBuddy().isAnonymous() || Passed.contains(sender))
    {
        kdebugf2();
        return false;
    }

    if (chat.chatAccount().statusContainer()->status().type() == "Invisible" && DropAnonymousWhenInvisible)
    {
        writeLog(sender, tr("Chat with anonim silently dropped.\n") + "----------------------------------------------------\n");

        kdebugf2();
        return true;
    }

    if (IgnoreInvisible)
    {
        if (sender.currentStatus().isDisconnected())
        {
            QDateTime *dateTime = chat.chatAccount().data()->moduleData<QDateTime>("firewall-account-connected");
            if (dateTime && (*dateTime < QDateTime::currentDateTime()))
            {
                Protocol *protocol = chat.chatAccount().protocolHandler();
                if (!protocol)
                {
                    kdebugf2();
                    return false;
                }

                ChatService *chatService = protocol->chatService();
                if (!chatService)
                {
                    kdebugf2();
                    return false;
                }

                chatService->sendMessage(chat, tr("This message has been generated AUTOMATICALLY!\n\nI'm a busy person and I don't have time for stupid chats with the persons hiding itself. If you want to talk with me change the status to Online or Busy first."), true);
            }

            writeLog(sender, tr("Chat with invisible anonim ignored.\n") + "----------------------------------------------------\n");

            kdebugf2();
            return true;
        }
    }

    if (pattern.exactMatch(message.simplified()))
    {
        Passed.insert(sender);

        if (Confirmation)
        {
            Protocol *protocol = chat.chatAccount().protocolHandler();
            if (!protocol)
            {
                kdebugf2();
                return false;
            }

            ChatService *chatService = protocol->chatService();
            if (!chatService)
            {
                kdebugf2();
                return false;
            }

            chatService->sendMessage(chat, ConfirmationText, true);
        }

        writeLog(sender, tr("User wrote right answer!\n") + "----------------------------------------------------\n");

        ignore = true;

        kdebugf2();
        return false;
    }
    else
    {
        if (LastContact != sender && Search)
        {
            SearchWindow *sd = new SearchWindow(Core::instance()->kaduWindow(), sender.ownerBuddy());
            sd->show();
            sd->firstSearch();

            LastContact = sender;
        }

        kdebugm(KDEBUG_INFO, "%s\n", qPrintable(message));

        QDateTime *dateTime = chat.chatAccount().data()->moduleData<QDateTime>("firewall-account-connected");

        if (dateTime && (*dateTime < QDateTime::currentDateTime()))
        {
            Protocol *protocol = chat.chatAccount().protocolHandler();
            if (!protocol)
            {
                kdebugf2();
                return false;
            }

            ChatService *chatService = protocol->chatService();
            if (!chatService)
            {
                kdebugf2();
                return false;
            }

            chatService->sendMessage(chat, ConfirmationQuestion, true);
        }

        kdebugf2();
        return true;
    }
}