void NinjamRoomWindow::addChatMessage(const Ninjam::User &user, const QString &message)
{
    QString userName = user.getName();

    bool isSystemVoteMessage = Gui::Chat::parseSystemVotingMessage(message).isValidVotingMessage();

    bool isChordProgressionMessage = false;
    if (!isSystemVoteMessage) {
        ChatChordsProgressionParser chordsParser;
        isChordProgressionMessage = chordsParser.containsProgression(message);
    }

    bool showBlockButton = canShowBlockButtonInChatMessage(userName);
    bool showTranslationButton = !isChordProgressionMessage;
    chatPanel->addMessage(userName, message, showTranslationButton, showBlockButton);

    static bool localUserWasVotingInLastMessage = false;

    if (isSystemVoteMessage) {
        Gui::Chat::SystemVotingMessage voteMessage = Gui::Chat::parseSystemVotingMessage(message);

        QTimer *expirationTimer = voteMessage.isBpiVotingMessage() ? bpiVotingExpiratonTimer : bpmVotingExpirationTimer;

        bool isFirstSystemVoteMessage = Gui::Chat::isFirstSystemVotingMessage(userName, message);
        if (isFirstSystemVoteMessage) { //starting a new votation round
            if (!localUserWasVotingInLastMessage) {  //don't create the vote button if local user is proposing BPI or BPM change
                createVoteButton(voteMessage);
            }
            else{ //if local user is proposing a bpi/bpm change the combos are disabled until the voting reach majority or expire
                if (voteMessage.isBpiVotingMessage())
                    ninjamPanel->setBpiComboPendingStatus(true);
                else
                    ninjamPanel->setBpmComboPendingStatus(true);
                if (QApplication::focusWidget()) //clear comboboxes focus when disabling
                    QApplication::focusWidget()->clearFocus();
            }
        }

        //timer is restarted in every vote
        expirationTimer->start(voteMessage.getExpirationTime() * 1000); //QTimer::start will cancel a previous voting expiration timer
    }
    else if (isChordProgressionMessage) {
        handleChordProgressionMessage(user, message);
    }

    localUserWasVotingInLastMessage = Gui::Chat::isLocalUserVotingMessage(message) && user.getName() == mainController->getUserName();
}
示例#2
0
void NinjamRoomWindow::addChatMessage(const Ninjam::User &user, const QString &message)
{
    bool isVoteMessage = !message.isNull() && message.toLower().startsWith(
        "[voting system] leading candidate:");
    bool isChordProgressionMessage = false;
    try{
        ChatChordsProgressionParser chordsParser;
        isChordProgressionMessage = chordsParser.containsProgression(message);
    }
    catch (...) {
        isChordProgressionMessage = false;// just in case
    }

    bool showTranslationButton = !isChordProgressionMessage;
    chatPanel->addMessage(user.getName(), message, showTranslationButton);

    if (isVoteMessage)
        handleVoteMessage(user, message);
    else if (isChordProgressionMessage)
        handleChordProgressionMessage(user, message);
}
示例#3
0
void NinjamRoomWindow::handleVoteMessage(const Ninjam::User &user, const QString &message)
{
    // local user is voting?
    static quint64 lastVoteCommand = 0;
    QString localUserFullName = mainController->getNinjamService()->getConnectedUserName();
    if (user.getFullName() == localUserFullName && message.toLower().contains("!vote"))
        lastVoteCommand = QDateTime::currentMSecsSinceEpoch();
    quint64 timeSinceLastVote = QDateTime::currentMSecsSinceEpoch() - lastVoteCommand;
    if (timeSinceLastVote >= 1000) {
        QString commandType = (message.toLower().contains("bpm")) ? "BPM" : "BPI";

        // [voting system] leading candidate: 1/2 votes for 12 BPI [each vote expires in 60s]
        int forIndex = message.indexOf("for");
        assert(forIndex >= 0);
        int spaceAfterValueIndex = message.indexOf(" ", forIndex + 4);
        QString voteValueString = message.mid(forIndex + 4, spaceAfterValueIndex - (forIndex + 4));
        int voteValue = voteValueString.toInt();

        if (commandType == "BPI")
            chatPanel->addBpiVoteConfirmationMessage(voteValue);
        else if (commandType == "BPM")// just in case
            chatPanel->addBpmVoteConfirmationMessage(voteValue);
    }
}