aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2021-01-18 18:54:11 +0300
committerCrystalwarrior <varsash@gmail.com>2021-01-18 18:54:11 +0300
commit78777391467556b1312a00bdf1618619f771476e (patch)
tree23f85e8529ae6760ec11a6c9f0e1cc51aad83d06
parentea94644cf5bbd11f507b318677a7360433a0ae92 (diff)
Simplify the logic behind last message = blankpost detection
I need to stop overcomplicating things.
-rw-r--r--include/courtroom.h1
-rw-r--r--src/courtroom.cpp39
2 files changed, 24 insertions, 16 deletions
diff --git a/include/courtroom.h b/include/courtroom.h
index 92b5a03c..4cf42e1e 100644
--- a/include/courtroom.h
+++ b/include/courtroom.h
@@ -349,6 +349,7 @@ private:
QVector<QString> arup_locks;
QVector<chatlogpiece> ic_chatlog_history;
+ QString last_ic_message = "";
QQueue<QStringList> chatmessage_queue;
diff --git a/src/courtroom.cpp b/src/courtroom.cpp
index 24d8c5fe..443fb305 100644
--- a/src/courtroom.cpp
+++ b/src/courtroom.cpp
@@ -2066,12 +2066,13 @@ void Courtroom::log_chatmessage(QString f_message, int f_char_id, QString f_show
}
}
- // If the chat message isn't a blankpost, or the chatlog history is empty, or its last message isn't a blankpost
- if (!f_message.isEmpty() || ic_chatlog_history.isEmpty() || ic_chatlog_history.last().get_showname() != f_showname) {
- // Add the message to the logs file
- log_ic_text(f_showname, f_displayname, f_message, "",
- f_color);
- }
+ // If our current message is a blankpost, the chat log isn't empty, the chat log's last message is a blank post, and the blankpost's showname is the same as ours
+ if (f_message.isEmpty() && !ic_chatlog_history.isEmpty() && ic_chatlog_history.last().get_message().isEmpty() && ic_chatlog_history.last().get_showname() == f_displayname)
+ return; // Skip adding message
+
+ // Add the message to the logs file
+ log_ic_text(f_showname, f_displayname, f_message, "",
+ f_color);
}
void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QString f_showname, int f_color)
@@ -2151,13 +2152,15 @@ void Courtroom::display_log_chatmessage(QString f_message, int f_char_id, QStrin
append_ic_text(f_evi_name, f_displayname, tr("has presented evidence"));
}
}
- int current = ic_chatlog_history.size() - chatmessage_queue.size() - 1;
- // If the chat message isn't a blankpost, or the chatlog history is empty, or its last message isn't a blankpost
- if (!f_message.isEmpty() || current <= -1 || ic_chatlog_history[current].get_showname() != f_showname) {
- // Append the message to the IC chatlogs in client
- append_ic_text(f_message, f_displayname, "",
- f_color);
- }
+
+ // If our current message is a blankpost, the chat log isn't empty, the chat log's last message is a blank post, and the blankpost's showname is the same as ours
+ if (f_message.isEmpty() && last_ic_message == f_displayname + ":")
+ return; // Skip adding message
+
+ last_ic_message = f_displayname + ":" + f_message;
+ // Append the message to the IC chatlogs in client
+ append_ic_text(f_message, f_displayname, "",
+ f_color);
}
bool Courtroom::handle_objection()
@@ -5241,12 +5244,16 @@ void Courtroom::on_showname_enable_clicked()
void Courtroom::regenerate_ic_chatlog()
{
ui_ic_chatlog->clear();
+ last_ic_message = "";
foreach (chatlogpiece item, ic_chatlog_history) {
- append_ic_text(item.get_message(),
- ui_showname_enable->isChecked() ? item.get_showname()
- : item.get_name(),
+ QString message = item.get_message();
+ QString name = ui_showname_enable->isChecked() ? item.get_showname()
+ : item.get_name();
+ append_ic_text(message,
+ name,
item.get_action(), item.get_chat_color(),
item.get_datetime().toLocalTime());
+ last_ic_message = name + ":" + message;
}
}