restored animation async from request
This commit is contained in:
parent
c8523bc115
commit
25eb366397
4 changed files with 53 additions and 41 deletions
|
@ -22,7 +22,17 @@ Conversation::Conversation(BHandler* replyTo) {
|
|||
Conversation::~Conversation() {
|
||||
}
|
||||
|
||||
|
||||
void Conversation::sendReply(BMessage message) {
|
||||
BLooper* looper = replyTarget->Looper(); // get the looper it's attached to
|
||||
|
||||
if (looper != nullptr) {
|
||||
BMessenger messenger(replyTarget, looper);
|
||||
messenger.SendMessage(&message);
|
||||
} else {
|
||||
printf("Handler not attached to a looper.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void Conversation::MessageReceived(BMessage* message) {
|
||||
switch (message->what) {
|
||||
//.. case B_HTTP_DATA_RECEIVED: {
|
||||
|
@ -67,50 +77,23 @@ void Conversation::MessageReceived(BMessage* message) {
|
|||
BHttpBody body = _lastResult->Body();
|
||||
if (body.text.has_value())
|
||||
{
|
||||
|
||||
json parsed = json::parse(body.text.value().String());
|
||||
|
||||
|
||||
|
||||
std::string content = parsed["choices"][0]["message"]["content"];
|
||||
|
||||
// printf("we got content:%s",content.c_str());
|
||||
|
||||
|
||||
BMessage message(kSendReply);
|
||||
message.AddString("text", BString(content.c_str()));
|
||||
|
||||
sendReply(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
BMessage message(kSendReply);
|
||||
message.AddString("text", "EMPTY BODY");
|
||||
sendReply(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BLooper* looper = replyTarget->Looper(); // get the looper it's attached to
|
||||
|
||||
if (looper != nullptr) {
|
||||
BMessenger messenger(replyTarget, looper);
|
||||
messenger.SendMessage(&message);
|
||||
} else {
|
||||
printf("Handler not attached to a looper.\n");
|
||||
}
|
||||
|
||||
|
||||
// status_t err = appMessenger.SendMessage(&message);
|
||||
//if (err != B_OK)
|
||||
// printf("SendMessage failed: %s\n", strerror(err));
|
||||
//else
|
||||
//printf("SendMessage OK");
|
||||
|
||||
// _answerView->SetText(content.c_str());
|
||||
|
||||
// _answerView->SetText(body.text.value());
|
||||
|
||||
}
|
||||
// else
|
||||
//_answerView->SetText("nuthin'");
|
||||
}
|
||||
|
||||
//_infoView->SetText("Completed");
|
||||
//_progress->SetMaxValue(100);
|
||||
//_progress->SetTo(100);
|
||||
|
||||
} break;
|
||||
break;
|
||||
|
||||
case UrlEvent::HttpStatus: {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue