Example #1
0
bool ChatWidgetMessageHandler::shouldOpenChatWidget(const Chat &chat) const
{
	if (!m_chatWidgetMessageHandlerConfiguration.openChatOnMessage())
		return false;

	auto silentMode = m_silentModeService->isSilentOrAutoSilent();
	if (silentMode)
		return false;

	auto handler = chat.chatAccount().protocolHandler();
	if (!handler)
		return false;

	if (m_chatWidgetMessageHandlerConfiguration.openChatOnMessageOnlyWhenOnline())
		return StatusTypeGroup::Online == m_statusTypeManager->statusTypeData(handler->status().type()).typeGroup();
	else
		return true;
}
Example #2
0
void CenzorNotificationService::notifyCenzored(const Chat &chat)
{
	auto data = QVariantMap{};
	data.insert(QStringLiteral("account"), qVariantFromValue(chat.chatAccount()));
	data.insert(QStringLiteral("chat"), qVariantFromValue(chat));

	auto notification = Notification{};
	notification.type = m_cenzoredEvent.name();
	notification.icon = KaduIcon{"kadu_icons/blocking"};
	notification.title = (tr("Cenzor"));
	notification.text = normalizeHtml(HtmlString{tr("Message was cenzored")});
	notification.details = normalizeHtml(HtmlString{tr("Your interlocutor used obscene word and became admonished")});
	notification.callbacks.append("chat-open");
	notification.callbacks.append("ignore");

	m_notificationService->notify(notification);

}
Example #3
0
Chat ModelIndexListConverter::chatFromIndex(const QModelIndex &index) const
{
	switch (index.data(ItemTypeRole).toInt())
	{
		case ChatRole:
		{
			Chat chat = index.data(ChatRole).value<Chat>();
			if (chat.chatAccount())
				return chat;
			else
				return Chat::null;
		}
		case BuddyRole:
			return m_unreadMessageRepository->unreadMessageForBuddy(index.data(BuddyRole).value<Buddy>()).messageChat();
		case ContactRole:
			return m_unreadMessageRepository->unreadMessageForContact(index.data(ContactRole).value<Contact>()).messageChat();
	}

	return Chat::null;
}
Example #4
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;
    }
}
Example #5
0
void Firewall::filterIncomingMessage(Chat chat, Contact sender, QString &message, time_t time, bool &ignore)
{
    Q_UNUSED(time)

    Account account = chat.chatAccount();

    Protocol *protocol = account.protocolHandler();
    if (!protocol)
        return;

// emotikony s± sprawdzane nawet przy ³±czeniu
    const int min_interval_notify = 2000;

    if (CheckFloodingEmoticons)
    {
        if ((!EmoticonsAllowKnown || sender.ownerBuddy().isAnonymous()) && checkEmoticons(message))
        {
            ignore = true;
            if (LastNotify.elapsed() > min_interval_notify)
            {
                FirewallNotification::notify(chat, sender, tr("flooding DoS attack with emoticons!"));

                writeLog(sender, message);

                LastNotify.restart();
            }
            kdebugf2();
            return;
        }
    }

// atak floodem
    if (checkFlood())
    {
        ignore = true;
        if (LastNotify.elapsed() > min_interval_notify)
        {
            FirewallNotification::notify(chat, sender, tr("flooding DoS attack!"));

            writeLog(sender, message);

            LastNotify.restart();
        }
        kdebugf2();
        return;
    }

// ochrona przed anonimami
    if (checkChat(chat, sender, message, ignore))
        ignore = true;

// ochrona przed konferencjami
    if (checkConference(chat))
        ignore = true;

// wiadomosc zatrzymana. zapisz do loga i wyswietl dymek
    if (ignore)
    {
        if (message.length() > 50)
            FirewallNotification::notify(chat, sender, message.left(50).append("..."));
        else
            FirewallNotification::notify(chat, sender, message);

        writeLog(sender, message);

        if (WriteInHistory)
        {
            if (History::instance()->currentStorage())
            {
                Message msg = Message::create();
                msg.setContent(message);
                msg.setType(Message::TypeReceived);
                msg.setReceiveDate(QDateTime::currentDateTime());
                msg.setSendDate(QDateTime::fromTime_t(time));
                History::instance()->currentStorage()->appendMessage(msg);
            }
        }
    }

    kdebugf2();
}