ChatForm::ChatForm(Friend* chatFriend) : f(chatFriend) , callId{0}, isTyping{false} { nameLabel->setText(f->getDisplayedName()); avatar->setPixmap(QPixmap(":/img/contact_dark.svg"), Qt::transparent); statusMessageLabel = new CroppingLabel(); statusMessageLabel->setObjectName("statusLabel"); statusMessageLabel->setFont(Style::getFont(Style::Medium)); statusMessageLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize()); statusMessageLabel->setTextFormat(Qt::PlainText); callConfirm = nullptr; offlineEngine = new OfflineMsgEngine(f); typingTimer.setSingleShot(true); netcam = nullptr; callDurationTimer = nullptr; disableCallButtonsTimer = nullptr; chatWidget->setTypingNotification(ChatMessage::createTypingNotification()); headTextLayout->addWidget(statusMessageLabel); headTextLayout->addStretch(); callDuration = new QLabel(); headTextLayout->addWidget(callDuration, 1, Qt::AlignCenter); callDuration->hide(); loadHistoryAction = menu.addAction(QString(), this, SLOT(onLoadHistory())); connect(Core::getInstance(), &Core::fileSendStarted, this, &ChatForm::startFileSend); connect(sendButton, &QPushButton::clicked, this, &ChatForm::onSendTriggered); connect(fileButton, &QPushButton::clicked, this, &ChatForm::onAttachClicked); connect(screenshotButton, &QPushButton::clicked, this, &ChatForm::onScreenshotClicked); connect(callButton, &QPushButton::clicked, this, &ChatForm::onCallTriggered); connect(videoButton, &QPushButton::clicked, this, &ChatForm::onVideoCallTriggered); connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered); connect(msgEdit, &ChatTextEdit::textChanged, this, &ChatForm::onTextEditChanged); connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed); connect(this, SIGNAL(chatAreaCleared()), getOfflineMsgEngine(), SLOT(removeAllReciepts())); connect(&typingTimer, &QTimer::timeout, this, [=]{ Core::getInstance()->sendTyping(f->getFriendID(), false); isTyping = false; } ); connect(nameLabel, &CroppingLabel::textChanged, this, [=](QString text, QString orig) { if (text != orig) emit aliasChanged(text); } ); setAcceptDrops(true); retranslateUi(); Translator::registerHandler(std::bind(&ChatForm::retranslateUi, this), this); }
void OfflineMsgEngine::deliverOfflineMsgs() { QMutexLocker ml(&mutex); if (!Settings::getInstance().getFauxOfflineMessaging()) return; if (f->getStatus() == Status::Offline) return; if (undeliveredMsgs.size() == 0) return; QMap<int, MsgPtr> msgs = undeliveredMsgs; removeAllReciepts(); for (auto iter = msgs.begin(); iter != msgs.end(); ++iter) { auto val = iter.value(); auto key = iter.key(); if (val.timestamp.msecsTo(QDateTime::currentDateTime()) < offlineTimeout) { registerReceipt(val.receipt, key, val.msg, val.timestamp); continue; } QString messageText = val.msg->toString(); int rec; if (val.msg->isAction()) rec = Core::getInstance()->sendAction(f->getFriendID(), messageText); else rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText); registerReceipt(rec, key, val.msg); } }