Ejemplo n.º 1
0
void Widget::onFriendMessageReceived(int friendId, const QString& message, bool isAction)
{
    Friend* f = FriendList::findFriend(friendId);
    if (!f)
        return;

    QDateTime timestamp = QDateTime::currentDateTime();
    f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp);

    if (isAction)
        HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, "/me " + message, f->getToxID().publicKey, timestamp);
    else
        HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, message, f->getToxID().publicKey, timestamp);

    if (activeChatroomWidget != nullptr)
    {
        if ((static_cast<GenericChatroomWidget*>(f->getFriendWidget()) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
        {
            f->setEventFlag(true);
            newMessageAlert();
        }
    }
    else
    {
        f->setEventFlag(true);
        newMessageAlert();
    }

    f->getFriendWidget()->updateStatusLight();
}
Ejemplo n.º 2
0
void Widget::onFriendMessageReceived(int friendId, const QString& message, bool isAction)
{
    Friend* f = FriendList::findFriend(friendId);
    if (!f)
        return;

    QDateTime timestamp = QDateTime::currentDateTime();
    f->getChatForm()->addMessage(f->getToxID(), message, isAction, timestamp, true);

    HistoryKeeper::getInstance()->addChatEntry(f->getToxID().publicKey, isAction ? "/me " + message : message,
                                               f->getToxID().publicKey, timestamp, true);

    f->setEventFlag(f->getFriendWidget() != activeChatroomWidget);
    newMessageAlert(f->getFriendWidget());
    f->getFriendWidget()->updateStatusLight();
}
Ejemplo n.º 3
0
Friend* FriendList::findFriend(const ToxID& userId)
{
    auto id = tox2id.find(userId.publicKey);
    if (id != tox2id.end())
    {
        Friend *f = findFriend(*id);
        if (!f)
            return nullptr;
        if (f->getToxID() == userId)
            return f;
    }

    return nullptr;
}
Ejemplo n.º 4
0
void FriendWidget::setFriendAlias()
{
    bool ok;
    Friend* f = FriendList::findFriend(friendId);

    QString alias = QInputDialog::getText(nullptr, tr("User alias"), tr("Alias:"), QLineEdit::Normal,
                                          f->getDisplayedName(), &ok);

    if (ok)
    {
        alias = alias.trimmed();
        alias.remove(QRegExp("[\t\n\v\f\r]"));
        alias = alias.left(128); // same as TOX_MAX_NAME_LENGTH
        f->setAlias(alias);
        Settings::getInstance().setFriendAlias(f->getToxID(), alias);
        hide();
        show();

        if (f->getFriendWidget()->isActive())
            Widget::getInstance()->setWindowTitle(f->getFriendWidget()->getName() + " - qTox");
    }
}