Exemple #1
0
void MessageManager::onPrivateMessage(const ChatMessage& aMessage, UserConnection* aUc) {
    bool myPM = aMessage.replyTo->getUser() == ClientManager::getInstance()->getMe();
    const UserPtr& user = myPM ? aMessage.to->getUser() : aMessage.replyTo->getUser();
    size_t wndCnt;
    {
        WLock l(cs);
        wndCnt = chats.size();
        auto i = chats.find(user);
        if (i != chats.end()) {
            //Debug purposes to see if this really ever happens!!
            if (aUc && !i->second->ccReady())
                LogManager::getInstance()->message("Message received via CCPM but frame not connected state! report to Night", LogManager::LOG_ERROR);

            i->second->handleMessage(aMessage); //We should have a listener in the frame
            return;
        }
    }

    Client* c = &aMessage.from->getClient();
    if (wndCnt > 200 || !myPM && isIgnoredOrFiltered(aMessage, c, true)) {
        DisconnectCCPM(user);
        return;
    }

    const auto& identity = aMessage.replyTo->getIdentity();
    if ((identity.isBot() && !SETTING(POPUP_BOT_PMS)) || (identity.isHub() && !SETTING(POPUP_HUB_PMS))) {
        c->Message(STRING(PRIVATE_MESSAGE_FROM) + " " + identity.getNick() + ": " + aMessage.format());
        return;
    }

    //This will result in creating a new window
    fire(MessageManagerListener::PrivateMessage(), aMessage);
}
void MessageManager::onPrivateMessage(const ChatMessagePtr& aMessage) {
	bool myPM = aMessage->getReplyTo()->getUser() == ClientManager::getInstance()->getMe();
	const UserPtr& user = myPM ? aMessage->getTo()->getUser() : aMessage->getReplyTo()->getUser();
	size_t wndCnt;
	{
		WLock l(cs);
		wndCnt = chats.size();
		auto i = chats.find(user);
		if (i != chats.end()) {
			i->second->handleMessage(aMessage); //We should have a listener in the frame
			return;
		}
	}

	auto c = aMessage->getFrom()->getClient();
	if (wndCnt > 200 || (!myPM && isIgnoredOrFiltered(aMessage, c.get(), true))) {
		DisconnectCCPM(user);
		return;
	}

	const auto& identity = aMessage->getReplyTo()->getIdentity();
	if ((identity.isBot() && !SETTING(POPUP_BOT_PMS)) || (identity.isHub() && !SETTING(POPUP_HUB_PMS))) {
		c->Message(STRING(PRIVATE_MESSAGE_FROM) + " " + identity.getNick() + ": " + aMessage->format());
		return;
	}

	auto chat = addChat(HintedUser(user, aMessage->getReplyTo()->getClient()->getHubUrl()), true);
	chat->handleMessage(aMessage);

	if (AirUtil::getAway() && (!SETTING(NO_AWAYMSG_TO_BOTS) || !user->isSet(User::BOT))) {
		ParamMap params;
		aMessage->getFrom()->getIdentity().getParams(params, "user", false);

		string error;
		chat->sendMessage(AirUtil::getAwayMessage(c->get(HubSettings::AwayMsg), params), error, false);
	}
}