Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(chatform): don't attempt to send messages to offline friends
Browse files Browse the repository at this point in the history
Stops critical error logs from toxcore.
  • Loading branch information
anthonybilinski committed Sep 6, 2018
1 parent dac1582 commit d9e587e
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,15 @@ void ChatForm::sendLoadedMessage(ChatMessage::Ptr chatMsg, MessageMetadata const
if (!metadata.needSending) {
return;
}
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
QString stringMsg = chatMsg->toString();
int receipt = metadata.isAction ? core->sendAction(friendId, stringMsg)

int receipt = 0;
if (f->getStatus() != Status::Offline) {
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
QString stringMsg = chatMsg->toString();
receipt = metadata.isAction ? core->sendAction(friendId, stringMsg)
: core->sendMessage(friendId, stringMsg);
}
getOfflineMsgEngine()->registerReceipt(receipt, metadata.id, chatMsg);
}

Expand Down Expand Up @@ -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);
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
int rec = isAction ? core->sendAction(friendId, part) : core->sendMessage(friendId, part);
int rec = 0;
if (f->getStatus() != Status::Offline) {
Core* core = Core::getInstance();
uint32_t friendId = f->getId();
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);
});
Expand Down

0 comments on commit d9e587e

Please sign in to comment.