| 151 | } |
| 152 | |
| 153 | void WizGroupMessage::on_queryMessageVersion_finished() |
| 154 | { |
| 155 | QNetworkReply* reply = qobject_cast<QNetworkReply *>(sender()); |
| 156 | |
| 157 | if (reply->error()) { |
| 158 | reply->deleteLater(); |
| 159 | syncEnd(); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | // return: "{"result": version,"return_code":200,"return_message":"success"}" |
| 164 | QString strReply = reply->readAll(); |
| 165 | reply->deleteLater(); |
| 166 | |
| 167 | qDebug() << "[Message Sync]query version finished, reply: " << strReply; |
| 168 | |
| 169 | rapidjson::Document document; |
| 170 | document.Parse<0>(strReply.toUtf8().constData()); |
| 171 | |
| 172 | if (!document.IsObject()) { |
| 173 | TOLOG("Error occured when try to parse json of message version"); |
| 174 | syncEnd(); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | QString nCode; |
| 179 | if (document["return_code"].IsString()) { |
| 180 | nCode = document["return_code"].getString(); |
| 181 | } else { |
| 182 | nCode = QString::number(document["return_code"].getInt()); |
| 183 | } |
| 184 | |
| 185 | QString strMsg = document["return_message"].getString(); |
| 186 | if (nCode != WIZAPI_RETURN_SUCCESS) { |
| 187 | TOLOG2("Error occured when get message version, code: %1, message: %2", |
| 188 | nCode, strMsg); |
| 189 | syncEnd(); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | qint64 nVersionRemote = document["result"].getInt64(); |
| 194 | qint64 nVersionLocal = m_db.getObjectVersion(WIZMESSAGEDATA::objectName()); |
| 195 | |
| 196 | qDebug() << "[Message Sync]local message version: " << nVersionLocal; |
| 197 | |
| 198 | // 3. compare version, determine fetch needed or not |
| 199 | if (nVersionLocal < nVersionRemote) { |
| 200 | callGetMessages(nVersionLocal); |
| 201 | } else { |
| 202 | syncEnd(); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | void WizGroupMessage::onGetMessages(const CWizMessageDataArray& messages) |
| 207 | { |
nothing calls this directly
no test coverage detected