* @brief Reads one chat's snapshot, or an empty object when missing/corrupt. */
| 158 | * @brief Reads one chat's snapshot, or an empty object when missing/corrupt. |
| 159 | */ |
| 160 | QJsonObject AI::ChatStore::loadChat(const QString& id) const |
| 161 | { |
| 162 | QFile f(chatPath(id)); |
| 163 | if (!f.exists() || !f.open(QIODevice::ReadOnly)) |
| 164 | return {}; |
| 165 | |
| 166 | const auto bytes = f.readAll(); |
| 167 | f.close(); |
| 168 | |
| 169 | QJsonParseError err; |
| 170 | const auto doc = QJsonDocument::fromJson(bytes, &err); |
| 171 | if (err.error != QJsonParseError::NoError || !doc.isObject()) { |
| 172 | qCWarning(serialStudioAI) << "ChatStore: invalid chat file" << id << err.errorString(); |
| 173 | return {}; |
| 174 | } |
| 175 | |
| 176 | return doc.object(); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * @brief Writes a chat's snapshot and refreshes its index metadata. |
no test coverage detected