1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(chatform): don't attempt to send messages to offline friends

Stops critical error logs from toxcore.
This commit is contained in:
Anthony Bilinski 2018-09-06 09:51:40 -07:00
parent dac1582b72
commit d9e587e4f5
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -871,11 +871,15 @@ void ChatForm::sendLoadedMessage(ChatMessage::Ptr chatMsg, MessageMetadata const
if (!metadata.needSending) {
return;
}
int receipt = 0;
if (f->getStatus() != Status::Offline) {
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
QString stringMsg = chatMsg->toString();
int receipt = metadata.isAction ? core->sendAction(friendId, stringMsg)
receipt = metadata.isAction ? core->sendAction(friendId, stringMsg)
: core->sendMessage(friendId, stringMsg);
}
getOfflineMsgEngine()->registerReceipt(receipt, metadata.id, chatMsg);
}
@ -1059,18 +1063,22 @@ void ChatForm::SendMessageStr(QString msg)
historyPart = ACTION_PREFIX + part;
}
bool status = !Settings::getInstance().getFauxOfflineMessaging();
ChatMessage::Ptr ma = createSelfMessage(part, timestamp, isAction, false);
int rec = 0;
if (f->getStatus() != Status::Offline) {
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
}
ChatMessage::Ptr ma = createSelfMessage(part, timestamp, isAction, false);
if (history && Settings::getInstance().getEnableLogging()) {
auto* offMsgEngine = getOfflineMsgEngine();
QString selfPk = Core::getInstance()->getSelfId().toString();
QString pk = f->getPublicKey().toString();
QString name = Core::getInstance()->getUsername();
history->addNewMessage(pk, historyPart, selfPk, timestamp, status, name,
bool isSent = !Settings::getInstance().getFauxOfflineMessaging();
history->addNewMessage(pk, historyPart, selfPk, timestamp, isSent, name,
[offMsgEngine, rec, ma](int64_t id) {
offMsgEngine->registerReceipt(rec, id, ma);
});