MCPcopy Create free account
hub / github.com/RGAA-Software/GoDesk / ParseRespMessage

Method ParseRespMessage

src/client/transfer/file_transfer.cpp:186–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184 }
185
186 void FileTransferChannel::ParseRespMessage(std::string_view _data) {
187 auto msg = std::make_shared<tc::Message>();
188 std::string data(_data.data(), _data.size());
189 if (!msg->ParseFromString(data)) {
190 LOGE("Parse proto message failed!");
191 return;
192 }
193
194 if (msg->type() == MessageType::kRespFileTransfer) {
195 auto rft = msg->resp_file_transfer();
196 if (rft.state() == RespFileTransfer::kTransferReady) {
197 LOGI("Transfer ready for : {}, id: {}", rft.filename(), rft.id());
198 continue_sending_ = true;
199 send_cv_.notify_one();
200
201 context_->SendAppMessage(EvtFileTransferReady {
202 .id_ = rft.id(),
203 .name_ = rft.filename(),
204 .path_ = rft.local_filepath(),
205 .total_size_ = rft.filesize(),
206 .timestamp_ = rft.timestamp(),
207 });
208
209 } else if (rft.state() == RespFileTransfer::kFileDeleteFailed) {
210 ErrorDialog(std::format("Can't delete file: {} in remote!", rft.filename()).c_str());
211 continue_sending_ = false;
212 send_cv_.notify_one();
213
214 context_->SendAppMessage(EvtFileTransferDeleteFailed {
215 .id_ = rft.id(),
216 .name_ = rft.filename(),
217 .path_ = rft.local_filepath(),
218 .timestamp_ = rft.timestamp(),
219 });
220
221 } else if (rft.state() == RespFileTransfer::kTransferSuccess) {
222 LOGI("Transfer success: {}, id: {}", rft.filename(), rft.id());
223 //InfoDialog(std::format("Transfer file: {} success", rft.filename()).c_str());
224
225 context_->SendAppMessage(EvtFileTransferSuccess {
226 .id_ = rft.id(),
227 .name_ = rft.filename(),
228 .path_ = rft.local_filepath(),
229 .timestamp_ = rft.timestamp(),
230 .total_size_ = rft.filesize(),
231 });
232
233 } else if (rft.state() == RespFileTransfer::kTransferFailed) {
234 LOGE("Transfer failed: {}, id: {}", rft.filename(), rft.id());
235 ErrorDialog(std::format("Transfer failed: {}", rft.filename()).c_str());
236
237 context_->SendAppMessage(EvtFileTransferFailed {
238 .id_ = rft.id(),
239 .name_ = rft.filename(),
240 .path_ = rft.local_filepath(),
241 .timestamp_ = rft.timestamp(),
242 });
243

Callers 1

StartMethod · 0.95

Calls 1

SendAppMessageMethod · 0.45

Tested by

no test coverage detected