mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-29 17:32:17 -07:00
[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:
parent
f210cef08c
commit
de2b948533
2 changed files with 19 additions and 13 deletions
|
|
@ -96,6 +96,18 @@ void TabMessage::closeEvent(QCloseEvent *event)
|
||||||
event->accept();
|
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()
|
void TabMessage::sendMessage()
|
||||||
{
|
{
|
||||||
if (sayEdit->text().isEmpty()) {
|
if (sayEdit->text().isEmpty()) {
|
||||||
|
|
@ -103,28 +115,21 @@ void TabMessage::sendMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userOnline) {
|
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();
|
notifyUserOffline();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_Message cmd;
|
sendPrivateMessage(sayEdit->text());
|
||||||
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);
|
|
||||||
|
|
||||||
sayEdit->clear();
|
sayEdit->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabMessage::sendInviteMessage(const QString &text)
|
void TabMessage::sendInviteMessage(const QString &text)
|
||||||
{
|
{
|
||||||
sayEdit->setText(text);
|
if (!userOnline) {
|
||||||
sendMessage();
|
notifyUserOffline();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendPrivateMessage(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabMessage::messageSent(const Response &response,
|
void TabMessage::messageSent(const Response &response,
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ public:
|
||||||
void sendInviteMessage(const QString &text);
|
void sendInviteMessage(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void sendPrivateMessage(const QString &text);
|
||||||
bool shouldShowSystemPopup(const Event_UserMessage &event);
|
bool shouldShowSystemPopup(const Event_UserMessage &event);
|
||||||
void showSystemPopup(const Event_UserMessage &event);
|
void showSystemPopup(const Event_UserMessage &event);
|
||||||
void notifyUserOffline();
|
void notifyUserOffline();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue