예제 #1
0
파일: core.cpp 프로젝트: rohilsurana/qTox
QString Core::getPeerName(const ToxID& id) const
{
    QString name;
    CUserId cid(id.toString());

    uint32_t friendId = tox_friend_by_public_key(tox, (uint8_t*)cid.data(), nullptr);
    if (friendId == std::numeric_limits<uint32_t>::max())
    {
        qWarning() << "Core::getPeerName: No such peer "+id.toString();
        return name;
    }

    const size_t nameSize = tox_friend_get_name_size(tox, friendId, nullptr);
    if (nameSize == SIZE_MAX)
    {
        //qDebug() << "Core::getPeerName: Can't get name of friend "+QString().setNum(friendId)+" ("+id.toString()+")";
        return name;
    }

    uint8_t* cname = new uint8_t[nameSize<TOX_MAX_NAME_LENGTH ? TOX_MAX_NAME_LENGTH : nameSize];
    if (tox_friend_get_name(tox, friendId, cname, nullptr) == false)
    {
        qWarning() << "Core::getPeerName: Can't get name of friend "+QString().setNum(friendId)+" ("+id.toString()+")";
        delete[] cname;
        return name;
    }

    name = name.fromLocal8Bit((char*)cname, nameSize);
    delete[] cname;
    return name;
}
예제 #2
0
파일: settings.cpp 프로젝트: gale320/qTox
void Settings::setAutoAcceptDir(const ToxID &id, const QString& dir)
{
    QString key = id.publicKey;

    auto it = friendLst.find(key);
    if (it != friendLst.end())
    {
        it->autoAcceptDir = dir;
    } else {
        updateFriendAdress(id.toString());
        setAutoAcceptDir(id, dir);
    }
}
예제 #3
0
파일: widget.cpp 프로젝트: AWeinb/qTox
void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QString& message, bool isAction)
{
    Group* g = GroupList::findGroup(groupnumber);
    if (!g)
        return;

    ToxID author = Core::getInstance()->getGroupPeerToxID(groupnumber, peernumber);
    bool targeted = !author.isMine() && (message.contains(nameMention) || message.contains(sanitizedNameMention));
    if (targeted && !isAction)
        g->getChatForm()->addAlertMessage(author, message, QDateTime::currentDateTime());
    else
        g->getChatForm()->addMessage(author, message, isAction, QDateTime::currentDateTime(), true);

    g->setEventFlag(static_cast<GenericChatroomWidget*>(g->getGroupWidget()) != activeChatroomWidget);

    if (targeted || Settings::getInstance().getGroupAlwaysNotify())
        newMessageAlert(g->getGroupWidget());

    if (targeted)
        g->setMentionedFlag(true); // useful for highlighting line or desktop notifications

    g->getGroupWidget()->updateStatusLight();
}
예제 #4
0
파일: chatform.cpp 프로젝트: rokups/qTox
void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
{
    QDateTime now = QDateTime::currentDateTime();

    if (since > now)
        return;

    if (earliestMessage)
    {
        if (*earliestMessage < since)
            return;
        if (*earliestMessage < now)
        {
            now = *earliestMessage;
            now = now.addMSecs(-1);
        }
    }

    auto msgs = HistoryKeeper::getInstance()->getChatHistory(HistoryKeeper::ctSingle, f->getToxID().publicKey, since, now);

    ToxID storedPrevId;
    std::swap(storedPrevId, previousId);
    QList<ChatActionPtr> historyMessages;

    QDate lastDate(1,0,0);
    for (const auto &it : msgs)
    {
        // Show the date every new day
        QDateTime msgDateTime = it.timestamp.toLocalTime();
        QDate msgDate = msgDateTime.date();
        if (msgDate > lastDate)
        {
            lastDate = msgDate;
            historyMessages.append(genSystemInfoAction(msgDate.toString(),"",QDateTime()));
        }

        // Show each messages
        ToxID msgSender = ToxID::fromString(it.sender);
        MessageActionPtr ca = genMessageActionAction(msgSender, it.message, false, msgDateTime);
        if (it.isSent || !msgSender.isMine())
        {
            ca->markAsSent();
        } else {
            if (processUndelivered)
            {
                int rec;
                if (ca->isAction())
                    rec = Core::getInstance()->sendAction(f->getFriendID(), ca->getRawMessage());
                else
                    rec = Core::getInstance()->sendMessage(f->getFriendID(), ca->getRawMessage());
                registerReceipt(rec, it.id, ca);
            }
        }
        historyMessages.append(ca);
    }
    std::swap(storedPrevId, previousId);

    int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();

    if (earliestMessage != nullptr)
        *earliestMessage = since;

    chatWidget->insertMessagesTop(historyMessages);

    savedSliderPos = chatWidget->verticalScrollBar()->maximum() - savedSliderPos;
    chatWidget->verticalScrollBar()->setValue(savedSliderPos);
}