[Client] Extract sendPrivateMessage() to fix invite message draft overwrite

sendInviteMessage() was calling sayEdit->setText(text) then sendMessage(),
which overwrites any text the user had typed.  Extract the command-building
and sending logic into a new sendPrivateMessage(const QString &text) method
that takes the text directly.  sendMessage() now calls it after its guards
and clears sayEdit; sendInviteMessage() calls it directly without touching
the input field at all.

Took 33 minutes
This commit is contained in:
Lukas Brübach 2026-08-17 03:40:53 +02:00
parent f210cef08c
commit de2b948533
2 changed files with 19 additions and 13 deletions

View file

@ -96,6 +96,18 @@ void TabMessage::closeEvent(QCloseEvent *event)
event->accept();
}
void TabMessage::sendPrivateMessage(const QString &text)
{
Command_Message cmd;
cmd.set_user_name(otherUserInfo->name());
cmd.set_message(text.toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
pend->setExtraData(text);
connect(pend, &PendingCommand::finished, this, &TabMessage::messageSent);
client->sendCommand(pend);
}
void TabMessage::sendMessage()
{
if (sayEdit->text().isEmpty()) {
@ -103,28 +115,21 @@ void TabMessage::sendMessage()
}
if (!userOnline) {
// Keep the draft: the user may be back momentarily, and the typed text
// should not be lost to a transient offline spell.
notifyUserOffline();
return;
}
Command_Message cmd;
cmd.set_user_name(otherUserInfo->name());
cmd.set_message(sayEdit->text().toStdString());
PendingCommand *pend = client->prepareSessionCommand(cmd);
pend->setExtraData(sayEdit->text());
connect(pend, &PendingCommand::finished, this, &TabMessage::messageSent);
client->sendCommand(pend);
sendPrivateMessage(sayEdit->text());
sayEdit->clear();
}
void TabMessage::sendInviteMessage(const QString &text)
{
sayEdit->setText(text);
sendMessage();
if (!userOnline) {
notifyUserOffline();
return;
}
sendPrivateMessage(text);
}
void TabMessage::messageSent(const Response &response,

View file

@ -67,6 +67,7 @@ public:
void sendInviteMessage(const QString &text);
private:
void sendPrivateMessage(const QString &text);
bool shouldShowSystemPopup(const Event_UserMessage &event);
void showSystemPopup(const Event_UserMessage &event);
void notifyUserOffline();